Skip to content

Commit 66b3fae

Browse files
Remove the active completion session.
1 parent a1cbfdf commit 66b3fae

File tree

9 files changed

+39
-44
lines changed

9 files changed

+39
-44
lines changed

src/services/services.ts

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,14 +1409,6 @@ module ts {
14091409

14101410
/// Language Service
14111411

1412-
interface CompletionSession {
1413-
fileName: string; // the file where the completion was requested
1414-
position: number; // position in the file where the completion was requested
1415-
entries: CompletionEntry[]; // entries for this completion
1416-
symbols: Map<Symbol>; // symbols by entry name map
1417-
typeChecker: TypeChecker; // the typeChecker used to generate this completion
1418-
}
1419-
14201412
interface FormattingOptions {
14211413
useTabs: boolean;
14221414
spacesPerTab: number;
@@ -2180,7 +2172,6 @@ module ts {
21802172
let typeInfoResolver: TypeChecker;
21812173
let useCaseSensitivefileNames = false;
21822174
let cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
2183-
let activeCompletionSession: CompletionSession; // The current active completion session, used to get the completion entry details
21842175

21852176
// Check if the localized messages json is set, otherwise query the host for it
21862177
if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
@@ -2918,41 +2909,32 @@ module ts {
29182909
return undefined;
29192910
}
29202911

2921-
// Clear the current activeCompletionSession for this session
2922-
activeCompletionSession = {
2923-
fileName: fileName,
2924-
position: position,
2925-
entries: [],
2926-
symbols: {},
2927-
typeChecker: typeInfoResolver
2928-
};
2929-
2930-
getCompletionEntriesFromSymbols(symbols, activeCompletionSession);
2912+
var entries = getCompletionEntriesFromSymbols(symbols);
29312913

29322914
// Add keywords if this is not a member completion list
29332915
if (!isMemberCompletion) {
2934-
addRange(activeCompletionSession.entries, keywordCompletions);
2916+
addRange(entries, keywordCompletions);
29352917
}
29362918

2937-
return {
2938-
isMemberCompletion,
2939-
isNewIdentifierLocation,
2940-
entries: activeCompletionSession.entries
2941-
};
2919+
return { isMemberCompletion, isNewIdentifierLocation, entries };
29422920

2943-
function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void {
2921+
function getCompletionEntriesFromSymbols(symbols: Symbol[]): CompletionEntry[] {
29442922
let start = new Date().getTime();
2923+
var entries: CompletionEntry[] = [];
2924+
var nameToSymbol: Map<Symbol> = {};
2925+
29452926
forEach(symbols, symbol => {
2946-
let entry = createCompletionEntry(symbol, session.typeChecker, location);
2927+
let entry = createCompletionEntry(symbol, typeInfoResolver, location);
29472928
if (entry) {
29482929
let id = escapeIdentifier(entry.name);
2949-
if (!lookUp(session.symbols, id)) {
2950-
session.entries.push(entry);
2951-
session.symbols[id] = symbol;
2930+
if (!lookUp(nameToSymbol, id)) {
2931+
entries.push(entry);
2932+
nameToSymbol[id] = symbol;
29522933
}
29532934
}
29542935
});
29552936
log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start));
2937+
return entries;
29562938
}
29572939
}
29582940

@@ -2962,7 +2944,7 @@ module ts {
29622944
// Look up a completion symbol with this name.
29632945
let result = getCompletionSymbols(fileName, position, entryName);
29642946
if (result) {
2965-
let { symbols, isMemberCompletion, isNewIdentifierLocation, location } = result;
2947+
let { symbols, location } = result;
29662948
if (symbols && symbols.length > 0) {
29672949
let symbol = symbols[0];
29682950
let displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, typeInfoResolver, location, SemanticMeaning.All);
@@ -2975,7 +2957,8 @@ module ts {
29752957
};
29762958
}
29772959
}
2978-
2960+
2961+
// Didn't find a symbol with this name. See if we can find a keyword instead.
29792962
let keywordCompletion = filter(keywordCompletions, c => c.name === entryName);
29802963
if (keywordCompletion) {
29812964
return {

tests/baselines/reference/APISample_compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ declare module "typescript" {
860860
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
861861
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
862862
getReturnTypeOfSignature(signature: Signature): Type;
863-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
863+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
864864
getSymbolAtLocation(node: Node): Symbol;
865865
getShorthandAssignmentValueSymbol(location: Node): Symbol;
866866
getTypeAtLocation(node: Node): Type;

tests/baselines/reference/APISample_compile.types

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,12 +2632,15 @@ declare module "typescript" {
26322632
>Signature : Signature
26332633
>Type : Type
26342634

2635-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
2636-
>getSymbolsInScope : (location: Node, meaning: SymbolFlags) => Symbol[]
2635+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
2636+
>getSymbolsInScope : (location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean) => Symbol[]
26372637
>location : Node
26382638
>Node : Node
26392639
>meaning : SymbolFlags
26402640
>SymbolFlags : SymbolFlags
2641+
>predicate : (symbol: Symbol) => boolean
2642+
>symbol : Symbol
2643+
>Symbol : Symbol
26412644
>Symbol : Symbol
26422645

26432646
getSymbolAtLocation(node: Node): Symbol;

tests/baselines/reference/APISample_linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ declare module "typescript" {
891891
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
892892
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
893893
getReturnTypeOfSignature(signature: Signature): Type;
894-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
894+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
895895
getSymbolAtLocation(node: Node): Symbol;
896896
getShorthandAssignmentValueSymbol(location: Node): Symbol;
897897
getTypeAtLocation(node: Node): Type;

tests/baselines/reference/APISample_linter.types

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,12 +2778,15 @@ declare module "typescript" {
27782778
>Signature : Signature
27792779
>Type : Type
27802780

2781-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
2782-
>getSymbolsInScope : (location: Node, meaning: SymbolFlags) => Symbol[]
2781+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
2782+
>getSymbolsInScope : (location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean) => Symbol[]
27832783
>location : Node
27842784
>Node : Node
27852785
>meaning : SymbolFlags
27862786
>SymbolFlags : SymbolFlags
2787+
>predicate : (symbol: Symbol) => boolean
2788+
>symbol : Symbol
2789+
>Symbol : Symbol
27872790
>Symbol : Symbol
27882791

27892792
getSymbolAtLocation(node: Node): Symbol;

tests/baselines/reference/APISample_transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ declare module "typescript" {
892892
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
893893
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
894894
getReturnTypeOfSignature(signature: Signature): Type;
895-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
895+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
896896
getSymbolAtLocation(node: Node): Symbol;
897897
getShorthandAssignmentValueSymbol(location: Node): Symbol;
898898
getTypeAtLocation(node: Node): Type;

tests/baselines/reference/APISample_transform.types

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,12 +2728,15 @@ declare module "typescript" {
27282728
>Signature : Signature
27292729
>Type : Type
27302730

2731-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
2732-
>getSymbolsInScope : (location: Node, meaning: SymbolFlags) => Symbol[]
2731+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
2732+
>getSymbolsInScope : (location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean) => Symbol[]
27332733
>location : Node
27342734
>Node : Node
27352735
>meaning : SymbolFlags
27362736
>SymbolFlags : SymbolFlags
2737+
>predicate : (symbol: Symbol) => boolean
2738+
>symbol : Symbol
2739+
>Symbol : Symbol
27372740
>Symbol : Symbol
27382741

27392742
getSymbolAtLocation(node: Node): Symbol;

tests/baselines/reference/APISample_watcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ declare module "typescript" {
929929
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
930930
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
931931
getReturnTypeOfSignature(signature: Signature): Type;
932-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
932+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
933933
getSymbolAtLocation(node: Node): Symbol;
934934
getShorthandAssignmentValueSymbol(location: Node): Symbol;
935935
getTypeAtLocation(node: Node): Type;

tests/baselines/reference/APISample_watcher.types

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,12 +2901,15 @@ declare module "typescript" {
29012901
>Signature : Signature
29022902
>Type : Type
29032903

2904-
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
2905-
>getSymbolsInScope : (location: Node, meaning: SymbolFlags) => Symbol[]
2904+
getSymbolsInScope(location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean): Symbol[];
2905+
>getSymbolsInScope : (location: Node, meaning: SymbolFlags, predicate?: (symbol: Symbol) => boolean) => Symbol[]
29062906
>location : Node
29072907
>Node : Node
29082908
>meaning : SymbolFlags
29092909
>SymbolFlags : SymbolFlags
2910+
>predicate : (symbol: Symbol) => boolean
2911+
>symbol : Symbol
2912+
>Symbol : Symbol
29102913
>Symbol : Symbol
29112914

29122915
getSymbolAtLocation(node: Node): Symbol;

0 commit comments

Comments
 (0)