Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path='../compiler/utilities.ts' />

/* @internal */
namespace ts.Completions {
export function getCompletionsAtPosition(host: LanguageServiceHost, typeChecker: TypeChecker, log: (message: string) => void, compilerOptions: CompilerOptions, sourceFile: SourceFile, position: number): CompletionInfo {
Expand Down Expand Up @@ -951,7 +953,6 @@ namespace ts.Completions {
if (!tryGetGlobalSymbols()) {
return undefined;
}
isGlobalCompletion = true;
}

log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
Expand Down Expand Up @@ -1030,15 +1031,13 @@ namespace ts.Completions {
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
// Cursor is inside a JSX self-closing element or opening element
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningLikeElement>jsxContainer);
isGlobalCompletion = false;

if (attrsType) {
symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), (<JsxOpeningLikeElement>jsxContainer).attributes);
isMemberCompletion = true;
isNewIdentifierLocation = false;
return true;
}

}
}

Expand Down Expand Up @@ -1079,6 +1078,12 @@ namespace ts.Completions {
position;

const scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
if (scopeNode) {
isGlobalCompletion =
scopeNode.kind === SyntaxKind.SourceFile ||
scopeNode.kind === SyntaxKind.TemplateExpression ||
isStatement(scopeNode);
}

/// TODO filter meaning based on the current context
const symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias;
Expand Down
51 changes: 35 additions & 16 deletions tests/cases/fourslash/completionListIsGlobalCompletion.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,65 @@
/// <reference path='fourslash.ts'/>

// @Filename: file.ts
////export var x = 10;
////export var y = 10;
////export default class C {
////}

// @Filename: a.ts
////import { /*1*/ } from "./file.ts"; // no globals in imports - export found

//@Filename: file.tsx
/////// <reference path="/*1*/..\services\services.ts" /> // no globals in reference paths
////import { /*2*/ } from "./file.ts"; // no globals in imports
////var test = "/*3*/"; // no globals in strings
/////*4*/class A { // insert globals
/////// <reference path="/*2*/..\services\services.ts" /> // no globals in reference paths
////import { /*3*/ } from "./file1.ts"; // no globals in imports - export not found
////var test = "/*4*/"; // no globals in strings
/////*5*/class A { // insert globals
//// foo(): string { return ''; }
////}
////
////class /*5*/B extends A { // no globals after class keyword
////class /*6*/B extends A { // no globals after class keyword
//// bar(): string {
//// /*6*/ // insert globals
//// /*7*/ // insert globals
//// return '';
//// }
////}
////
////class C</*7*/ U extends A, T extends A> { // no globals at beginning of generics
////class C</*8*/ U extends A, T extends A> { // no globals at beginning of generics
//// x: U;
//// y = this./*8*/x; // no globals inserted for member completions
//// /*9*/ // insert globals
//// y = this./*9*/x; // no globals inserted for member completions
//// /*10*/ // insert globals
////}
/////*10*/ // insert globals
////const y = <div /*11*/ />;
/////*11*/ // insert globals
////const y = <div /*12*/ />; // no globals in jsx attribute found
////const z = <div =/*13*/ />; // no globals in jsx attribute with syntax error
////const x = `/*14*/ ${/*15*/}`; // globals only in template expression
goTo.marker("1");
verify.completionListIsGlobal(false);
goTo.marker("2");
verify.completionListIsGlobal(false);
goTo.marker("3");
verify.completionListIsGlobal(false);
goTo.marker("4");
verify.completionListIsGlobal(true);
goTo.marker("5");
verify.completionListIsGlobal(false);
goTo.marker("6");
goTo.marker("5");
verify.completionListIsGlobal(true);
goTo.marker("7");
goTo.marker("6");
verify.completionListIsGlobal(false);
goTo.marker("7");
verify.completionListIsGlobal(true);
goTo.marker("8");
verify.completionListIsGlobal(false);
goTo.marker("9");
verify.completionListIsGlobal(true);
verify.completionListIsGlobal(false);
goTo.marker("10");
verify.completionListIsGlobal(true);
goTo.marker("11");
verify.completionListIsGlobal(true);
goTo.marker("12");
verify.completionListIsGlobal(false);
goTo.marker("13");
verify.completionListIsGlobal(false);
goTo.marker("14");
verify.completionListIsGlobal(false);
goTo.marker("15");
verify.completionListIsGlobal(true);