Skip to content

Commit 6aa22fb

Browse files
authored
Merge pull request #563 from coq-community/ocaml-lsp
Use ocaml-lsp datatypes for base LSP
2 parents bbebf72 + 3ca3b87 commit 6aa22fb

39 files changed

+552
-1037
lines changed

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
ppx_assert
4848
ppx_sexp_conv
4949
ppx_deriving
50+
ppx_import
5051
sexplib
5152
ppx_yojson_conv
52-
uri
53+
lsp
5354
]);
5455
};
5556

language-server/dm/completionSuggester.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(* See LICENSE file. *)
1212
(* *)
1313
(**************************************************************************)
14+
open Protocol
1415

1516
module CompactedDecl = Context.Compacted.Declaration
1617
open Printer
@@ -326,7 +327,7 @@ module Structured = struct
326327

327328
(* A Lower score is better as we are sorting in ascending order *)
328329

329-
let rank (options: Lsp.LspData.Settings.Completion.t) (goal, goal_evar) sigma env lemmas : CompletionItems.completion_item list =
330+
let rank (options: Settings.Completion.t) (goal, goal_evar) sigma env lemmas : CompletionItems.completion_item list =
330331
let size_impact = options.sizeFactor in
331332
let atomic_factor = options.atomicFactor in
332333
let finalScore score size = Float.sub size (Float.mul score size_impact) in
@@ -379,7 +380,7 @@ module SelectiveUnification = struct
379380
|> List.stable_sort (fun a b -> compare (snd a) (snd b))
380381
|> List.map fst
381382

382-
let selectiveRank (options: Lsp.LspData.Settings.Completion.t) (goal : Evd.econstr) sigma env (lemmas : CompletionItems.completion_item list) : CompletionItems.completion_item list =
383+
let selectiveRank (options: Settings.Completion.t) (goal : Evd.econstr) sigma env (lemmas : CompletionItems.completion_item list) : CompletionItems.completion_item list =
383384
try
384385
let take, skip = takeSkip options.unificationLimit lemmas in
385386
List.append (rankByUnifiability goal sigma env take) skip
@@ -390,8 +391,8 @@ module SelectiveUnification = struct
390391
let rank = selectiveRank
391392
end
392393

393-
let rank_choices (options: Lsp.LspData.Settings.Completion.t) (goal, goal_evar) sigma env lemmas =
394-
let open Lsp.LspData.Settings.Completion.RankingAlgoritm in
394+
let rank_choices (options: Settings.Completion.t) (goal, goal_evar) sigma env lemmas =
395+
let open Settings.Completion.RankingAlgoritm in
395396
match options.algorithm with
396397
| SplitTypeIntersection -> TypeIntersection.rank goal sigma env lemmas
397398
| StructuredSplitUnification -> SelectiveUnification.rank options goal sigma env (Structured.rank options (goal, goal_evar) sigma env lemmas)

language-server/dm/completionSuggester.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(* *)
1313
(**************************************************************************)
1414

15-
open Lsp.LspData
15+
open Protocol
1616
open CompletionItems
1717

1818
val get_completions : Settings.Completion.t -> Vernacstate.t -> completion_item list option

language-server/dm/document.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
(* *)
1313
(**************************************************************************)
1414
open Gramlib
15-
open Lsp
16-
open LspData
1715
open Types
16+
open Lsp.Types
1817
open Scheduler
1918

2019
let Log log = Log.mk_log "document"

language-server/dm/document.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(**************************************************************************)
1414

1515
open Types
16-
open Lsp.LspData
16+
open Lsp.Types
1717

1818
(** This file defines operations on the content of a document (text, parsing
1919
of sentences, scheduling). *)

language-server/dm/documentManager.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
(* *)
1313
(**************************************************************************)
1414

15+
open Lsp.Types
16+
open Protocol
17+
open Protocol.LspWrapper
1518
open Types
16-
open Lsp.LspData
1719

1820
let Log log = Log.mk_log "documentManager"
1921

2022
type state = {
21-
uri : Uri.t;
23+
uri : DocumentUri.t;
2224
init_vs : Vernacstate.t;
2325
opts : Coqargs.injection_command list;
2426
document : Document.document;
@@ -115,7 +117,7 @@ let make_diagnostic doc range oloc message severity =
115117
| Some loc ->
116118
RawDocument.range_of_loc (Document.raw_document doc) loc
117119
in
118-
Diagnostic.{ range; message; severity }
120+
Diagnostic.create ~range ~message ~severity ()
119121

120122
let make_coq_feedback doc range oloc message channel =
121123
let range =
@@ -144,15 +146,15 @@ let diagnostics st =
144146
(* we are resilient to a state where invalidate was not called yet *)
145147
let exists (id,_) = Option.has_some (Document.get_sentence st.document id) in
146148
let exec_errors = all_exec_errors |> List.filter exists in
147-
let warnings_and_errors (id, (lvl, oloc, msg)) = Option.map (fun lvl -> id, (lvl, oloc, msg)) (Severity.t_of_feedback_level lvl) in
149+
let warnings_and_errors (id, (lvl, oloc, msg)) = Option.map (fun lvl -> id, (lvl, oloc, msg)) (DiagnosticSeverity.of_feedback_level lvl) in
148150
let diags = all_feedback |> List.filter exists |> List.filter_map warnings_and_errors in
149151
let mk_diag (id,(lvl,oloc,msg)) =
150152
make_diagnostic st.document (Document.range_of_id st.document id) oloc msg lvl
151153
in
152-
let mk_error_diag (id,(oloc,msg)) = mk_diag (id,(Severity.Error,oloc,msg)) in
154+
let mk_error_diag (id,(oloc,msg)) = mk_diag (id,(DiagnosticSeverity.Error,oloc,msg)) in
153155
let mk_parsing_error_diag Document.{ msg = (oloc,msg); start; stop } =
154156
let doc = Document.raw_document st.document in
155-
let severity = Severity.Error in
157+
let severity = DiagnosticSeverity.Error in
156158
let start = RawDocument.position_of_loc doc start in
157159
let end_ = RawDocument.position_of_loc doc stop in
158160
let range = Range.{ start; end_ } in
@@ -242,7 +244,7 @@ let validate_document state =
242244

243245
let init init_vs ~opts uri ~text =
244246
Vernacstate.unfreeze_full_state init_vs;
245-
let top = Coqargs.(dirpath_of_top (TopPhysical (Uri.path uri))) in
247+
let top = Coqargs.(dirpath_of_top (TopPhysical (DocumentUri.to_path uri))) in
246248
Coqinit.start_library ~top opts;
247249
let init_vs = Vernacstate.freeze_full_state () in
248250
let document = Document.create_document init_vs.Vernacstate.synterp text in
@@ -290,7 +292,7 @@ let get_proof st pos =
290292
in
291293
let oid = Option.cata id_of_pos st.observe_id pos in
292294
let ost = Option.bind oid (ExecutionManager.get_vernac_state st.execution_state) in
293-
Option.bind ost Lsp.ProofState.get_proof
295+
Option.bind ost ProofState.get_proof
294296

295297
let get_context st pos =
296298
let loc = RawDocument.loc_of_position (Document.raw_document st.document) pos in

language-server/dm/documentManager.mli

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
(**************************************************************************)
1414

1515
open Types
16-
open Lsp.LspData
16+
open Lsp.Types
17+
open Protocol
18+
open Protocol.LspWrapper
1719
open CompletionItems
1820

1921
(** The document manager holds the view that Coq has of the currently open
@@ -28,7 +30,7 @@ val pp_event : Format.formatter -> event -> unit
2830

2931
type events = event Sel.event list
3032

31-
val init : Vernacstate.t -> opts:Coqargs.injection_command list -> Uri.t -> text:string -> state * events
33+
val init : Vernacstate.t -> opts:Coqargs.injection_command list -> DocumentUri.t -> text:string -> state * events
3234
(** [init st opts uri text] initializes the document manager with initial vernac state
3335
[st] on which command line opts will be set. *)
3436

@@ -72,7 +74,7 @@ val executed_ranges : state -> exec_overview
7274
(** returns the ranges corresponding to the sentences
7375
that have been executed and remotely executes *)
7476

75-
val observe_id_range : state -> Lsp.LspData.Range.t option
77+
val observe_id_range : state -> Range.t option
7678
(** returns the range of the sentence referenced by observe_id **)
7779

7880
val diagnostics : state -> Diagnostic.t list
@@ -83,7 +85,7 @@ val feedbacks : state -> CoqFeedback.t list
8385
(** feedback [doc] returns notice, info and debug level feedbacks from coq corresponding
8486
to the sentences that have been executed in [doc]. *)
8587

86-
val get_proof : state -> Position.t option -> Lsp.ProofState.t option
88+
val get_proof : state -> Position.t option -> ProofState.t option
8789

8890
val get_completions : state -> Position.t -> (completion_item list, string) Result.t
8991

@@ -94,7 +96,7 @@ val search : state -> id:string -> Position.t -> string -> notification Sel.even
9496

9597
val about : state -> Position.t -> pattern:string -> (string,string) Result.t
9698

97-
val hover : state -> Position.t -> (string list) option
99+
val hover : state -> Position.t -> MarkupContent.t option
98100
(** Returns an optional Result:
99101
if None, the position did not have a word,
100102
if Some, an Ok/Error result is returned. *)

language-server/dm/dune

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
(name dm)
33
(public_name vscoq-language-server.dm)
44
(modules :standard \ vscoqtop_proof_worker vscoqtop_tactic_worker)
5-
(libraries base coq-core.sysinit coq-core.vernac coq-core.parsing sel lsp language))
5+
(libraries base coq-core.sysinit coq-core.vernac coq-core.parsing lsp sel protocol language))
66

77
(executable
88
(name vscoqtop_proof_worker)
99
(public_name vscoqtop_proof_worker.opt)
1010
(modules vscoqtop_proof_worker)
1111
(flags -linkall)
1212
(package vscoq-language-server)
13-
(libraries coq-core.sysinit coq-core.tactics dm lsp))
13+
(libraries coq-core.sysinit coq-core.tactics lsp dm protocol))
1414

1515
(executable
1616
(name vscoqtop_tactic_worker)
1717
(public_name vscoqtop_tactic_worker.opt)
1818
(modules vscoqtop_tactic_worker)
1919
(flags -linkall)
2020
(package vscoq-language-server)
21-
(libraries coq-core.sysinit coq-core.tactics dm lsp))
21+
(libraries coq-core.sysinit coq-core.tactics lsp dm protocol))

language-server/dm/executionManager.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(* *)
1313
(**************************************************************************)
1414

15+
open Protocol
1516
open Scheduler
1617
open Types
1718

@@ -41,9 +42,10 @@ type delegation_mode =
4142

4243
type options = {
4344
delegation_mode : delegation_mode;
44-
completion_options : Lsp.LspData.Settings.Completion.t;
45+
completion_options : Settings.Completion.t;
4546
enableDiagnostics : bool
4647
}
48+
4749
let default_options = {
4850
delegation_mode = CheckProofsInMaster;
4951
completion_options = {

language-server/dm/executionManager.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
(**************************************************************************)
1414

1515
open Types
16+
open Protocol
1617

1718
(** The event manager is in charge of the actual event of tasks (as
1819
defined by the scheduler), caching event states and invalidating
@@ -25,7 +26,7 @@ type delegation_mode =
2526

2627
type options = {
2728
delegation_mode : delegation_mode;
28-
completion_options : Lsp.LspData.Settings.Completion.t;
29+
completion_options : Settings.Completion.t;
2930
enableDiagnostics : bool;
3031
}
3132

language-server/dm/rawDocument.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
(* See LICENSE file. *)
1212
(* *)
1313
(**************************************************************************)
14-
open Lsp
15-
open LspData
14+
open Lsp.Types
1615

1716
type text_edit = Range.t * string
1817

language-server/dm/rawDocument.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
(* See LICENSE file. *)
1212
(* *)
1313
(**************************************************************************)
14-
open Lsp
15-
open LspData
14+
open Lsp.Types
1615

1716
type text_edit = Range.t * string
1817

language-server/dm/searchQuery.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(**************************************************************************)
1414
open Util
1515
open Printer
16-
open Lsp.LspData
16+
open Protocol.LspWrapper
1717
open Vernacexpr
1818
open Pp
1919
(* Note: this queue is not very useful today, as we process results in the main

language-server/dm/searchQuery.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(* See LICENSE file. *)
1212
(* *)
1313
(**************************************************************************)
14-
open Lsp.LspData
14+
open Protocol.LspWrapper
1515

1616
val query_feedback : notification Sel.event
1717

language-server/dm/types.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(* See LICENSE file. *)
1212
(* *)
1313
(**************************************************************************)
14-
open Lsp.LspData
14+
open Lsp.Types
1515

1616
type sentence_id = Stateid.t
1717
type sentence_id_set = Stateid.Set.t

language-server/language/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(library
22
(name language)
33
(public_name vscoq-language-server.language)
4-
(libraries coq-core.sysinit))
4+
(libraries coq-core.sysinit lsp))

language-server/language/hover.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,22 @@ let ref_info env _sigma ref udecl =
224224
let path = Libnames.pr_path (Nametab.path_of_global ref) ++ canonical_name_info ref in
225225
let args = print_arguments ref in
226226
let args = if Pp.ismt args then [] else ["**Args:** " ^ (Pp.string_of_ppcmds (print_arguments ref))] in
227-
[md_code_block @@ compactify @@ Pp.string_of_ppcmds typ]@args@
227+
String.concat "\n" @@ [md_code_block @@ compactify @@ Pp.string_of_ppcmds typ]@args@
228228
[Format.sprintf "**%s** %s" (pr_globref_kind ref) (Pp.string_of_ppcmds path)]
229229

230230
let mod_info mp =
231-
[md_code_block @@ Format.sprintf "Module %s" (DirPath.to_string (Nametab.dirpath_of_module mp))]
231+
md_code_block @@ Format.sprintf "Module %s" (DirPath.to_string (Nametab.dirpath_of_module mp))
232232

233233
let modtype_info mp =
234-
[md_code_block @@ Format.sprintf "Module Type %s" (Libnames.string_of_path (Nametab.path_of_modtype mp))]
234+
md_code_block @@ Format.sprintf "Module Type %s" (Libnames.string_of_path (Nametab.path_of_modtype mp))
235235

236236
let syndef_info kn =
237-
[md_code_block @@ Format.sprintf "Notation %s" (Libnames.string_of_path (Nametab.path_of_abbreviation kn))]
237+
md_code_block @@ Format.sprintf "Notation %s" (Libnames.string_of_path (Nametab.path_of_abbreviation kn))
238238

239239
let get_hover_contents env sigma ref_or_by_not =
240240
match ref_or_by_not.CAst.v with
241241
| Constrexpr.AN qid ->
242-
begin try
242+
let r = begin try
243243
let udecl = None in
244244
let ref = Nametab.locate qid in
245245
Some (ref_info env sigma ref udecl)
@@ -258,4 +258,6 @@ let get_hover_contents env sigma ref_or_by_not =
258258
with Not_found ->
259259
None
260260
end
261+
in
262+
Option.map Lsp.Types.(fun value -> MarkupContent.create ~kind:MarkupKind.Markdown ~value) r
261263
| Constrexpr.ByNotation (_ntn,_sc) -> assert false

language-server/language/hover.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ val get_hover_contents :
1818
env ->
1919
evar_map ->
2020
Libnames.qualid Constrexpr.or_by_notation ->
21-
(string list) option
21+
Lsp.Types.MarkupContent.t option

language-server/lsp/dune

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)