Skip to content

Commit 1baf496

Browse files
author
Arthur Ozga
committed
merge master and add isGlobalCompletion flags to CompletionInfo
2 parents eb362fe + f4dc114 commit 1baf496

File tree

11 files changed

+94
-53
lines changed

11 files changed

+94
-53
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
8686
'/// <reference path="types.ts" />\r\n' +
8787
'/* @internal */\r\n' +
8888
'namespace ts {\r\n' +
89-
' export var Diagnostics = {\r\n';
89+
' export const Diagnostics = {\r\n';
9090
var names = Utilities.getObjectKeys(messageTable);
9191
for (var i = 0; i < names.length; i++) {
9292
var name = names[i];

src/compiler/core.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace ts {
212212
* true for all elements, otherwise returns a new array instance containing the filtered subset.
213213
*/
214214
export function filter<T, U extends T>(array: T[], f: (x: T) => x is U): U[];
215-
export function filter<T>(array: T[], f: (x: T) => boolean): T[]
215+
export function filter<T>(array: T[], f: (x: T) => boolean): T[];
216216
export function filter<T>(array: T[], f: (x: T) => boolean): T[] {
217217
if (array) {
218218
const len = array.length;
@@ -1879,10 +1879,10 @@ namespace ts {
18791879
declare var process: any;
18801880
declare var require: any;
18811881

1882-
let currentAssertionLevel: AssertionLevel;
1882+
export let currentAssertionLevel = AssertionLevel.None;
18831883

18841884
export function shouldAssert(level: AssertionLevel): boolean {
1885-
return getCurrentAssertionLevel() >= level;
1885+
return currentAssertionLevel >= level;
18861886
}
18871887

18881888
export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void {
@@ -1899,35 +1899,6 @@ namespace ts {
18991899
export function fail(message?: string): void {
19001900
Debug.assert(/*expression*/ false, message);
19011901
}
1902-
1903-
function getCurrentAssertionLevel() {
1904-
if (currentAssertionLevel !== undefined) {
1905-
return currentAssertionLevel;
1906-
}
1907-
1908-
if (sys === undefined) {
1909-
return AssertionLevel.None;
1910-
}
1911-
1912-
const developmentMode = /^development$/i.test(getEnvironmentVariable("NODE_ENV"));
1913-
currentAssertionLevel = developmentMode
1914-
? AssertionLevel.Normal
1915-
: AssertionLevel.None;
1916-
1917-
return currentAssertionLevel;
1918-
}
1919-
}
1920-
1921-
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
1922-
if (host && host.getEnvironmentVariable) {
1923-
return host.getEnvironmentVariable(name);
1924-
}
1925-
1926-
if (sys && sys.getEnvironmentVariable) {
1927-
return sys.getEnvironmentVariable(name);
1928-
}
1929-
1930-
return "";
19311902
}
19321903

19331904
/** Remove an item from an array, moving everything to its right one space left. */

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ namespace ts {
206206
readFile: fileName => sys.readFile(fileName),
207207
trace: (s: string) => sys.write(s + newLine),
208208
directoryExists: directoryName => sys.directoryExists(directoryName),
209-
getEnvironmentVariable: name => getEnvironmentVariable(name, /*host*/ undefined),
209+
getEnvironmentVariable: name => sys.getEnvironmentVariable ? sys.getEnvironmentVariable(name) : "",
210210
getDirectories: (path: string) => sys.getDirectories(path),
211211
realpath
212212
};

src/compiler/sys.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace ts {
8383
getEnvironmentVariable?(name: string): string;
8484
};
8585

86-
export var sys: System = (function() {
86+
export let sys: System = (function() {
8787

8888
function getWScriptSystem(): System {
8989

@@ -637,4 +637,10 @@ namespace ts {
637637
}
638638
return sys;
639639
})();
640+
641+
if (sys && sys.getEnvironmentVariable) {
642+
Debug.currentAssertionLevel = /^development$/i.test(sys.getEnvironmentVariable("NODE_ENV"))
643+
? AssertionLevel.Normal
644+
: AssertionLevel.None;
645+
}
640646
}

src/harness/fourslash.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ namespace FourSlash {
754754
}
755755
}
756756

757+
public verifyCompletionListIsGlobal(expected: boolean) {
758+
const completions = this.getCompletionListAtCaret();
759+
if (completions && completions.isGlobalCompletion !== expected) {
760+
this.raiseError(`verifyCompletionListIsGlobal failed - expected result to be ${completions.isGlobalCompletion}`);
761+
}
762+
}
763+
757764
public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) {
758765
const completions = this.getCompletionListAtCaret();
759766
if (completions) {
@@ -3046,6 +3053,10 @@ namespace FourSlashInterface {
30463053
this.state.verifyCompletionListIsEmpty(this.negative);
30473054
}
30483055

3056+
public completionListIsGlobal(expected: boolean) {
3057+
this.state.verifyCompletionListIsGlobal(expected);
3058+
}
3059+
30493060
public completionListAllowsNewIdentifier() {
30503061
this.state.verifyCompletionListAllowsNewIdentifier(this.negative);
30513062
}

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ namespace Harness {
509509
tryEnableSourceMapsForHost?(): void;
510510
getEnvironmentVariable?(name: string): string;
511511
}
512-
export var IO: IO;
512+
export let IO: IO;
513513

514514
// harness always uses one kind of new line
515515
const harnessNewLine = "\r\n";

src/server/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ namespace ts.server {
214214
const response = this.processResponse<protocol.CompletionsResponse>(request);
215215

216216
return {
217+
isGlobalCompletion: false,
217218
isMemberCompletion: false,
218219
isNewIdentifierLocation: false,
219220
entries: response.body.map(entry => {

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ts.server {
1212
export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;
1313

1414
export type ProjectServiceEvent =
15-
{ eventName: "context", data: { project: Project, fileName: NormalizedPath } } | { eventName: "configFileDiag", data: { triggerFile?: string, configFileName: string, diagnostics: Diagnostic[] } }
15+
{ eventName: "context", data: { project: Project, fileName: NormalizedPath } } | { eventName: "configFileDiag", data: { triggerFile?: string, configFileName: string, diagnostics: Diagnostic[] } };
1616

1717
export interface ProjectServiceEventHandler {
1818
(event: ProjectServiceEvent): void;

src/services/completions.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace ts.Completions {
1414
return undefined;
1515
}
1616

17-
const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName } = completionData;
17+
const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName } = completionData;
1818

1919
if (isJsDocTagName) {
2020
// If the current position is a jsDoc tag name, only tag names should be provided for completion
21-
return { isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getAllJsDocCompletionEntries() };
21+
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getAllJsDocCompletionEntries() };
2222
}
2323

2424
const entries: CompletionEntry[] = [];
@@ -56,7 +56,7 @@ namespace ts.Completions {
5656
addRange(entries, keywordCompletions);
5757
}
5858

59-
return { isMemberCompletion, isNewIdentifierLocation: isNewIdentifierLocation, entries };
59+
return { isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation: isNewIdentifierLocation, entries };
6060

6161
function getJavaScriptCompletionEntries(sourceFile: SourceFile, position: number, uniqueNames: Map<string>): CompletionEntry[] {
6262
const entries: CompletionEntry[] = [];
@@ -190,7 +190,7 @@ namespace ts.Completions {
190190
if (type) {
191191
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/false);
192192
if (entries.length) {
193-
return { isMemberCompletion: true, isNewIdentifierLocation: true, entries };
193+
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries };
194194
}
195195
}
196196
}
@@ -209,7 +209,7 @@ namespace ts.Completions {
209209
}
210210

211211
if (entries.length) {
212-
return { isMemberCompletion: false, isNewIdentifierLocation: true, entries };
212+
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: true, entries };
213213
}
214214

215215
return undefined;
@@ -221,7 +221,7 @@ namespace ts.Completions {
221221
if (type) {
222222
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, node, /*performCharacterChecks*/false);
223223
if (entries.length) {
224-
return { isMemberCompletion: true, isNewIdentifierLocation: true, entries };
224+
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries };
225225
}
226226
}
227227
return undefined;
@@ -233,7 +233,7 @@ namespace ts.Completions {
233233
const entries: CompletionEntry[] = [];
234234
addStringLiteralCompletionsFromType(type, entries);
235235
if (entries.length) {
236-
return { isMemberCompletion: false, isNewIdentifierLocation: false, entries };
236+
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries };
237237
}
238238
}
239239
return undefined;
@@ -281,6 +281,7 @@ namespace ts.Completions {
281281
entries = getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, span);
282282
}
283283
return {
284+
isGlobalCompletion: false,
284285
isMemberCompletion: false,
285286
isNewIdentifierLocation: true,
286287
entries
@@ -549,13 +550,18 @@ namespace ts.Completions {
549550
}
550551

551552
const completionInfo: CompletionInfo = {
552-
isMemberCompletion: false,
553-
/**
554-
* The user may type in a path that doesn't yet exist, creating a "new identifier"
555-
* with respect to the collection of identifiers the server is aware of.
556-
*/
557-
isNewIdentifierLocation: true,
558-
entries: []
553+
/**
554+
* We don't want the editor to offer any other completions, such as snippets, inside a comment.
555+
*/
556+
isGlobalCompletion: false,
557+
isMemberCompletion: false,
558+
/**
559+
* The user may type in a path that doesn't yet exist, creating a "new identifier"
560+
* with respect to the collection of identifiers the server is aware of.
561+
*/
562+
isNewIdentifierLocation: true,
563+
564+
entries: []
559565
};
560566

561567
const text = sourceFile.text.substr(range.pos, position - range.pos);
@@ -828,7 +834,7 @@ namespace ts.Completions {
828834
}
829835

830836
if (isJsDocTagName) {
831-
return { symbols: undefined, isMemberCompletion: false, isNewIdentifierLocation: false, location: undefined, isRightOfDot: false, isJsDocTagName };
837+
return { symbols: undefined, isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, location: undefined, isRightOfDot: false, isJsDocTagName };
832838
}
833839

834840
if (!insideJsDocTagExpression) {
@@ -900,6 +906,7 @@ namespace ts.Completions {
900906
}
901907

902908
const semanticStart = timestamp();
909+
let isGlobalCompletion = false;
903910
let isMemberCompletion: boolean;
904911
let isNewIdentifierLocation: boolean;
905912
let symbols: Symbol[] = [];
@@ -935,14 +942,16 @@ namespace ts.Completions {
935942
if (!tryGetGlobalSymbols()) {
936943
return undefined;
937944
}
945+
isGlobalCompletion = true;
938946
}
939947

940948
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
941949

942-
return { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), isJsDocTagName };
950+
return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), isJsDocTagName };
943951

944952
function getTypeScriptMemberSymbols(): void {
945953
// Right of dot member completion list
954+
isGlobalCompletion = false;
946955
isMemberCompletion = true;
947956
isNewIdentifierLocation = false;
948957

src/services/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ namespace ts {
503503
}
504504

505505
export interface CompletionInfo {
506+
isGlobalCompletion: boolean;
506507
isMemberCompletion: boolean;
507508

508509
/**

0 commit comments

Comments
 (0)