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