Added new keword compeltion filter for assertions
This commit is contained in:
parent
74805c2e23
commit
b2c555a57d
2 changed files with 30 additions and 8 deletions
|
@ -38,6 +38,7 @@ namespace ts.Completions {
|
|||
InterfaceElementKeywords, // Keywords inside interface body
|
||||
ConstructorParameterKeywords, // Keywords at constructor parameter
|
||||
FunctionLikeBodyKeywords, // Keywords at function like body
|
||||
TypeAssertionKeywords,
|
||||
TypeKeywords,
|
||||
Last = TypeKeywords
|
||||
}
|
||||
|
@ -1181,7 +1182,11 @@ namespace ts.Completions {
|
|||
function filterGlobalCompletion(symbols: Symbol[]): void {
|
||||
const isTypeOnly = isTypeOnlyCompletion();
|
||||
const allowTypes = isTypeOnly || !isContextTokenValueLocation(contextToken) && isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker);
|
||||
if (isTypeOnly) keywordFilters = KeywordCompletionFilters.TypeKeywords;
|
||||
if (isTypeOnly) {
|
||||
keywordFilters = isInsideTypeAssertion()
|
||||
? KeywordCompletionFilters.TypeAssertionKeywords
|
||||
: KeywordCompletionFilters.TypeKeywords;
|
||||
}
|
||||
|
||||
filterMutate(symbols, symbol => {
|
||||
if (!isSourceFile(location)) {
|
||||
|
@ -1211,6 +1216,10 @@ namespace ts.Completions {
|
|||
});
|
||||
}
|
||||
|
||||
function isInsideTypeAssertion(): boolean {
|
||||
return isAsExpression(contextToken.parent);
|
||||
}
|
||||
|
||||
function isTypeOnlyCompletion(): boolean {
|
||||
return insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
|
||||
}
|
||||
|
@ -2057,6 +2066,8 @@ namespace ts.Completions {
|
|||
return isParameterPropertyModifier(kind);
|
||||
case KeywordCompletionFilters.FunctionLikeBodyKeywords:
|
||||
return isFunctionLikeBodyKeyword(kind);
|
||||
case KeywordCompletionFilters.TypeAssertionKeywords:
|
||||
return isTypeKeyword(kind) || kind === SyntaxKind.ConstKeyword;
|
||||
case KeywordCompletionFilters.TypeKeywords:
|
||||
return isTypeKeyword(kind);
|
||||
default:
|
||||
|
|
11
tests/cases/fourslash/completionListAsConst.ts
Normal file
11
tests/cases/fourslash/completionListAsConst.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////const a = {
|
||||
//// b: 42 as con/*0*/
|
||||
////};
|
||||
////
|
||||
////1 as con/*1*/
|
||||
////
|
||||
////const b = 42 as /*2*/
|
||||
|
||||
verify.completions({ marker: test.markers(), includes: [{ name: "const", sortText: completion.SortText.GlobalsOrKeywords }] });
|
Loading…
Reference in a new issue