Skip to content

Commit 63d9a41

Browse files
authored
LSP fix completion inside comments (#4214)
1 parent a713dea commit 63d9a41

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

private/buf/buflsp/completion.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,26 +1497,31 @@ func defToOptionMessage(file *file, def ast.DeclDef) ir.MessageValue {
14971497
return ir.MessageValue{}
14981498
}
14991499

1500+
// isTokenType returns true if the tokens are valid for a type declaration e.g "buf.registry.Type".
15001501
func isTokenType(tok token.Token) bool {
15011502
kind := tok.Kind()
15021503
return kind == token.Ident || (kind == token.Keyword && tok.Text() == ".")
15031504
}
15041505

1506+
// isTokenSpace returns true for spaces, excluding newlines.
15051507
func isTokenSpace(tok token.Token) bool {
15061508
return tok.Kind() == token.Space && strings.IndexByte(tok.Text(), '\n') == -1
15071509
}
15081510

1511+
// isTokenParen returns true for '(' or ')' tokens.
15091512
func isTokenParen(tok token.Token) bool {
15101513
return tok.Kind() == token.Keyword &&
15111514
(strings.HasPrefix(tok.Text(), "(") ||
15121515
strings.HasSuffix(tok.Text(), ")"))
15131516
}
15141517

1518+
// isTokenTypeDelimiter returns true if the token represents a delimiter for completion.
1519+
// A delimiter is a newline or start of stream. This handles invalid partial declarations.
15151520
func isTokenTypeDelimiter(tok token.Token) bool {
15161521
kind := tok.Kind()
15171522
return (kind == token.Unrecognized && tok.IsZero()) ||
15181523
(kind == token.Space && strings.IndexByte(tok.Text(), '\n') != -1) ||
1519-
(kind == token.Comment)
1524+
(kind == token.Comment && strings.HasSuffix(tok.Text(), "\n"))
15201525
}
15211526

15221527
// extractAroundOffset extracts the value around the offset by querying the token stream.

0 commit comments

Comments
 (0)