mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Don't show the currently-completing thing at the cursor in JS files
Fixes #6693 (cherry picked from commit 124bd517e71353d8c22c0ee63f2e830c0b18004c)
This commit is contained in:
parent
96ec9be665
commit
f84bbcdf59
@ -62,7 +62,7 @@ namespace ts {
|
||||
export interface SourceFile {
|
||||
/* @internal */ version: string;
|
||||
/* @internal */ scriptSnapshot: IScriptSnapshot;
|
||||
/* @internal */ nameTable: Map<string>;
|
||||
/* @internal */ nameTable: Map<number>;
|
||||
|
||||
/* @internal */ getNamedDeclarations(): Map<Declaration[]>;
|
||||
|
||||
@ -808,7 +808,7 @@ namespace ts {
|
||||
public languageVersion: ScriptTarget;
|
||||
public languageVariant: LanguageVariant;
|
||||
public identifiers: Map<string>;
|
||||
public nameTable: Map<string>;
|
||||
public nameTable: Map<number>;
|
||||
public resolvedModules: Map<ResolvedModule>;
|
||||
public imports: LiteralExpression[];
|
||||
public moduleAugmentations: LiteralExpression[];
|
||||
@ -1957,8 +1957,6 @@ namespace ts {
|
||||
const text = scriptSnapshot.getText(0, scriptSnapshot.getLength());
|
||||
const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents);
|
||||
setSourceFileFields(sourceFile, scriptSnapshot, version);
|
||||
// after full parsing we can use table with interned strings as name table
|
||||
sourceFile.nameTable = sourceFile.identifiers;
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
@ -3834,7 +3832,7 @@ namespace ts {
|
||||
|
||||
if (isRightOfDot && isSourceFileJavaScript(sourceFile)) {
|
||||
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries);
|
||||
addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames));
|
||||
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames));
|
||||
}
|
||||
else {
|
||||
if (!symbols || symbols.length === 0) {
|
||||
@ -3867,12 +3865,17 @@ namespace ts {
|
||||
|
||||
return { isMemberCompletion, isNewIdentifierLocation, entries };
|
||||
|
||||
function getJavaScriptCompletionEntries(sourceFile: SourceFile, uniqueNames: Map<string>): CompletionEntry[] {
|
||||
function getJavaScriptCompletionEntries(sourceFile: SourceFile, position: number, uniqueNames: Map<string>): CompletionEntry[] {
|
||||
const entries: CompletionEntry[] = [];
|
||||
const target = program.getCompilerOptions().target;
|
||||
|
||||
const nameTable = getNameTable(sourceFile);
|
||||
for (const name in nameTable) {
|
||||
// Skip identifiers produced only from the current location
|
||||
if (nameTable[name] === position) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!uniqueNames[name]) {
|
||||
uniqueNames[name] = name;
|
||||
const displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks*/ true);
|
||||
@ -7525,7 +7528,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function getNameTable(sourceFile: SourceFile): Map<string> {
|
||||
export function getNameTable(sourceFile: SourceFile): Map<number> {
|
||||
if (!sourceFile.nameTable) {
|
||||
initializeNameTable(sourceFile);
|
||||
}
|
||||
@ -7534,7 +7537,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function initializeNameTable(sourceFile: SourceFile): void {
|
||||
const nameTable: Map<string> = {};
|
||||
const nameTable: Map<number> = {};
|
||||
|
||||
walk(sourceFile);
|
||||
sourceFile.nameTable = nameTable;
|
||||
@ -7542,7 +7545,7 @@ namespace ts {
|
||||
function walk(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
nameTable[(<Identifier>node).text] = (<Identifier>node).text;
|
||||
nameTable[(<Identifier>node).text] = nameTable[(<Identifier>node).text] === undefined ? node.pos : -1;
|
||||
break;
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
@ -7554,7 +7557,7 @@ namespace ts {
|
||||
node.parent.kind === SyntaxKind.ExternalModuleReference ||
|
||||
isArgumentOfElementAccessExpression(node)) {
|
||||
|
||||
nameTable[(<LiteralExpression>node).text] = (<LiteralExpression>node).text;
|
||||
nameTable[(<LiteralExpression>node).text] = nameTable[(<LiteralExpression>node).text] === undefined ? node.pos : -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
21
tests/cases/fourslash/getJavaScriptCompletions20.ts
Normal file
21
tests/cases/fourslash/getJavaScriptCompletions20.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: file.js
|
||||
//// /**
|
||||
//// * A person
|
||||
//// * @constructor
|
||||
//// * @param {string} name - The name of the person.
|
||||
//// * @param {number} age - The age of the person.
|
||||
//// */
|
||||
//// function Person(name, age) {
|
||||
//// this.name = name;
|
||||
//// this.age = age;
|
||||
//// }
|
||||
////
|
||||
////
|
||||
//// Person.getName = 10;
|
||||
//// Person.getNa/**/ = 10;
|
||||
|
||||
goTo.marker();
|
||||
verify.not.memberListContains('getNa');
|
||||
Loading…
x
Reference in New Issue
Block a user