11/// <reference path="..\services\services.ts" />
22
3- /* tslint:disable:no-null-keyword */
4-
53namespace ts . server {
64 export interface Logger {
75 close ( ) : void ;
@@ -74,14 +72,16 @@ namespace ts.server {
7472 }
7573
7674 export interface NormalizedPathMap < T > {
77- get ( path : NormalizedPath ) : T ;
78- set ( path : NormalizedPath , value : T ) : void ;
75+ get ( path : NormalizedPath ) : T ;
76+ set ( path : NormalizedPath , value : T ) : void ;
7977 contains ( path : NormalizedPath ) : boolean ;
8078 remove ( path : NormalizedPath ) : void ;
8179 }
8280
8381 export function createNormalizedPathMap < T > ( ) : NormalizedPathMap < T > {
82+ /* tslint:disable:no-null-keyword */
8483 const map : Map < T > = Object . create ( null ) ;
84+ /* tslint:enable:no-null-keyword */
8585 return {
8686 get ( path ) {
8787 return map [ path ] ;
@@ -97,48 +97,49 @@ namespace ts.server {
9797 }
9898 } ;
9999 }
100- function throwLanguageServiceIsDisabledError ( ) { ;
100+ function throwLanguageServiceIsDisabledError ( ) {
101+ ;
101102 throw new Error ( "LanguageService is disabled" ) ;
102103 }
103104
104105 export const nullLanguageService : LanguageService = {
105- cleanupSemanticCache : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
106- getSyntacticDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
107- getSemanticDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
108- getCompilerOptionsDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
109- getSyntacticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
106+ cleanupSemanticCache : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
107+ getSyntacticDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
108+ getSemanticDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
109+ getCompilerOptionsDiagnostics : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
110+ getSyntacticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
110111 getEncodedSyntacticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
111- getSemanticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
112- getEncodedSemanticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
113- getCompletionsAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
114- findReferences : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
115- getCompletionEntryDetails : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
116- getQuickInfoAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
117- findRenameLocations : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
118- getNameOrDottedNameSpan : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
119- getBreakpointStatementAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
120- getBraceMatchingAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
121- getSignatureHelpItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
122- getDefinitionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
123- getRenameInfo : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
124- getTypeDefinitionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
125- getReferencesAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
126- getDocumentHighlights : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
127- getOccurrencesAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
128- getNavigateToItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
129- getNavigationBarItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
130- getOutliningSpans : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
131- getTodoComments : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
132- getIndentationAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
133- getFormattingEditsForRange : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
134- getFormattingEditsForDocument : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
135- getFormattingEditsAfterKeystroke : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
136- getDocCommentTemplateAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
137- isValidBraceCompletionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
138- getEmitOutput : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
139- getProgram : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
140- getNonBoundSourceFile : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
141- dispose : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
112+ getSemanticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
113+ getEncodedSemanticClassifications : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
114+ getCompletionsAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
115+ findReferences : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
116+ getCompletionEntryDetails : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
117+ getQuickInfoAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
118+ findRenameLocations : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
119+ getNameOrDottedNameSpan : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
120+ getBreakpointStatementAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
121+ getBraceMatchingAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
122+ getSignatureHelpItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
123+ getDefinitionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
124+ getRenameInfo : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
125+ getTypeDefinitionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
126+ getReferencesAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
127+ getDocumentHighlights : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
128+ getOccurrencesAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
129+ getNavigateToItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
130+ getNavigationBarItems : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
131+ getOutliningSpans : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
132+ getTodoComments : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
133+ getIndentationAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
134+ getFormattingEditsForRange : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
135+ getFormattingEditsForDocument : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
136+ getFormattingEditsAfterKeystroke : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
137+ getDocCommentTemplateAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
138+ isValidBraceCompletionAtPosition : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
139+ getEmitOutput : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
140+ getProgram : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
141+ getNonBoundSourceFile : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
142+ dispose : ( ) : any => throwLanguageServiceIsDisabledError ( ) ,
142143 } ;
143144
144145 export interface ServerLanguageServiceHost {
@@ -172,4 +173,24 @@ namespace ts.server {
172173 export function makeInferredProjectName ( counter : number ) {
173174 return `/dev/null/inferredProject${ counter } *` ;
174175 }
176+
177+ export class ThrottledOperations {
178+ private pendingTimeouts : Map < any > = { } ;
179+ constructor ( private readonly host : ServerHost ) {
180+ }
181+
182+ public schedule ( operationId : string , delay : number , cb : ( ) => void ) {
183+ if ( hasProperty ( this . pendingTimeouts , operationId ) ) {
184+ // another operation was already scheduled for this id - cancel it
185+ this . host . clearTimeout ( this . pendingTimeouts [ operationId ] ) ;
186+ }
187+ // schedule new operation, pass arguments
188+ this . pendingTimeouts [ operationId ] = this . host . setTimeout ( ThrottledOperations . run , delay , this , operationId , cb ) ;
189+ }
190+
191+ private static run ( self : ThrottledOperations , operationId : string , cb : ( ) => void ) {
192+ delete self . pendingTimeouts [ operationId ] ;
193+ cb ( ) ;
194+ }
195+ }
175196}
0 commit comments