From 1539cac6101b9ad5ed7ec26c10f6b62e2e0dffab Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Thu, 12 Dec 2024 17:11:27 -0500 Subject: [PATCH] Have `SemanticTokensFull` return `nil` when no symbols are available for the file (#3531) --- private/buf/buflsp/server.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/private/buf/buflsp/server.go b/private/buf/buflsp/server.go index e6f79f1512..040bedd46f 100644 --- a/private/buf/buflsp/server.go +++ b/private/buf/buflsp/server.go @@ -410,6 +410,14 @@ 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