@@ -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 {
0 commit comments