Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove dependency on workspace_root #1133

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions ocaml-lsp-server/src/diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,14 @@ let equal_message =
type t =
{ dune :
(Dune.t, (Drpc.Diagnostic.Id.t, Uri.t * Diagnostic.t) Table.t) Table.t
; workspace_root : Uri.t Lazy.t
; merlin : (Uri.t, Diagnostic.t list) Table.t
; send : PublishDiagnosticsParams.t list -> unit Fiber.t
; mutable dirty_uris : Uri_set.t
; related_information : bool
; tags : DiagnosticTag.t list
}

let workspace_root t = Lazy.force t.workspace_root

let create (capabilities : PublishDiagnosticsClientCapabilities.t option)
~workspace_root send =
let create (capabilities : PublishDiagnosticsClientCapabilities.t option) send =
let related_information, tags =
match capabilities with
| None -> (false, [])
Expand All @@ -107,7 +103,6 @@ let create (capabilities : PublishDiagnosticsClientCapabilities.t option)
; merlin = Table.create (module Uri) 32
; dirty_uris = Uri_set.empty
; send
; workspace_root
; related_information
; tags
}
Expand Down
3 changes: 0 additions & 3 deletions ocaml-lsp-server/src/diagnostics.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ type t

val create :
PublishDiagnosticsClientCapabilities.t option
-> workspace_root:Uri.t Lazy.t
-> (PublishDiagnosticsParams.t list -> unit Fiber.t)
-> t

val send : t -> [ `All | `One of Uri.t ] -> unit Fiber.t

val workspace_root : t -> Uri.t

module Dune : sig
type t

Expand Down
9 changes: 6 additions & 3 deletions ocaml-lsp-server/src/dune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ end = struct
in
Some ())

let diagnostic_loop client config (running : running) diagnostics =
let diagnostic_loop ~dune_root client config (running : running) diagnostics =
let* res = Client.poll client Drpc.Sub.diagnostic in
let send_diagnostics evs =
let promotions, add, remove =
Expand Down Expand Up @@ -335,7 +335,7 @@ end = struct
in
let uri : Uri.t =
match Drpc.Diagnostic.loc d with
| None -> Diagnostics.workspace_root diagnostics
| None -> dune_root
| Some loc ->
let { Lexing.pos_fname; _ } = Drpc.Loc.start loc in
Uri.of_path pos_fname
Expand Down Expand Up @@ -527,7 +527,10 @@ end = struct
progress_loop client diagnostics document_store progress
in
let diagnostics =
diagnostic_loop client config running diagnostics
let dune_root =
DocumentUri.of_path (Registry.Dune.root source)
in
diagnostic_loop ~dune_root client config running diagnostics
in
Fiber.all_concurrently_unit
[ progress; diagnostics; Fiber.Ivar.read finish ]))
Expand Down
6 changes: 0 additions & 6 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,10 @@ let on_initialize server (ip : InitializeParams.t) =
let state : State.t = Server.state server in
let workspaces = Workspaces.create ip in
let diagnostics =
let workspace_root =
lazy
(let state = Server.state server in
State.workspace_root state)
in
Diagnostics.create
(let open Option.O in
let* td = ip.capabilities.textDocument in
td.publishDiagnostics)
~workspace_root
(function
| [] -> Fiber.return ()
| diagnostics ->
Expand Down