ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Handle DidCreateFiles notification

Unfortunately neovim does not support this at the time of writing,
meaning that the server won't know about trees created via the code
action. A possible workaround would be to implement polling/file
watching, which is something we want anyway.

Remove some dead code

authored by

Kento Okura and committed by
Jon Sterling
ae2b12be 3d6ed1c7

+64 -75
-1
lib/compiler/Imports.ml
··· 130 130 let fixup (tree : Tree.code) (forest : State.t) = 131 131 let@ () = Reporter.tracef "when updating imports for %a" Tree.pp_identity tree.identity in 132 132 Logs.debug (fun m -> m "updating imports for %a" Tree.pp_identity tree.identity); 133 - Logs.debug (fun m -> m "%a" Code.pp tree.nodes); 134 133 let graph = forest.import_graph in 135 134 match tree.identity with 136 135 | Tree.Anonymous -> assert false
-54
lib/language_server/Code_action.ml
··· 5 5 * 6 6 *) 7 7 8 - open Lsp_error 9 8 open Forester_compiler 10 9 11 10 module L = Lsp.Types 12 11 13 - (* This function is mainly decodes the arguments to the command*) 14 - let execute (params : L.ExecuteCommandParams.t) = 15 - let Lsp_state.{forest; _} = Lsp_state.get () in 16 - match params with 17 - | {arguments; command; _} -> 18 - match command with 19 - | "new tree" -> 20 - let open Yojson.Safe.Util in 21 - let prefix, mode = 22 - match arguments with 23 - | Some [json_stuff] -> 24 - let prefix = json_stuff |> member "prefix" |> to_string_option in 25 - let mode = 26 - json_stuff |> member "mode" |> to_string |> function 27 - | "random" -> `Random 28 - | "sequential" -> `Sequential 29 - | _ -> 30 - raise @@ 31 - decode_error @@ 32 - Format.asprintf 33 - "got invalid arguments when executing \"new tree\" command" 34 - in 35 - prefix, mode 36 - | x -> 37 - raise @@ 38 - decode_error @@ 39 - Format.( 40 - asprintf 41 - "got invalid arguments when executing \"new tree\" command. Expected data in the shape of [{\"prefix\" = ..., \"mode\" = ...}], but got: %a." 42 - (pp_print_option (pp_print_list Yojson.Safe.pp)) 43 - x 44 - ) 45 - in 46 - let env = forest.env in 47 - let template = None in 48 - let res = Forester_frontend.Forester.create_tree ~env ~prefix ~template ~mode ~forest ~dest_dir: None in 49 - `String res 50 - | _ -> `Null 51 - 52 12 let resolve (params : L.CodeAction.t) = params 53 - 54 - let create_new_tree_cmd ~prefix ~mode = 55 - let mode = match mode with `Sequential -> "sequential" | `Random -> "random" in 56 - L.Command.create 57 - ~command: "new tree" 58 - ~title: "" 59 - ~arguments: [ 60 - `Assoc 61 - [ 62 - "prefix", `String prefix; 63 - "mode", `String mode 64 - ] 65 - ] 66 - () 67 13 68 14 let next_addrs ~(forest : State.t) prefix = 69 15 let seq, dir =
+9 -7
lib/language_server/Definitions.ml
··· 20 20 let host = forest.config.host in 21 21 let uri = URI_scheme.lsp_uri_to_uri ~host textDocument.uri in 22 22 match forest.={uri} with 23 - | None -> assert false 23 + | None -> None 24 24 | Some tree -> 25 25 match Tree.to_code tree with 26 26 | None -> None 27 27 | Some {nodes; _} -> 28 28 match Analysis.addr_at ~position nodes with 29 - | None -> assert false 29 + | None -> None 30 30 | Some {value = str; _} -> 31 31 let uri = URI_scheme.user_uri ~host str in 32 - let path = URI.Tbl.find forest.resolver uri in 33 - let uri = Lsp.Uri.of_path path in 34 - let range = L.Range.create ~start: {character = 1; line = 0} ~end_: {character = 1; line = 0} in 35 - Some 36 - (`Location [L.Location.{uri; range}]) 32 + match URI.Tbl.find_opt forest.resolver uri with 33 + | None -> None 34 + | Some path -> 35 + let uri = Lsp.Uri.of_path path in 36 + let range = L.Range.create ~start: {character = 1; line = 0} ~end_: {character = 1; line = 0} in 37 + Some 38 + (`Location [L.Location.{uri; range}])
-1
lib/language_server/Did_change.ml
··· 23 23 | None -> assert false 24 24 | Some doc -> 25 25 let new_doc = Lsp.Text_document.apply_content_changes doc contentChanges in 26 - Eio.traceln "After change, doc has content %s" (Lsp.Text_document.text new_doc); 27 26 forest.={uri} <- Document new_doc; 28 27 Lsp_state.modify (fun ({forest; _} as lsp_state) -> 29 28 let new_forest = Driver.run_until_done (Action.Parse lsp_uri) forest in
+31
lib/language_server/Did_create_files.ml
··· 1 + (* 2 + * SPDX-FileCopyrightText: 2024 The Forester Project Contributors 3 + * 4 + * SPDX-License-Identifier: GPL-3.0-or-later 5 + *) 6 + 7 + open Forester_prelude 8 + open Forester_core 9 + open Forester_compiler 10 + 11 + open State.Syntax 12 + 13 + module L = Lsp.Types 14 + 15 + let compute ({files}: L.CreateFilesParams.t) = 16 + Eio.traceln "recieved DidCreateFiles notification"; 17 + Lsp_state.modify (fun ({forest; _} as lsp_state) -> 18 + let host = forest.config.host in 19 + let env = forest.env in 20 + Eio.traceln "client created %d files" (List.length files); 21 + begin 22 + let@ {uri} = List.iter @~ files in 23 + let lsp_uri = L.DocumentUri.of_string uri in 24 + let uri = URI_scheme.lsp_uri_to_uri ~host lsp_uri in 25 + let path = Eio.Path.(env#fs / (L.DocumentUri.to_path lsp_uri)) in 26 + let doc = Imports.load_tree path in 27 + forest.={uri} <- Document doc 28 + end; 29 + let new_forest = Driver.run_until_done Parse_all forest in 30 + {lsp_state with forest = new_forest} 31 + )
+20 -10
lib/language_server/Forester_lsp.ml
··· 77 77 ~workDoneProgress: false 78 78 () 79 79 in 80 - let workspaceSymbolProvider = 81 - `WorkspaceSymbolOptions (L.WorkspaceSymbolOptions.create ()) 82 - in 83 - let documentSymbolProvider = 84 - `DocumentSymbolOptions (L.DocumentSymbolOptions.create ()) 80 + let workspaceSymbolProvider = `WorkspaceSymbolOptions (L.WorkspaceSymbolOptions.create ()) in 81 + let documentSymbolProvider = `DocumentSymbolOptions (L.DocumentSymbolOptions.create ()) in 82 + let workspace = 83 + L.ServerCapabilities.create_workspace 84 + ~fileOperations: ( 85 + L.FileOperationOptions.create 86 + ~didCreate: { 87 + filters = [ 88 + L.FileOperationFilter.create 89 + ~pattern: (L.FileOperationPattern.create ~glob: "**/*.tree" ()) 90 + () 91 + ] 92 + } 93 + () 94 + ) 95 + () 85 96 in 97 + 86 98 (* [NOTE: Position Encodings] 87 99 For various historical reasons, the spec states that we are _required_ to support UTF-16. 88 100 This causes more trouble than it's worth, so we always select UTF-8 as our encoding, even 89 101 if the client doesn't support it. *) 90 - let positionEncoding 91 - = 92 - L.PositionEncodingKind.UTF8 93 - in 94 - (* [FIME: Reed M, 09/06/2022] The current verison of the LSP library doesn't support 'positionEncoding' *) 102 + let positionEncoding = L.PositionEncodingKind.UTF8 in 103 + (* [FIXME: Reed M, 09/06/2022] The current verison of the LSP library doesn't support 'positionEncoding' *) 95 104 L.ServerCapabilities.create 96 105 ~textDocumentSync 97 106 ~hoverProvider ··· 104 113 ~documentSymbolProvider 105 114 ~documentLinkProvider 106 115 ~workspaceSymbolProvider 116 + ~workspace 107 117 () 108 118 109 119 let supports_utf8_encoding (init_params : L.InitializeParams.t) =
+3 -1
lib/language_server/Lsp_server.ml
··· 29 29 module Publish = Publish 30 30 module Semantic_tokens = Semantic_tokens 31 31 module Workspace_symbols = Workspace_symbols 32 + module Did_create_files = Did_create_files 32 33 end 33 34 34 35 module Semantic_tokens = Semantic_tokens ··· 81 82 | Shutdown -> initiate_shutdown () 82 83 | CodeAction params -> Code_action.compute params 83 84 | CodeActionResolve params -> Code_action.resolve params 84 - | ExecuteCommand params -> Code_action.execute params 85 + (* | ExecuteCommand params -> Code_action.execute params *) 85 86 | TextDocumentHover params -> Hover.compute params 86 87 | TextDocumentCompletion params -> Completion.compute params 87 88 | InlayHint params -> Inlay_hint.compute params ··· 132 133 | TextDocumentDidOpen params -> Did_open.compute params 133 134 | TextDocumentDidChange params -> Did_change.compute params 134 135 | ChangeConfiguration params -> Change_configuration.compute params 136 + (* | DidCreateFiles params -> Did_create_files.compute params *) 135 137 | DidSaveTextDocument _ -> () 136 138 | TextDocumentDidClose _ -> () 137 139 | _ ->
+1 -1
lib/language_server/Lsp_server.mli
··· 35 35 (** Reference: {{:https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction}[textDocument/codeAction]} 36 36 *) 37 37 module Code_action : sig 38 - val execute : Lsp.Types.ExecuteCommandParams.t -> Yojson.Safe.t 38 + (* val execute : Lsp.Types.ExecuteCommandParams.t -> Yojson.Safe.t *) 39 39 val compute : Lsp.Types.CodeActionParams.t -> Lsp.Types.CodeActionResult.t 40 40 end 41 41