Skip to content

Commit f84bbcd

Browse files
RyanCavanaughbillti
authored andcommitted
Don't show the currently-completing thing at the cursor in JS files
Fixes #6693 (cherry picked from commit 124bd51)
1 parent 96ec9be commit f84bbcd

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

src/services/services.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace ts {
6262
export interface SourceFile {
6363
/* @internal */ version: string;
6464
/* @internal */ scriptSnapshot: IScriptSnapshot;
65-
/* @internal */ nameTable: Map<string>;
65+
/* @internal */ nameTable: Map<number>;
6666

6767
/* @internal */ getNamedDeclarations(): Map<Declaration[]>;
6868

@@ -808,7 +808,7 @@ namespace ts {
808808
public languageVersion: ScriptTarget;
809809
public languageVariant: LanguageVariant;
810810
public identifiers: Map<string>;
811-
public nameTable: Map<string>;
811+
public nameTable: Map<number>;
812812
public resolvedModules: Map<ResolvedModule>;
813813
public imports: LiteralExpression[];
814814
public moduleAugmentations: LiteralExpression[];
@@ -1957,8 +1957,6 @@ namespace ts {
19571957
const text = scriptSnapshot.getText(0, scriptSnapshot.getLength());
19581958
const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents);
19591959
setSourceFileFields(sourceFile, scriptSnapshot, version);
1960-
// after full parsing we can use table with interned strings as name table
1961-
sourceFile.nameTable = sourceFile.identifiers;
19621960
return sourceFile;
19631961
}
19641962

@@ -3834,7 +3832,7 @@ namespace ts {
38343832

38353833
if (isRightOfDot && isSourceFileJavaScript(sourceFile)) {
38363834
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries);
3837-
addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames));
3835+
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames));
38383836
}
38393837
else {
38403838
if (!symbols || symbols.length === 0) {
@@ -3867,12 +3865,17 @@ namespace ts {
38673865

38683866
return { isMemberCompletion, isNewIdentifierLocation, entries };
38693867

3870-
function getJavaScriptCompletionEntries(sourceFile: SourceFile, uniqueNames: Map<string>): CompletionEntry[] {
3868+
function getJavaScriptCompletionEntries(sourceFile: SourceFile, position: number, uniqueNames: Map<string>): CompletionEntry[] {
38713869
const entries: CompletionEntry[] = [];
38723870
const target = program.getCompilerOptions().target;
38733871

38743872
const nameTable = getNameTable(sourceFile);
38753873
for (const name in nameTable) {
3874+
// Skip identifiers produced only from the current location
3875+
if (nameTable[name] === position) {
3876+
continue;
3877+
}
3878+
38763879
if (!uniqueNames[name]) {
38773880
uniqueNames[name] = name;
38783881
const displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks*/ true);
@@ -7525,7 +7528,7 @@ namespace ts {
75257528
}
75267529

75277530
/* @internal */
7528-
export function getNameTable(sourceFile: SourceFile): Map<string> {
7531+
export function getNameTable(sourceFile: SourceFile): Map<number> {
75297532
if (!sourceFile.nameTable) {
75307533
initializeNameTable(sourceFile);
75317534
}
@@ -7534,15 +7537,15 @@ namespace ts {
75347537
}
75357538

75367539
function initializeNameTable(sourceFile: SourceFile): void {
7537-
const nameTable: Map<string> = {};
7540+
const nameTable: Map<number> = {};
75387541

75397542
walk(sourceFile);
75407543
sourceFile.nameTable = nameTable;
75417544

75427545
function walk(node: Node) {
75437546
switch (node.kind) {
75447547
case SyntaxKind.Identifier:
7545-
nameTable[(<Identifier>node).text] = (<Identifier>node).text;
7548+
nameTable[(<Identifier>node).text] = nameTable[(<Identifier>node).text] === undefined ? node.pos : -1;
75467549
break;
75477550
case SyntaxKind.StringLiteral:
75487551
case SyntaxKind.NumericLiteral:
@@ -7554,7 +7557,7 @@ namespace ts {
75547557
node.parent.kind === SyntaxKind.ExternalModuleReference ||
75557558
isArgumentOfElementAccessExpression(node)) {
75567559

7557-
nameTable[(<LiteralExpression>node).text] = (<LiteralExpression>node).text;
7560+
nameTable[(<LiteralExpression>node).text] = nameTable[(<LiteralExpression>node).text] === undefined ? node.pos : -1;
75587561
}
75597562
break;
75607563
default:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: file.js
5+
//// /**
6+
//// * A person
7+
//// * @constructor
8+
//// * @param {string} name - The name of the person.
9+
//// * @param {number} age - The age of the person.
10+
//// */
11+
//// function Person(name, age) {
12+
//// this.name = name;
13+
//// this.age = age;
14+
//// }
15+
////
16+
////
17+
//// Person.getName = 10;
18+
//// Person.getNa/**/ = 10;
19+
20+
goTo.marker();
21+
verify.not.memberListContains('getNa');

0 commit comments

Comments
 (0)