ocaml
0
fork

Configure Feed

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

lsp: workspace symbols

also adds infrastructure for document links and code actions.

authored by

Kento Okura and committed by
Jon Sterling
344675b0 0f7a46a3

+113 -6
+3 -3
lib/language_server/Analysis.ml
··· 29 29 let paths_of_dirs ~env = 30 30 List.map (path_of_dir ~env) 31 31 32 - let build_once ~env (state : Base.server) () = 33 - let tree_dirs = (paths_of_dirs ~env state.config.trees) in 32 + let build_once (state : Base.server) () = 33 + let tree_dirs = (paths_of_dirs ~env: state.env state.config.trees) in 34 34 Eio.traceln "Planting forest"; 35 35 let parsed_trees = 36 36 Forester_frontend.Forester.parse_trees_in_dirs ··· 62 62 try 63 63 let articles, _ = 64 64 Forester_frontend.Forest_reader.read_trees 65 - ~env 65 + ~env: state.env 66 66 ~host: state.config.host 67 67 parsed_trees 68 68 in
-1
lib/language_server/Analysis.mli
··· 12 12 val check : Base.server -> L.DocumentUri.t -> unit 13 13 14 14 val build_once : 15 - env: Forester_frontend.Forest_reader.env -> 16 15 Base.server -> 17 16 unit -> 18 17 unit
+12 -1
lib/language_server/Forester_lsp.ml
··· 69 69 `SemanticTokensOptions 70 70 (L.SemanticTokensOptions.create ~legend: Semantic_tokens.legend ~full ()) 71 71 in 72 + let documentLinkProvider = 73 + L.DocumentLinkOptions.create 74 + ~resolveProvider: true 75 + ~workDoneProgress: false 76 + () 77 + in 78 + let workspaceSymbolProvider = 79 + `WorkspaceSymbolOptions (L.WorkspaceSymbolOptions.create ()) 80 + in 72 81 (* [NOTE: Position Encodings] 73 82 For various historical reasons, the spec states that we are _required_ to support UTF-16. 74 83 This causes more trouble than it's worth, so we always select UTF-8 as our encoding, even ··· 88 97 ~completionProvider 89 98 ~definitionProvider 90 99 ~semanticTokensProvider 100 + ~documentLinkProvider 101 + ~workspaceSymbolProvider 91 102 () 92 103 93 104 let supports_utf8_encoding (init_params : L.InitializeParams.t) = ··· 193 204 should_shutdown = false; 194 205 } 195 206 in 196 - Analysis.build_once ~env init (); 207 + Analysis.build_once init (); 197 208 Server.run ~init @@ 198 209 fun () -> 199 210 begin
+98 -1
lib/language_server/LspServer.ml
··· 102 102 103 103 (* [TODO: Reed M, 12/12/2022] No code actions for now. *) 104 104 let code_action (_params : L.CodeActionParams.t) : L.CodeActionResult.t = 105 - None 105 + let action = L.CodeAction.create ~title: "find tree" () in 106 + Some [`CodeAction action] 106 107 107 108 let completion 108 109 (params : L.CompletionParams.t) ··· 281 282 code 282 283 |> Option.some 283 284 285 + (* TODO: handle external links as well? *) 286 + let document_link (params : L.DocumentLinkParams.t) = 287 + match params with 288 + | { textDocument; _ } -> 289 + let server = State.get () in 290 + let links = 291 + match Hashtbl.find_opt server.codes textDocument with 292 + | Some tree -> 293 + begin 294 + tree.code 295 + |> List.filter_map 296 + ( 297 + fun node -> 298 + match Range.(node.value) with 299 + | Code.Group (Squares, [{ value = Text addr; _ }]) 300 + | Code.Group (Parens, [{ value = Text addr; _ }]) 301 + | Code.Group (Braces, [{ value = Text addr; _ }]) -> 302 + (* TODO: Need to analyse syn *) 303 + let range = (LspShims.Loc.lsp_range_of_range node.loc) in 304 + let iri = (Iri_scheme.user_iri ~host: server.config.host addr) in 305 + let* target = Hashtbl.find_opt server.resolver iri in 306 + let* { frontmatter; _ } = F.get_article iri in 307 + let* tooltip = Option.map PT.string_of_content frontmatter.title in 308 + let link = 309 + L.DocumentLink.create 310 + ~range 311 + ~target: target.uri 312 + ~tooltip 313 + () 314 + in 315 + Some link 316 + | _ -> 317 + None 318 + ) 319 + end 320 + | None -> 321 + [] 322 + in 323 + Some links 324 + 325 + (* I don't understand this request...*) 326 + let document_link_resolve (params : L.DocumentLink.t) = 327 + match params with 328 + | link -> 329 + link 330 + 331 + let workspace_symbol (_params : L.WorkspaceSymbolParams.t) = 332 + (* let _s = L.WorkspaceSymbol.create ~name: "test" () in *) 333 + let server = State.get () in 334 + let symbols = 335 + server.codes 336 + |> Hashtbl.to_seq 337 + |> Seq.map 338 + ( 339 + fun ((ident : L.TextDocumentIdentifier.t), _) -> 340 + let location = 341 + L.Location.{ 342 + range = L.Range.{ 343 + end_ = { character = 0; line = 0; }; 344 + start = { character = 0; line = 0; }; 345 + }; 346 + uri = ident.uri 347 + } 348 + in 349 + let iri = 350 + ident.uri 351 + |> Lsp.Uri.to_path 352 + |> String.split_on_char '/' 353 + |> List.rev 354 + |> List.hd 355 + |> Filename.chop_extension 356 + |> Iri_scheme.user_iri ~host: server.config.host 357 + in 358 + let title = 359 + match F.get_article iri with 360 + | None -> "untitled" 361 + | Some { frontmatter; _ } -> 362 + begin 363 + match frontmatter.title with 364 + | None -> "untitled" 365 + | Some content -> 366 + PT.string_of_content content 367 + end 368 + in 369 + L.SymbolInformation.create ~kind: File ~location ~name: title () 370 + ) 371 + |> List.of_seq 372 + in 373 + Some symbols 374 + 284 375 module Request = struct 285 376 type 'resp t = 'resp Lsp.Client_request.t 286 377 type packed = Lsp_Request.packed ··· 306 397 Semantic_tokens.on_delta_request params 307 398 | SemanticTokensFull params -> 308 399 Semantic_tokens.on_full_request params 400 + | TextDocumentLink params -> 401 + document_link params 402 + | TextDocumentLinkResolve params -> 403 + document_link_resolve params 404 + | WorkspaceSymbol params -> 405 + workspace_symbol params 309 406 | _ -> 310 407 raise @@ LspError (UnknownRequest mthd) 311 408