Skip to content
Open
10 changes: 5 additions & 5 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ func (l *LanguageService) getCompletionData(
completionKind = CompletionKindMemberLike
// Declaring new property/method/accessor
isNewIdentifierLocation = true
if contextToken.Kind == ast.KindAsteriskToken {
if contextToken != nil && contextToken.Kind == ast.KindAsteriskToken {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do all of those defensive checks in Strada, so we should not need them here, just need the actual fix that makes the contextToken not nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot obey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the defensive nil checks. The fix now only includes the variable shadowing correction in getRelevantTokens (commit 4c877f7).

keywordFilters = KeywordCompletionFiltersNone
} else if ast.IsClassLike(decl) {
keywordFilters = KeywordCompletionFiltersClassElementKeywords
Expand All @@ -1458,17 +1458,17 @@ func (l *LanguageService) getCompletionData(
}

var classElement *ast.Node
if contextToken.Kind == ast.KindSemicolonToken {
if contextToken != nil && contextToken.Kind == ast.KindSemicolonToken {
classElement = contextToken.Parent.Parent
} else {
} else if contextToken != nil {
classElement = contextToken.Parent
}
var classElementModifierFlags ast.ModifierFlags
if ast.IsClassElement(classElement) {
classElementModifierFlags = classElement.ModifierFlags()
}
// If this is context token is not something we are editing now, consider if this would lead to be modifier.
if contextToken.Kind == ast.KindIdentifier && !isCurrentlyEditingNode(contextToken, file, position) {
if contextToken != nil && contextToken.Kind == ast.KindIdentifier && !isCurrentlyEditingNode(contextToken, file, position) {
switch contextToken.Text() {
case "private":
classElementModifierFlags |= ast.ModifierFlagsPrivate
Expand Down Expand Up @@ -2750,7 +2750,7 @@ func getSourceFromOrigin(origin *symbolOriginInfo) string {
func getRelevantTokens(position int, file *ast.SourceFile) (contextToken *ast.Node, previousToken *ast.Node) {
previousToken = astnav.FindPrecedingToken(file, position)
if previousToken != nil && position <= previousToken.End() && (ast.IsMemberName(previousToken) || ast.IsKeywordKind(previousToken.Kind)) {
contextToken := astnav.FindPrecedingToken(file, previousToken.Pos())
contextToken = astnav.FindPrecedingToken(file, previousToken.Pos())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't possibly do anything anymore...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - the variable shadowing fix alone wasn't sufficient. The issue was that tryGetObjectTypeDeclarationCompletionContainer could return a non-nil declaration even when contextToken was nil (specifically in the Identifier case at line 4166). I've added a nil check there: if contextToken != nil && isFromObjectTypeDeclaration(location) (commit 27b3371).

return contextToken, previousToken
}
return previousToken, previousToken
Expand Down
Loading