-
Notifications
You must be signed in to change notification settings - Fork 12.8k
refactor: improve string export name completions #58818
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
refactor: improve string export name completions #58818
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
src/services/completions.ts
Outdated
if (needsConvertPropertyAccess && contextToken?.kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.QualifiedName) { | ||
replacementSpan = createTextSpanFromNode(contextToken, sourceFile); | ||
insertText = `[${quotePropertyName(sourceFile, preferences, name)}]`; | ||
} |
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.
Is it worth doing this if it's guaranteed to be wrong, compared to just not offering this?
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.
Yes, and I hope QualifiedName can contain ["stringLiteral"]
in the future, since now a type name may not be an identifier.
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.
What does the error message say when you land in this position? IMO it’s very annoying and confusing for completions to be invalid. It might be ok in this edge case if the diagnostic explains what’s going on and how to fix it, but if it’s just Module 'foo' has no export "non identifier"
, then I think we need to do better somehow, and I’d lean toward not offering the completion in the meantime.
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.
Code:
type z = x.
Before this PR:
type z = x.a b
// Namespace '...' has no exported member 'a'.
// ';' expected.
// Cannot find name 'b'.
After this PR:
type z = x['a b']
// Cannot use namespace 'x' as a type.
I think the error message becomes better
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.
But is that better than not offering the broken completion at all? I’m not sure.
ping @andrewbranch please take a look again thanks! |
My latest feedback stands—I don’t think we should offer invalid completions. |
I still think the completion I gave was better, but I removed that to satisfy the review requirement. Can you review this now, thanks! |
Thanks @Jack-Works! |
continue of #49297 and #58640