-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Exclude literal completions after closing quote and JSX attribute location #52676
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
Merged
andrewbranch
merged 4 commits into
microsoft:main
from
zardoy:exclude-literal-completions
Feb 28, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,15 @@ | |
|
|
||
| // @jsx: preserve | ||
| // @filename: /a.tsx | ||
| ////type Props = { a: number } | { b: "somethingelse" }; | ||
| ////type Props = { a: number } | { b: "somethingelse", c: 0 | 1 }; | ||
| ////declare function Foo(args: Props): any | ||
| //// | ||
| ////const a1 = <Foo b={"/*1*/"} /> | ||
| ////const a2 = <Foo b="/*2*/" /> | ||
| ////const a3 = <Foo b="somethingelse"/*3*/ /> | ||
| ////const a4 = <Foo b={"somethingelse"} /*4*/ /> | ||
| ////const a5 = <Foo b={"somethingelse"} c={0} /*5*/ /> | ||
|
|
||
| verify.completions({ marker: ["1", "2"], exact: ["somethingelse"] }); | ||
| verify.completions({ marker: ["3", "4"], excludes: ['"somethingelse"'], }); | ||
|
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. didn't use exact: [a], because |
||
| verify.completions({ marker: ["5"], excludes: ["0", "1"], }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Basically it always disallow literal completions in string and
identifierlocations. I wonder wether it can break any edge cases I don't know about?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.
You could instead use
isInStringOrRegularExpressionOrTemplateLiteralwhich will tell you if you're inside of the node (even if that node is unterminated).TypeScript/src/services/completions.ts
Line 3694 in 1c822c4
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.
@DanielRosenwasser so as I understand your proposal is to replace
isStringLiteralLikewithisInStringOrRegularExpressionOrTemplateLiteral, but whats the difference? Am I missing something?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.
If I understand correctly, the second one checks if the position is inside of the string, whereas the original just checks if the previous token is a string or template string. You might still want to keep
isStringLiteralLike, but you want to check if the cursor is actually inside of the string.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 do I need this check? What issue it covers? I'm pretty sure there is already check if I'm inside of the string
TypeScript/src/services/stringCompletions.ts
Lines 198 to 200 in d0938c8
I have two checks for two issues correspondly, first one checks if the previous token is a string and second checks if jsx attribute identifier expected (see added tests). In the second check token is not necessarily is string: playground.
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.
I think I see - it sounds like the idea that the previous token the the one immediately to the left of the original context token, so we could not have been inside of the string. Is that right?
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.
previousTokenis either the token you’re currently typing or one behind, if you closed out a token but haven’t started typing a new one yet:but, when the cursor is inside the string, a different code path would have already handled that and returned results from
stringCompletions.ts. So in this case, we know we’re not inside the string. (Confusingly,stringCompletions.tsdoesn’t handle completions of entire string literals including the quotes; it only handles completions inside existing string literals.)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.
Wow this is really great explanation of first check. Thank you so much, I wish I could write same explanations in first place 😄