-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We can now open documents on the lsp side, which means that we can implement ml/mli toggling entirely in LSP ps-id: e8a3b313-bfc9-4f75-af26-48228f3e999a
- Loading branch information
Showing
9 changed files
with
196 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
open Import | ||
open Fiber.O | ||
|
||
let command_name = "ocamllsp/open-related-source" | ||
|
||
let command_run server (params : ExecuteCommandParams.t) = | ||
let uri = | ||
match params.arguments with | ||
| Some [ json ] -> DocumentUri.t_of_yojson json | ||
| None | Some _ -> | ||
Jsonrpc.Response.Error.raise | ||
@@ Jsonrpc.Response.Error.make | ||
~code:Jsonrpc.Response.Error.Code.InvalidParams | ||
~message:"takes a single uri as input" () | ||
in | ||
let uri = Uri.to_string uri in | ||
let+ { ShowDocumentResult.success } = | ||
let req = ShowDocumentParams.create ~uri ~takeFocus:true () in | ||
Server.request server (Server_request.ShowDocumentRequest req) | ||
in | ||
if not success then Format.eprintf "failed to open %s@." uri; | ||
`Null | ||
|
||
let for_uri uri = | ||
Document.get_impl_intf_counterparts uri | ||
|> List.map ~f:(fun uri -> | ||
let path = Uri.to_path uri in | ||
let exists = Sys.file_exists path in | ||
let title = | ||
sprintf "%s %s" | ||
(if exists then "Open" else "Create") | ||
(Filename.basename path) | ||
in | ||
let command = | ||
let arguments = [ DocumentUri.yojson_of_t uri ] in | ||
Command.create ~title ~command:command_name ~arguments () | ||
in | ||
let edit = | ||
match exists with | ||
| true -> None | ||
| false -> | ||
let documentChanges = | ||
[ `CreateFile (CreateFile.create ~uri ()) ] | ||
in | ||
Some (WorkspaceEdit.create ~documentChanges ()) | ||
in | ||
CodeAction.create ?edit ~title ~kind:(CodeActionKind.Other "switch") | ||
~command ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
open Import | ||
|
||
val command_name : string | ||
|
||
val command_run : _ Server.t -> ExecuteCommandParams.t -> Json.t Fiber.t | ||
|
||
val for_uri : DocumentUri.t -> CodeAction.t list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters