Skip to content

Commit 9cde1cd

Browse files
authored
Check for empty path components when parsing options in LSP (#4227)
1 parent b641342 commit 9cde1cd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Add `textDocument/rename` and `textDocument/prepareRename` support for `buf lsp serve`.
6+
- Fix panic in LSP for empty option paths.
67

78
## [v1.61.0] - 2025-11-25
89

private/buf/buflsp/file.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,17 @@ func (f *file) messageToSymbolsHelper(msg ir.MessageValue, index int, parents []
688688
//
689689
// In the example, in the second definition, (option) and .message for field_b has a
690690
// separate span from (option) and .message for field_a, but when we walk the mesasge
691-
// tree, we get the span for (option) and .mesage for the first field. So we check the
691+
// tree, we get the span for (option) and .message for the first field. So we check the
692692
// symbols we've collected so far in parents and make sure we have captured a symbol for
693693
// each path component.
694694
for element := range seq.Values(field.Elements()) {
695695
key := field.KeyASTs().At(element.ValueNodeIndex())
696696
components := slices.Collect(key.AsPath().Components)
697+
// If there are no path components for an element, then we skip it, since there are
698+
// no symbols to track.
699+
if len(components) == 0 {
700+
continue
701+
}
697702
var span source.Span
698703
// This covers the first case in the example above where the path is relative,
699704
// e.g. field_a is a relative path within { } for (option).message.

0 commit comments

Comments
 (0)