@@ -139,6 +139,49 @@ export const decorateLanguageService = (
139139 }
140140 }
141141
142+ const readonlyModeDisableFeatures : Array < keyof ts . LanguageService > = [
143+ 'getOutliningSpans' ,
144+ 'getSyntacticDiagnostics' ,
145+ 'getSemanticDiagnostics' ,
146+ 'getSuggestionDiagnostics' ,
147+ 'provideInlayHints' ,
148+ 'getLinkedEditingRangeAtPosition' ,
149+ 'getApplicableRefactors' ,
150+ 'getCompletionsAtPosition' ,
151+ 'getDefinitionAndBoundSpan' ,
152+ 'getFormattingEditsAfterKeystroke' ,
153+ 'getDocumentHighlights' ,
154+ ]
155+ for ( const feature of readonlyModeDisableFeatures ) {
156+ const orig = proxy [ feature ]
157+ proxy [ feature ] = ( ...args ) => {
158+ const enabledFeaturesSetting = c ( 'customizeEnabledFeatures' ) ?? { }
159+ const toDisableRaw =
160+ Object . entries ( enabledFeaturesSetting ) . find ( ( [ path ] ) => {
161+ if ( typeof args [ 0 ] !== 'string' ) return false
162+ return args [ 0 ] . includes ( path )
163+ } ) ?. [ 1 ] ??
164+ enabledFeaturesSetting [ '*' ] ??
165+ { }
166+ const toDisable : string [ ] =
167+ toDisableRaw === 'disable-auto-invoked'
168+ ? // todo
169+ readonlyModeDisableFeatures
170+ : Object . entries ( toDisableRaw )
171+ . filter ( ( [ , v ] ) => v === false )
172+ . map ( ( [ k ] ) => k )
173+ if ( toDisable . includes ( feature ) ) return undefined
174+ // eslint-disable-next-line @typescript-eslint/no-require-imports
175+ const performance = globalThis . performance ?? require ( 'perf_hooks' ) . performance
176+ const start = performance . now ( )
177+ //@ts -expect-error
178+ const result = orig ( ...args )
179+ const time = performance . now ( ) - start
180+ if ( time > 100 ) console . log ( `[typescript-vscode-plugin perf warning] ${ feature } took ${ time } ms: ${ args [ 0 ] } ${ args [ 1 ] } ` )
181+ return result
182+ }
183+ }
184+
142185 languageService [ thisPluginMarker ] = true
143186
144187 if ( ! __WEB__ && c ( 'enableHooksFile' ) ) {
0 commit comments