Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c26ac2

Browse filesBrowse files
author
Orta
authored
Merge pull request microsoft#32243 from orta/fix-30536
Adds support for class completions after ASI inserted class property definition
2 parents 4bb0aae + e55f97e commit 2c26ac2
Copy full SHA for 2c26ac2

5 files changed

+39-6Lines changed: 39 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/completions.ts‎

Copy file name to clipboardExpand all lines: src/services/completions.ts
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ namespace ts.Completions {
16171617
* Relevant symbols are stored in the captured 'symbols' variable.
16181618
*/
16191619
function tryGetClassLikeCompletionSymbols(): GlobalsSearch {
1620-
const decl = tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location);
1620+
const decl = tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position);
16211621
if (!decl) return GlobalsSearch.Continue;
16221622

16231623
// We're looking up possible property names from parent type.
@@ -2234,7 +2234,7 @@ namespace ts.Completions {
22342234
* Returns the immediate owning class declaration of a context token,
22352235
* on the condition that one exists and that the context implies completion should be given.
22362236
*/
2237-
function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile, contextToken: Node | undefined, location: Node): ObjectTypeDeclaration | undefined {
2237+
function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile, contextToken: Node | undefined, location: Node, position: number): ObjectTypeDeclaration | undefined {
22382238
// class c { method() { } | method2() { } }
22392239
switch (location.kind) {
22402240
case SyntaxKind.SyntaxList:
@@ -2244,9 +2244,15 @@ namespace ts.Completions {
22442244
if (cls && !findChildOfKind(cls, SyntaxKind.CloseBraceToken, sourceFile)) {
22452245
return cls;
22462246
}
2247+
break;
2248+
case SyntaxKind.Identifier: // class c extends React.Component { a: () => 1\n compon| }
2249+
if (isFromObjectTypeDeclaration(location)) {
2250+
return findAncestor(location, isObjectTypeDeclaration);
2251+
}
22472252
}
22482253

22492254
if (!contextToken) return undefined;
2255+
22502256
switch (contextToken.kind) {
22512257
case SyntaxKind.SemicolonToken: // class c {getValue(): number; | }
22522258
case SyntaxKind.CloseBraceToken: // class c { method() { } | }
@@ -2258,7 +2264,13 @@ namespace ts.Completions {
22582264
case SyntaxKind.CommaToken: // class c {getValue(): number, | }
22592265
return tryCast(contextToken.parent, isObjectTypeDeclaration);
22602266
default:
2261-
if (!isFromObjectTypeDeclaration(contextToken)) return undefined;
2267+
if (!isFromObjectTypeDeclaration(contextToken)) {
2268+
// class c extends React.Component { a: () => 1\n| }
2269+
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) {
2270+
return location;
2271+
}
2272+
return undefined;
2273+
}
22622274
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
22632275
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(stringToToken(contextToken.text)!)) // TODO: GH#18217
22642276
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
Collapse file

‎src/services/types.ts‎

Copy file name to clipboardExpand all lines: src/services/types.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ namespace ts {
892892
}
893893

894894
export interface CompletionInfo {
895-
/** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
895+
/** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
896896
isGlobalCompletion: boolean;
897897
isMemberCompletion: boolean;
898898

Collapse file

‎tests/baselines/reference/api/tsserverlibrary.d.ts‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/api/tsserverlibrary.d.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5404,7 +5404,7 @@ declare namespace ts {
54045404
argumentCount: number;
54055405
}
54065406
interface CompletionInfo {
5407-
/** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
5407+
/** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
54085408
isGlobalCompletion: boolean;
54095409
isMemberCompletion: boolean;
54105410
/**
Collapse file

‎tests/baselines/reference/api/typescript.d.ts‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/api/typescript.d.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5404,7 +5404,7 @@ declare namespace ts {
54045404
argumentCount: number;
54055405
}
54065406
interface CompletionInfo {
5407-
/** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
5407+
/** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
54085408
isGlobalCompletion: boolean;
54095409
isMemberCompletion: boolean;
54105410
/**
Collapse file
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// class Parent {
4+
//// protected shouldWork() {
5+
//// console.log();
6+
//// }
7+
//// }
8+
////
9+
//// class Child extends Parent {
10+
//// // this assumes ASI, but on next line wants to
11+
//// x = () => 1
12+
//// shoul/*insideid*/
13+
//// }
14+
////
15+
//// class ChildTwo extends Parent {
16+
//// // this assumes ASI, but on next line wants to
17+
//// x = () => 1
18+
//// /*root*/ //nothing
19+
//// }
20+
21+
verify.completions({ marker: ["insideid", "root"], includes: "shouldWork", isNewIdentifierLocation: true });

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.