Skip to content

Commit bc0d31a

Browse files
committed
feat: add a way to add excludes to workspace symbol search (eg to exclude node_modules for source search only, also improves performance)
1 parent 5c63db3 commit bc0d31a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/configurationType.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ export type Configuration = {
199199
* @default []
200200
*/
201201
additionalIncludeExtensions: string[]
202+
/**
203+
* Patterns to exclude from workspace symbol search
204+
* Example: `["**\/node_modules/**"]`
205+
* Can gradually improve performance, will be set to node_modules by default in future
206+
* @uniqueItems true
207+
* @default []
208+
* @defaultTODO ["**\/node_modules/**"]
209+
*/
210+
// TODO enable node_modules default when cancellationToken is properly used
211+
workspaceSymbolSearchExcludePatterns: string[]
202212
/**
203213
* @default ["fixMissingFunctionDeclaration"]
204214
* @uniqueItems true

typescript/src/decorateProxy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import decorateDocumentHighlights from './documentHighlights'
1111
import completionEntryDetails from './completionEntryDetails'
1212
import { GetConfig } from './types'
1313
import lodashGet from 'lodash.get'
14+
import decorateWorkspaceSymbolSearch from './workspaceSymbolSearch'
1415

1516
/** @internal */
1617
export const thisPluginMarker = '__essentialPluginsMarker__'
@@ -107,6 +108,7 @@ export const decorateLanguageService = (
107108
decorateDefinitions(proxy, info, c)
108109
decorateReferences(proxy, languageService, c)
109110
decorateDocumentHighlights(proxy, languageService, c)
111+
decorateWorkspaceSymbolSearch(proxy, languageService, c, languageServiceHost)
110112

111113
if (pluginSpecificSyntaxServerConfigCheck) {
112114
if (!__WEB__) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { GetConfig } from './types'
2+
3+
export default (proxy: ts.LanguageService, languageService: ts.LanguageService, c: GetConfig, languageServiceHost: ts.LanguageServiceHost) => {
4+
proxy.getNavigateToItems = (searchValue, maxResultCount, fileName, excludeDtsFiles) => {
5+
const workspaceSymbolSearchExcludePatterns = c('workspaceSymbolSearchExcludePatterns')
6+
if (!workspaceSymbolSearchExcludePatterns.length) {
7+
return languageService.getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles)
8+
}
9+
10+
const program = languageService.getProgram()!
11+
const cancellationToken = languageServiceHost.getCompilerHost?.()?.getCancellationToken?.() ?? {
12+
isCancellationRequested: () => false,
13+
throwIfCancellationRequested: () => {},
14+
}
15+
let sourceFiles = fileName ? [program.getSourceFile(fileName)!] : program.getSourceFiles()
16+
if (!fileName) {
17+
const excludes = tsFull.getRegularExpressionForWildcard(workspaceSymbolSearchExcludePatterns, '', 'exclude')?.slice(1)
18+
if (excludes) {
19+
const re = new RegExp(excludes)
20+
sourceFiles = sourceFiles.filter(x => !re.test(x.fileName))
21+
}
22+
}
23+
return tsFull.NavigateTo.getNavigateToItems(
24+
sourceFiles as any,
25+
program.getTypeChecker() as any,
26+
// TODO! use real cancellationToken
27+
cancellationToken,
28+
searchValue,
29+
maxResultCount,
30+
excludeDtsFiles ?? false,
31+
)
32+
}
33+
}

0 commit comments

Comments
 (0)