Skip to content

Commit 5906a3a

Browse files
Add more context to completion items (#4117)
1 parent 84c1abe commit 5906a3a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

private/buf/buflsp/completion.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
457457
}
458458

459459
var items []protocol.CompletionItem
460-
for importPath := range file.importToFile {
460+
for importPath, importFile := range file.importToFile {
461461
suggest := fmt.Sprintf("%q", importPath)
462462
if !strings.HasPrefix(suggest, prefix) || !strings.HasSuffix(suggest, suffix) {
463463
file.lsp.logger.Debug("completion: skipping on prefix/suffix",
@@ -469,6 +469,10 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
469469
continue
470470
}
471471

472+
var importFileIsDeprecated bool
473+
if _, ok := importFile.ir.Deprecated().AsBool(); ok {
474+
importFileIsDeprecated = true
475+
}
472476
items = append(items, protocol.CompletionItem{
473477
Label: importPath,
474478
Kind: protocol.CompletionItemKindFile,
@@ -480,6 +484,7 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
480484
NewText: suggest[len(prefix) : len(suggest)-len(suffix)],
481485
},
482486
AdditionalTextEdits: additionalTextEdits,
487+
Deprecated: importFileIsDeprecated,
483488
})
484489
}
485490
return items
@@ -651,7 +656,8 @@ func typeReferencesToCompletionItems(
651656
Range: editRange,
652657
NewText: label,
653658
},
654-
Deprecated: isDeprecated,
659+
Deprecated: isDeprecated,
660+
Documentation: symbol.FormatDocs(),
655661
// TODO: If this type's file is not currently imported add an additional edit.
656662
}) {
657663
break

private/buf/buflsp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (s *server) Hover(
333333
return nil, nil
334334
}
335335

336-
docs := symbol.FormatDocs(ctx)
336+
docs := symbol.FormatDocs()
337337
if docs == "" {
338338
return nil, nil
339339
}

private/buf/buflsp/symbol.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package buflsp
2222

2323
import (
24-
"context"
2524
"fmt"
2625
"log/slog"
2726
"slices"
@@ -184,7 +183,7 @@ func (s *symbol) LogValue() slog.Value {
184183
// string for showing to the client.
185184
//
186185
// Returns the empty string if no docs are available.
187-
func (s *symbol) FormatDocs(ctx context.Context) string {
186+
func (s *symbol) FormatDocs() string {
188187
var def ast.DeclDef
189188
switch s.kind.(type) {
190189
case *imported:
@@ -265,12 +264,7 @@ func (s *symbol) FormatDocs(ctx context.Context) string {
265264
reference, _ := s.kind.(*reference)
266265
def = reference.def
267266
}
268-
var tooltip strings.Builder
269-
docs := getCommentsFromDef(def)
270-
if docs != "" {
271-
fmt.Fprintln(&tooltip, docs)
272-
}
273-
return tooltip.String()
267+
return getCommentsFromDef(def)
274268
}
275269

276270
// GetSymbolInformation returns the protocol symbol information for the symbol.

0 commit comments

Comments
 (0)