mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
fix(52212): No member completions, and irrelevant value completions, when class property initializer has no semicolon (#52213)
This commit is contained in:
parent
41e4139357
commit
86ccd20e53
@ -4829,7 +4829,7 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
|
||||
return cls;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Identifier: {
|
||||
case SyntaxKind.Identifier: {
|
||||
const originalKeywordKind = identifierToKeywordKind(location as Identifier);
|
||||
if (originalKeywordKind) {
|
||||
return undefined;
|
||||
@ -4868,16 +4868,17 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
|
||||
case SyntaxKind.CommaToken: // class c {getValue(): number, | }
|
||||
return tryCast(contextToken.parent, isObjectTypeDeclaration);
|
||||
default:
|
||||
if (!isFromObjectTypeDeclaration(contextToken)) {
|
||||
// class c extends React.Component { a: () => 1\n| }
|
||||
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) {
|
||||
if (isObjectTypeDeclaration(location)) {
|
||||
// class C extends React.Component { a: () => 1\n| }
|
||||
// class C { prop = ""\n | }
|
||||
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line) {
|
||||
return location;
|
||||
}
|
||||
return undefined;
|
||||
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
|
||||
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
|
||||
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
|
||||
}
|
||||
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
|
||||
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
|
||||
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
230
tests/baselines/reference/completionsClassMembers1.baseline
Normal file
230
tests/baselines/reference/completionsClassMembers1.baseline
Normal file
@ -0,0 +1,230 @@
|
||||
[
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/completionsClassMembers1.ts",
|
||||
"position": 93,
|
||||
"name": ""
|
||||
},
|
||||
"completionList": {
|
||||
"flags": 0,
|
||||
"isGlobalCompletion": false,
|
||||
"isMemberCompletion": true,
|
||||
"isNewIdentifierLocation": true,
|
||||
"entries": [
|
||||
{
|
||||
"name": "method",
|
||||
"kind": "method",
|
||||
"kindModifiers": "",
|
||||
"sortText": "11",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "text"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "I",
|
||||
"kind": "interfaceName"
|
||||
},
|
||||
{
|
||||
"text": ".",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "methodName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "void",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
},
|
||||
{
|
||||
"name": "abstract",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "abstract",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "accessor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "accessor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "async",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "async",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "constructor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "constructor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "declare",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "declare",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "get",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "get",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "override",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "override",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "private",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "private",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "protected",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "protected",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "public",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "public",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "readonly",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "readonly",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "set",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "set",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "static",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "static",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
235
tests/baselines/reference/completionsClassMembers2.baseline
Normal file
235
tests/baselines/reference/completionsClassMembers2.baseline
Normal file
@ -0,0 +1,235 @@
|
||||
[
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/completionsClassMembers2.ts",
|
||||
"position": 93,
|
||||
"name": ""
|
||||
},
|
||||
"completionList": {
|
||||
"flags": 0,
|
||||
"isGlobalCompletion": false,
|
||||
"isMemberCompletion": true,
|
||||
"isNewIdentifierLocation": true,
|
||||
"entries": [
|
||||
{
|
||||
"name": "abstract",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "abstract",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "accessor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "accessor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "async",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "async",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "constructor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "constructor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "declare",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "declare",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "get",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "get",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "override",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "override",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "private",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "private",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "protected",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "protected",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "public",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "public",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "readonly",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "readonly",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "set",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "set",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "static",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "static",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "method",
|
||||
"kind": "method",
|
||||
"kindModifiers": "",
|
||||
"sortText": "17",
|
||||
"insertText": "method(): void {\r\n}",
|
||||
"replacementSpan": {
|
||||
"start": 71,
|
||||
"length": 16
|
||||
},
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "text"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "I",
|
||||
"kind": "interfaceName"
|
||||
},
|
||||
{
|
||||
"text": ".",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "methodName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "void",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
230
tests/baselines/reference/completionsClassMembers3.baseline
Normal file
230
tests/baselines/reference/completionsClassMembers3.baseline
Normal file
@ -0,0 +1,230 @@
|
||||
[
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/completionsClassMembers3.ts",
|
||||
"position": 101,
|
||||
"name": ""
|
||||
},
|
||||
"completionList": {
|
||||
"flags": 0,
|
||||
"isGlobalCompletion": false,
|
||||
"isMemberCompletion": true,
|
||||
"isNewIdentifierLocation": true,
|
||||
"entries": [
|
||||
{
|
||||
"name": "method",
|
||||
"kind": "method",
|
||||
"kindModifiers": "",
|
||||
"sortText": "11",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "text"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "I",
|
||||
"kind": "interfaceName"
|
||||
},
|
||||
{
|
||||
"text": ".",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "method",
|
||||
"kind": "methodName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "void",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
},
|
||||
{
|
||||
"name": "abstract",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "abstract",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "accessor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "accessor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "async",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "async",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "constructor",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "constructor",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "declare",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "declare",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "get",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "get",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "override",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "override",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "private",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "private",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "protected",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "protected",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "public",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "public",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "readonly",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "readonly",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "set",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "set",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "static",
|
||||
"kind": "keyword",
|
||||
"kindModifiers": "",
|
||||
"sortText": "15",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "static",
|
||||
"kind": "keyword"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
13
tests/cases/fourslash/completionsClassMembers1.ts
Normal file
13
tests/cases/fourslash/completionsClassMembers1.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface I {
|
||||
//// method(): void;
|
||||
////}
|
||||
////
|
||||
////export class C implements I {
|
||||
//// property = "foo"
|
||||
////
|
||||
//// /**/
|
||||
////}
|
||||
|
||||
verify.baselineCompletions();
|
||||
16
tests/cases/fourslash/completionsClassMembers2.ts
Normal file
16
tests/cases/fourslash/completionsClassMembers2.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface I {
|
||||
//// method(): void;
|
||||
////}
|
||||
////
|
||||
////export class C implements I {
|
||||
//// property = "foo"
|
||||
////
|
||||
//// /**/
|
||||
////}
|
||||
|
||||
verify.baselineCompletions({
|
||||
includeCompletionsWithInsertText: true,
|
||||
includeCompletionsWithClassMemberSnippets: true,
|
||||
});
|
||||
13
tests/cases/fourslash/completionsClassMembers3.ts
Normal file
13
tests/cases/fourslash/completionsClassMembers3.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface I {
|
||||
//// method(): void;
|
||||
////}
|
||||
////
|
||||
////export class C implements I {
|
||||
//// property = "foo" + "foo"
|
||||
////
|
||||
//// /**/
|
||||
////}
|
||||
|
||||
verify.baselineCompletions();
|
||||
Loading…
x
Reference in New Issue
Block a user