aboutsummaryrefslogtreecommitdiff
path: root/bin/lsp_diagnostic.ml
diff options
context:
space:
mode:
Diffstat (limited to 'bin/lsp_diagnostic.ml')
-rw-r--r--bin/lsp_diagnostic.ml24
1 files changed, 24 insertions, 0 deletions
diff --git a/bin/lsp_diagnostic.ml b/bin/lsp_diagnostic.ml
new file mode 100644
index 0000000..7f697f8
--- /dev/null
+++ b/bin/lsp_diagnostic.ml
@@ -0,0 +1,24 @@
+module Types = Linol_lsp.Types
+(** Generate a diagnostic from the report *)
+
+let position : Lexing.position -> Types.Position.t =
+ fun pos ->
+ {
+ character = pos.Lexing.pos_cnum - pos.Lexing.pos_bol;
+ line = pos.Lexing.pos_lnum - 1;
+ }
+
+let build : Qsp_syntax.Report.t -> Types.Diagnostic.t =
+ fun { level; loc; message } ->
+ let severity =
+ match level with
+ | Error -> Types.DiagnosticSeverity.Error
+ | Warn -> Types.DiagnosticSeverity.Warning
+ | Debug -> Types.DiagnosticSeverity.Hint
+ in
+
+ let start = position (fst loc) and end_ = position (snd loc) in
+ let range = Types.Range.{ start; end_ } in
+
+ let message = `String message in
+ Types.Diagnostic.create ~range ~message ~severity ()