Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lang/lsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type LSPClient struct {
*lspHandler
tokenTypes []string
tokenModifiers []string
hasSemanticTokensRange bool
files map[DocumentURI]*TextDocumentItem
provider LanguageServiceProvider
ClientOptions
Expand Down Expand Up @@ -193,8 +192,6 @@ func initLSPClient(ctx context.Context, svr io.ReadWriteCloser, dir DocumentURI,
if !ok || semanticTokensProvider == nil {
return nil, fmt.Errorf("server did not provide SemanticTokensProvider")
}
semanticTokensRange, ok := semanticTokensProvider["range"].(bool)
cli.hasSemanticTokensRange = ok && semanticTokensRange
legend, ok := semanticTokensProvider["legend"].(map[string]interface{})
if !ok || legend == nil {
return nil, fmt.Errorf("server did not provide SemanticTokensProvider.legend")
Expand Down
15 changes: 8 additions & 7 deletions lang/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ func NewURI(file string) DocumentURI {
}

type TextDocumentItem struct {
URI DocumentURI `json:"uri"`
LanguageID string `json:"languageId"`
Version int `json:"version"`
Text string `json:"text"`
LineCounts []int `json:"-"`
Symbols map[Range]*DocumentSymbol `json:"-"`
Definitions map[Position][]Location `json:"-"`
URI DocumentURI `json:"uri"`
LanguageID string `json:"languageId"`
Version int `json:"version"`
Text string `json:"text"`
LineCounts []int `json:"-"`
Symbols map[Range]*DocumentSymbol `json:"-"`
Definitions map[Position][]Location `json:"-"`
SemanticTokens *SemanticTokens `json:"-"`
}

type DocumentSymbol struct {
Expand Down
29 changes: 17 additions & 12 deletions lang/lsp/lsp_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,27 @@ func (cli *LSPClient) References(ctx context.Context, id Location) ([]Location,
return resp, nil
}

// Some language servers do not provide semanticTokens/range.
// In that case, we fall back to semanticTokens/full and then filter the tokens manually.
func (cli *LSPClient) getSemanticTokensRange(ctx context.Context, req DocumentRange, resp *SemanticTokens) error {
if cli.hasSemanticTokensRange {
if err := cli.Call(ctx, "textDocument/semanticTokens/range", req, resp); err != nil {
f, err := cli.DidOpen(ctx, DocumentURI(req.TextDocument.URI))
if err != nil {
return err
}

if f.SemanticTokens == nil {
req1 := SemanticTokensFullParams{
TextDocument: req.TextDocument,
}
var fullResp SemanticTokens
if err := cli.Call(ctx, "textDocument/semanticTokens/full", req1, &fullResp); err != nil {
return err
}
return nil
}
// fall back to semanticTokens/full
req1 := SemanticTokensFullParams{
TextDocument: req.TextDocument,
}
if err := cli.Call(ctx, "textDocument/semanticTokens/full", req1, resp); err != nil {
return err
f.SemanticTokens = &fullResp
}

resp.ResultID = f.SemanticTokens.ResultID
resp.Data = make([]uint32, len(f.SemanticTokens.Data))
copy(resp.Data, f.SemanticTokens.Data)

filterSemanticTokensInRange(resp, req.Range)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion lang/utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CountFiles(dir string, subfix string, skipdir string) (int, int) {
skipdir, _ = filepath.Abs(filepath.Join(dir, skipdir))
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if strings.HasPrefix(path, skipdir) {
return nil
return filepath.SkipDir
}
if !info.IsDir() && filepath.Ext(path) == subfix {
count++
Expand Down
2 changes: 1 addition & 1 deletion testdata/asts/localsession_g.json

Large diffs are not rendered by default.

Loading