From ac75cc25f844171743d62399a01a33cc0b195917 Mon Sep 17 00:00:00 2001 From: am Date: Thu, 3 Jul 2025 23:26:27 +1000 Subject: [PATCH] less silly range impl --- bin/lsp/main.ml | 19 ++++++++++--------- lib/lsp/process_doc.ml | 39 +++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/bin/lsp/main.ml b/bin/lsp/main.ml index adebaee..051b6aa 100644 --- a/bin/lsp/main.ml +++ b/bin/lsp/main.ml @@ -236,18 +236,19 @@ class lsp_server = | Linol_lsp.Client_request.SemanticTokensRange { partialResultToken; range; textDocument; workDoneToken } -> log "semantic token range"; - let begin_range = LineCol.of_position range.start in - let end_range = LineCol.of_position range.end_ in + let begin_range : Token.t = + (LineCol.of_position range.start, 0) + in + let end_range : Token.t = (LineCol.of_position range.end_, -1) in let m = (match (Hashtbl.find buffers textDocument.uri).ast with - | Ast (p, syms) -> Some syms + | Ast (p, syms) -> Some syms.all_tokens | _ -> None) - |> Option.map Processor.get_semantic_token_map - |> Option.map - (TokenMap.filter (fun i _ -> - let pos = fst i in - LineCol.compare pos begin_range > 0 - && LineCol.compare pos end_range < 0)) + |> Option.map (fun m -> + match TokenMap.split begin_range m with + | l, data, r -> r) + |> Option.map (fun m -> + match TokenMap.split end_range m with l, data, r -> l) |> Option.map SemanticTokensProcessor.to_semantic_tokens_full in Lwt.return m diff --git a/lib/lsp/process_doc.ml b/lib/lsp/process_doc.ml index 5be7e05..e5f13e4 100644 --- a/lib/lsp/process_doc.ml +++ b/lib/lsp/process_doc.ml @@ -33,7 +33,7 @@ module Processor = struct all_tokens : SemanticTokensProcessor.t; } - let get_semantic_token_map (s : symbs) = + let semantic_tokens_from_symbs (s : symbs) = SemanticTokensProcessor.empty |> SemanticTokensProcessor.add (StringMap.to_seq s.proc_defs) (fun (_, di) -> @@ -47,11 +47,9 @@ module Processor = struct { token_type = "method"; token_modifiers = [] } |> SemanticTokensProcessor.add_tokmap s.proc_refs { token_type = "class"; token_modifiers = [] } - |> TokenMap.union (fun i a b -> Some a) s.all_tokens let to_semantic_highlight_data (s : symbs) = - SemanticTokensProcessor.to_semantic_tokens_full - (get_semantic_token_map s) + SemanticTokensProcessor.to_semantic_tokens_full s.all_tokens let get_syms (s : symbs) : Linol_lwt.DocumentSymbol.t list = let block_sym (blockname : string) (def : def_info) = @@ -197,15 +195,28 @@ module Processor = struct let process_cast (linebreaks : linebreaks) (p : moduleT) : symbs = let vis = new getBlocks linebreaks in + + let stokens = + Semantic_tokens.SemanticTokensFromAST.get_semtokens_of_cast linebreaks + p + in + let _ = visit_prog vis p in - { - proc_defs = vis#get_proc_defs; - proc_children = vis#get_proc_children; - block_defs = vis#get_block_defs; - proc_refs = vis#get_proc_refs; - block_refs = vis#get_block_refs; - all_tokens = - Semantic_tokens.SemanticTokensFromAST.get_semtokens_of_cast - linebreaks p; - } + let sym0 = + { + proc_defs = vis#get_proc_defs; + proc_children = vis#get_proc_children; + block_defs = vis#get_block_defs; + proc_refs = vis#get_proc_refs; + block_refs = vis#get_block_refs; + all_tokens = SemanticTokensProcessor.empty; + } + in + let all_tokens = + TokenMap.union + (fun i a b -> Some a) + stokens + (semantic_tokens_from_symbs sym0) + in + { sym0 with all_tokens } end