Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ export namespace Completion {
sortText: SortText.GlobalsOrKeywords,
}));

const deprioritizedSortText = SortText.SortBelow(SortText.LocationPriority);

export const functionMembers: readonly ExpectedCompletionEntryObject[] = [
methodEntry("apply"),
methodEntry("call"),
Expand All @@ -1416,7 +1418,7 @@ export namespace Completion {
propertyEntry("length"),
{ name: "arguments", kind: "property", kindModifiers: "declare", text: "(property) Function.arguments: any" },
propertyEntry("caller"),
].sort(compareExpectedCompletionEntries);
].map(m => ({ ...m, sortText: deprioritizedSortText })).sort(compareExpectedCompletionEntries);

export function functionMembersPlus(plus: readonly ExpectedCompletionEntryObject[]): ExpectedExactCompletionsPlus {
return combineExpectedCompletionEntries("functionMembersPlus", functionMembers, plus);
Expand Down Expand Up @@ -1448,7 +1450,7 @@ export namespace Completion {

export const functionMembersWithPrototype: readonly ExpectedCompletionEntryObject[] = [
...functionMembers,
propertyEntry("prototype"),
{ ...propertyEntry("prototype"), sortText: deprioritizedSortText },
].sort(compareExpectedCompletionEntries);

export function functionMembersWithPrototypePlus(plus: readonly ExpectedCompletionEntryObject[]): ExpectedCompletionEntryObject[] {
Expand Down
20 changes: 19 additions & 1 deletion src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3824,7 +3824,13 @@ function getCompletionData(
// each individual type has. This is because we're going to add all identifiers
// anyways. So we might as well elevate the members that were at least part
// of the individual types to a higher status since we know what they are.
symbols.push(...filter(getPropertiesForCompletion(type, typeChecker), s => typeChecker.isValidPropertyAccessForCompletions(propertyAccess, type, s)));
const uncheckedSymbols = filter(getPropertiesForCompletion(type, typeChecker), s => typeChecker.isValidPropertyAccessForCompletions(propertyAccess, type, s));
for (const symbol of uncheckedSymbols) {
if (isNativeFunctionMember(symbol)) {
symbolToSortTextMap[getSymbolId(symbol)] = SortText.SortBelow(SortText.LocationPriority);
}
}
symbols.push(...uncheckedSymbols);
}

if (insertAwait && preferences.includeCompletionsWithInsertText) {
Expand Down Expand Up @@ -3913,6 +3919,9 @@ function getCompletionData(
if (isStaticProperty(symbol)) {
symbolToSortTextMap[getSymbolId(symbol)] = SortText.LocalDeclarationPriority;
}
else if (isNativeFunctionMember(symbol)) {
symbolToSortTextMap[getSymbolId(symbol)] = SortText.SortBelow(SortText.LocationPriority);
}
}

function addSymbolOriginInfo(symbol: Symbol) {
Expand Down Expand Up @@ -5857,6 +5866,15 @@ function isStaticProperty(symbol: Symbol) {
return !!(symbol.valueDeclaration && getEffectiveModifierFlags(symbol.valueDeclaration) & ModifierFlags.Static && isClassLike(symbol.valueDeclaration.parent));
}

function isNativeFunctionMember(symbol: Symbol): boolean {
const parent = symbol.parent;
if (!parent) return false;
const parentName = parent.escapedName;
if (parentName !== "Function" && parentName !== "CallableFunction" && parentName !== "NewableFunction") return false;
// A symbol is in the global scope if its parent is undefined
return parent.parent === undefined;
}

function tryGetObjectLiteralContextualType(node: ObjectLiteralExpression, typeChecker: TypeChecker) {
const type = typeChecker.getContextualType(node);
if (type) {
Expand Down
Loading
Loading