From 4c95baf4341505fc6d133b35a716bd5c6b146c16 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Thu, 12 Dec 2024 14:06:28 -0500 Subject: [PATCH] Have SemanticTokensFull return nil on no symbols instead --- private/buf/buflsp/server.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/private/buf/buflsp/server.go b/private/buf/buflsp/server.go index 773a87b776..040bedd46f 100644 --- a/private/buf/buflsp/server.go +++ b/private/buf/buflsp/server.go @@ -410,10 +410,18 @@ func (s *server) SemanticTokensFull( progress.Begin(ctx, "Processing Tokens") defer progress.Done(ctx) + // In the case where there are no symbols for the file, we return nil for SemanticTokensFull. + // This is based on the specification for the method textDocument/semanticTokens/full, + // the expected response is the union type `SemanticTokens | null`. + // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_semanticTokens + if len(file.symbols) == 0 { + return nil, nil + } + var ( + encoded []uint32 prevLine, prevCol uint32 ) - encoded := []uint32{} for i, symbol := range file.symbols { progress.Report(ctx, fmt.Sprintf("%d/%d", i+1, len(file.symbols)), float64(i)/float64(len(file.symbols)))