Adds support for class completions after ASI inserted class property definition#32243
Merged
Conversation
Signed-off-by: Andrew Branch <andrew.branch@microsoft.com>
andrewbranch
approved these changes
Jul 3, 2019
| if (!isFromObjectTypeDeclaration(contextToken)) return undefined; | ||
| if (!isFromObjectTypeDeclaration(contextToken)) { | ||
| // class c extends React.Component { a: () => 1\n| } | ||
| if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) { |
Member
There was a problem hiding this comment.
Adding the isObjectTypeDeclaration(location) miiiight have been overly conservative, but I suggested it to err on the side of caution—the smallest reasonable net I could think of that would catch the repros provided.
sheetalkamat
reviewed
Jul 8, 2019
| if (!isFromObjectTypeDeclaration(contextToken)) return undefined; | ||
| if (!isFromObjectTypeDeclaration(contextToken)) { | ||
| // class c extends React.Component { a: () => 1\n| } | ||
| if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) { |
Member
There was a problem hiding this comment.
Can you please reverse the order of checks here (that is checking isObjectTypeDeclaration(location) before line?
Contributor
Author
There was a problem hiding this comment.
Switching the if ordering changes the behavior from what it previously was, and starts to trigger behavior which I think we don't want.
This fourslash test fails:
/// <reference path="fourslash.ts" />
////function /*a*/ ;
////function* /*b*/ ;
////interface I {
//// abstract baseMethod(): Iterable<number>;
////}
////class C implements I {
//// */*c*/ ;
//// public */*d*/
////}
////const o: I = {
//// */*e*/
////};
////1 * /*f*/
verify.completions(
{ marker: ["a", "b"], exact: undefined, isNewIdentifierLocation: true },
{ marker: ["c", "d"], exact: ["baseMethod"], isNewIdentifierLocation: true },
{ marker: "e", exact: ["baseMethod"] },
{ marker: "f", includes: [{ name: "Number", sortText: completion.SortText.GlobalsOrKeywords }] },
);
With
1) fourslash tests
tests/cases/fourslash/completionsGeneratorFunctions.ts
fourslash test completionsGeneratorFunctions.ts runs correctly:
Error: At f: Expected 'isNewIdentifierLocation' to be false, got true
Which is returning an empty array of completions
sandersn
approved these changes
Jul 10, 2019
Contributor
Author
|
Alright I'm merging this 👍 |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #30536 - handles both the case where you start writing on a newline directly, and when you are continuing to write inside an identifier.