ocaml
0
fork

Configure Feed

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

improve hover handler

authored by

Kento Okura and committed by
Jon Sterling
56a4deae 9521a2ff

+28 -28
+27 -28
lib/language_server/Hover.ml
··· 8 8 open Forester_core 9 9 open Forester_compiler 10 10 open Forester_frontend 11 + open Forester_search 12 + open State.Syntax 11 13 12 14 module L = Lsp.Types 13 - (* module F = Analysis.F *) 14 - (* module PT = Analysis.PT *) 15 15 module T = Types 16 16 17 - let compute 18 - ({position; 19 - textDocument; 20 - _ 21 - }: 22 - L.HoverParams.t 23 - ) 24 - : L.Hover.t option 25 - = 17 + let (let*) = Option.bind 18 + 19 + let compute ({position; textDocument; _}: L.HoverParams.t) = 26 20 let Lsp_state.{forest; _} = Lsp_state.get () in 27 21 let render = 28 22 Plain_text_client.string_of_content ··· 31 25 in 32 26 let config = forest.config in 33 27 let host = config.host in 34 - let content = 35 - match State.get_code 36 - forest 37 - (URI_scheme.lsp_uri_to_uri ~host: forest.config.host textDocument.uri) with 38 - | None -> "code of current tree is not stored. this is a bug" 28 + let uri = URI_scheme.lsp_uri_to_uri ~host: forest.config.host textDocument.uri in 29 + let* content = 30 + match forest.={uri} with 31 + | None -> Reporter.fatal Internal_error ~extra_remarks: [Asai.Diagnostic.loctextf "%a is not in the index" URI.pp uri] 39 32 | Some tree -> 40 - (* TODO: use node_at and provide hover for things other than links.*) 41 - match Analysis.addr_at ~position tree.nodes with 42 - | None -> Format.asprintf "character: %i, line: %i." position.character position.line; 43 - | Some Range.{value = addr_at_cursor; _} -> 44 - let uri_under_cursor = URI_scheme.user_uri ~host addr_at_cursor in 45 - match State.get_article uri_under_cursor forest with 46 - | None -> 47 - Format.asprintf "Could not get article %a." URI.pp uri_under_cursor 48 - | Some {mainmatter; frontmatter; _} -> 49 - let main = render mainmatter in 50 - if main = "" then (Format.asprintf "%a" T.(pp_frontmatter pp_content) frontmatter) 51 - else main 33 + match Tree.to_code tree with 34 + | None -> None 35 + | Some {nodes; _} -> 36 + match Analysis.node_at ~position nodes with 37 + | None -> None 38 + | Some node -> 39 + let tree_under_cursor = 40 + let* {value = addr; _} = Analysis.extract_addr node in 41 + let uri_under_cursor = URI_scheme.user_uri ~host addr in 42 + State.get_article uri_under_cursor forest 43 + in 44 + match tree_under_cursor with 45 + | Some article -> Some (render article.mainmatter) 46 + | None -> 47 + let* doc = Tree.to_doc tree in 48 + let* search_term = Analysis.word_at ~position doc in 49 + let results = List.map snd @@ Index.search forest.search_index search_term in 50 + Some Format.(asprintf "Relevant results:@.%a@." (pp_print_list ~pp_sep: (fun out () -> fprintf out "@.") URI.pp) results) 52 51 in 53 52 Some 54 53 (
+1
lib/language_server/dune
··· 12 12 repr 13 13 unix 14 14 ocamlgraph 15 + forester.search 15 16 forester.prelude 16 17 forester.core 17 18 forester.compiler