@@ -156,22 +156,27 @@ func (cli *LSPClient) References(ctx context.Context, id Location) ([]Location,
156156 return resp , nil
157157}
158158
159- // Some language servers do not provide semanticTokens/range.
160- // In that case, we fall back to semanticTokens/full and then filter the tokens manually.
161159func (cli * LSPClient ) getSemanticTokensRange (ctx context.Context , req DocumentRange , resp * SemanticTokens ) error {
162- if cli .hasSemanticTokensRange {
163- if err := cli .Call (ctx , "textDocument/semanticTokens/range" , req , resp ); err != nil {
160+ f , err := cli .DidOpen (ctx , DocumentURI (req .TextDocument .URI ))
161+ if err != nil {
162+ return err
163+ }
164+
165+ if f .SemanticTokens == nil {
166+ req1 := SemanticTokensFullParams {
167+ TextDocument : req .TextDocument ,
168+ }
169+ var fullResp SemanticTokens
170+ if err := cli .Call (ctx , "textDocument/semanticTokens/full" , req1 , & fullResp ); err != nil {
164171 return err
165172 }
166- return nil
167- }
168- // fall back to semanticTokens/full
169- req1 := SemanticTokensFullParams {
170- TextDocument : req .TextDocument ,
171- }
172- if err := cli .Call (ctx , "textDocument/semanticTokens/full" , req1 , resp ); err != nil {
173- return err
173+ f .SemanticTokens = & fullResp
174174 }
175+
176+ resp .ResultID = f .SemanticTokens .ResultID
177+ resp .Data = make ([]uint32 , len (f .SemanticTokens .Data ))
178+ copy (resp .Data , f .SemanticTokens .Data )
179+
175180 filterSemanticTokensInRange (resp , req .Range )
176181 return nil
177182}
0 commit comments