Skip to content

Commit 9707c25

Browse files
Tighten up item kinds (#4128)
1 parent 355a02f commit 9707c25

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

private/buf/buflsp/completion.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func completionItemsForKeyword(ctx context.Context, file *file, declPath []ast.D
262262
),
263263
keywordToCompletionItem(
264264
predeclaredTypeKeywords(),
265-
protocol.CompletionItemKindClass,
265+
protocol.CompletionItemKindKeyword,
266266
tokenSpan,
267267
offset,
268268
),
@@ -377,7 +377,7 @@ func completionItemsForField(ctx context.Context, file *file, declPath []ast.Dec
377377
iters = append(iters,
378378
keywordToCompletionItem(
379379
predeclaredTypeKeywords(),
380-
protocol.CompletionItemKindClass,
380+
protocol.CompletionItemKindKeyword,
381381
tokenSpan,
382382
offset,
383383
),
@@ -643,8 +643,16 @@ func typeReferencesToCompletionItems(
643643
editRange := reportSpanToProtocolRange(span)
644644
prefix, suffix := splitSpan(span, offset)
645645
for _, symbol := range fileSymbolTypesIter {
646-
if !symbol.ir.Kind().IsType() {
647-
continue
646+
// We only support types in this completion instance, and not scalar values, which leaves us
647+
// with messages and enums.
648+
var kind protocol.CompletionItemKind
649+
switch symbol.ir.Kind() {
650+
case ir.SymbolKindMessage:
651+
kind = protocol.CompletionItemKindClass // Messages are like classes
652+
case ir.SymbolKindEnum:
653+
kind = protocol.CompletionItemKindEnum
654+
default:
655+
continue // Unsupported kind, skip it.
648656
}
649657
label := string(symbol.ir.FullName())
650658
if strings.HasPrefix(label, parentPrefix) {
@@ -655,24 +663,6 @@ func typeReferencesToCompletionItems(
655663
if !strings.HasPrefix(label, prefix) || !strings.HasSuffix(label, suffix) {
656664
continue
657665
}
658-
var kind protocol.CompletionItemKind
659-
switch symbol.ir.Kind() {
660-
case ir.SymbolKindMessage:
661-
kind = protocol.CompletionItemKindStruct
662-
case ir.SymbolKindEnum:
663-
kind = protocol.CompletionItemKindEnum
664-
case ir.SymbolKindService:
665-
kind = protocol.CompletionItemKindInterface
666-
case ir.SymbolKindScalar:
667-
kind = protocol.CompletionItemKindClass
668-
case ir.SymbolKindPackage:
669-
kind = protocol.CompletionItemKindModule
670-
case ir.SymbolKindField, ir.SymbolKindEnumValue, ir.SymbolKindExtension, ir.SymbolKindOneof, ir.SymbolKindMethod:
671-
// These should be skipped by IsType() filter.
672-
}
673-
if kind == 0 {
674-
continue // Unsupported kind, skip it.
675-
}
676666
var isDeprecated bool
677667
if _, ok := symbol.ir.Deprecated().AsBool(); ok {
678668
isDeprecated = true

private/buf/buflsp/symbol.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ func (s *symbol) GetSymbolInformation() protocol.SymbolInformation {
307307
kind = protocol.SymbolKindInterface // Services are like interfaces
308308
case ir.SymbolKindMethod:
309309
kind = protocol.SymbolKindMethod
310+
case ir.SymbolKindScalar:
311+
kind = protocol.SymbolKindConstant
310312
default:
311313
kind = protocol.SymbolKindVariable
312314
}

0 commit comments

Comments
 (0)