-
Notifications
You must be signed in to change notification settings - Fork 764
Fix nil pointer dereference in completion at property start after JSDoc #2259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
e823278
9654302
ddf52a6
e64582b
4c877f7
d55224e
27b3371
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1447,7 +1447,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 { | ||
| keywordFilters = KeywordCompletionFiltersNone | ||
| } else if ast.IsClassLike(decl) { | ||
| keywordFilters = KeywordCompletionFiltersClassElementKeywords | ||
|
|
@@ -1461,17 +1461,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 | ||
|
|
@@ -2753,7 +2753,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()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can't possibly do anything anymore...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return contextToken, previousToken | ||
| } | ||
| return previousToken, previousToken | ||
|
|
||
There was a problem hiding this comment.
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
contextTokennotnil.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot obey.
There was a problem hiding this comment.
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).