mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Add helper functions to simplify getCompletionEntryDisplayNameForSymbol (#20552)
This commit is contained in:
parent
fd5ed5ac79
commit
20c846d671
@ -8128,7 +8128,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getLiteralTypeFromPropertyName(prop: Symbol) {
|
||||
return getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier || startsWith(prop.escapedName as string, "__@") ?
|
||||
return getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier || isKnownSymbol(prop) ?
|
||||
neverType :
|
||||
getLiteralType(symbolName(prop));
|
||||
}
|
||||
|
||||
@ -2119,6 +2119,10 @@ namespace ts {
|
||||
return "__@" + symbolName as __String;
|
||||
}
|
||||
|
||||
export function isKnownSymbol(symbol: Symbol): boolean {
|
||||
return startsWith(symbol.escapedName as string, "__@");
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the word "Symbol" with unicode escapes
|
||||
*/
|
||||
|
||||
@ -1988,36 +1988,17 @@ namespace ts.Completions {
|
||||
|
||||
/**
|
||||
* Get the name to be display in completion from a given symbol.
|
||||
*
|
||||
* @return undefined if the name is of external module
|
||||
*/
|
||||
function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, allowStringLiteral: boolean, origin: SymbolOriginInfo | undefined): string | undefined {
|
||||
const name = getSymbolName(symbol, origin, target);
|
||||
if (!name) return undefined;
|
||||
|
||||
// First check of the displayName is not external module; if it is an external module, it is not valid entry
|
||||
if (symbol.flags & SymbolFlags.Namespace) {
|
||||
const firstCharCode = name.charCodeAt(0);
|
||||
if (isSingleOrDoubleQuote(firstCharCode)) {
|
||||
// If the symbol is external module, don't show it in the completion list
|
||||
// (i.e declare module "http" { const x; } | // <= request completion here, "http" should not be there)
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// If the symbol is for a member of an object type and is the internal name of an ES
|
||||
// symbol, it is not a valid entry. Internal names for ES symbols start with "__@"
|
||||
if (symbol.flags & SymbolFlags.ClassMember) {
|
||||
const escapedName = symbol.escapedName as string;
|
||||
if (escapedName.length >= 3 &&
|
||||
escapedName.charCodeAt(0) === CharacterCodes._ &&
|
||||
escapedName.charCodeAt(1) === CharacterCodes._ &&
|
||||
escapedName.charCodeAt(2) === CharacterCodes.at) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return getCompletionEntryDisplayName(name, target, performCharacterChecks, allowStringLiteral);
|
||||
return name === undefined
|
||||
// If the symbol is external module, don't show it in the completion list
|
||||
// (i.e declare module "http" { const x; } | // <= request completion here, "http" should not be there)
|
||||
|| symbol.flags & SymbolFlags.Module && startsWithQuote(name)
|
||||
// If the symbol is the internal name of an ES symbol, it is not a valid entry. Internal names for ES symbols start with "__@"
|
||||
|| isKnownSymbol(symbol)
|
||||
? undefined
|
||||
: getCompletionEntryDisplayName(name, target, performCharacterChecks, allowStringLiteral);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1300,12 +1300,16 @@ namespace ts {
|
||||
*/
|
||||
export function stripQuotes(name: string) {
|
||||
const length = name.length;
|
||||
if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && isSingleOrDoubleQuote(name.charCodeAt(0))) {
|
||||
if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && startsWithQuote(name)) {
|
||||
return name.substring(1, length - 1);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
export function startsWithQuote(name: string): boolean {
|
||||
return isSingleOrDoubleQuote(name.charCodeAt(0));
|
||||
}
|
||||
|
||||
export function scriptKindIs(fileName: string, host: LanguageServiceHost, ...scriptKinds: ScriptKind[]): boolean {
|
||||
const scriptKind = getScriptKind(fileName, host);
|
||||
return forEach(scriptKinds, k => k === scriptKind);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user