src/vs/workbench/contrib/search/common/search.ts

253 LOC · 161 covered · 92 uncovered · 20 ranges · 13 concepts · 8 introducers · 15 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileextractRange.test|title=extractRangeFromFilter basics|occurrence=1 · 0 introduced LOCextractRange.test|title=…file.txt:19:20 - ["@"]|occurrence=1, file.txt (19,20) - ["@"]|occurrence=1 · 0 introduced LOCfile.txt:19:20 - ["@"]|o…file.txt:20:3-40|occurrence=1, file.txt#20#3-40,5|occurrence=1, +2 · 0 introduced LOCfile.txt:20:3-40|occurre…file.txt#19 - ["@"]|occurrence=1 · 0 introduced LOCfile.txt#19 - ["@"]|occu…search.ts ×1 · 7 introduced LOCsearch.ts ×1search.ts ×1 · 10 introduced LOCsearch.ts ×1search.ts ×5 · 25 introduced LOCsearch.ts ×5search.ts ×1 · 3 introduced LOCsearch.ts ×1file.txt (19,20) - ["@"]|occurrence=1, file.txt (19,20)@ - ["@"]|occurrence=1, +1 · 0 introduced LOCfile.txt (19,20) - ["@"]…search.ts ×2 · 8 introduced LOCsearch.ts ×2search.ts ×1 · 2 introduced LOCsearch.ts ×1search.ts ×1 · 2 introduced LOCsearch.ts ×1search.ts ×8 · 104 introduced LOCsearch.ts ×8extractRange.test|title=extractRangeFromFilter allow space after path|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter allow space after path|occurrence=1extractRange.test|title=…extractRange.test|title=extractRangeFromFilter basics|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter basics|occurrence=1extractRange.test|title=…file.txt#20#3-40,5|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt#20#3-40,5|occurrence=1file.txt#20#3-40,5|occur…file.txt(20,3-40,5)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt(20,3-40,5)|occurrence=1file.txt(20,3-40,5)|occu…file.txt:20-40|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt:20-40|occurrence=1file.txt:20-40|occurrenc…file.txt:20-|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt:20-|occurrence=1file.txt:20-|occurrence=…file.txt:20:3-40:5|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt:20:3-40:5|occurrence=1file.txt:20:3-40:5|occur…file.txt:20:3-40|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges /some/path/file.txt:20:3-40|occurrence=1file.txt:20:3-40|occurre…extractRange.test|title=extractRangeFromFilter ranges hyphen in path is not treated as a range|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter ranges hyphen in path is not treated as a range|occurrence=1extractRange.test|title=…file.txt (19,20) - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless /some/@path/file.txt (19,20) - ["@"]|occurrence=1file.txt (19,20) - ["@"]…file.txt#19 - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless /some/@path/file.txt#19 - ["@"]|occurrence=1file.txt#19 - ["@"]|occu…file.txt:19:20 - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless /some/@path/file.txt:19:20 - ["@"]|occurrence=1file.txt:19:20 - ["@"]|o…file.txt (19,20)@ - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless /some/path/file.txt (19,20)@ - ["@"]|occurrence=1file.txt (19,20)@ - ["@"…file.txt@alphasymbol - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless /some/path/file.txt@alphasymbol - ["@"]|occurrence=1file.txt@alphasymbol - […file.txt (19,20) - ["@"]|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/search/test/common/extractRange.test|title=extractRangeFromFilter unless @/some/path/file.txt (19,20) - ["@"]|occurrence=1file.txt (19,20) - ["@"]…Focused file · src/vs/workbench/contrib/search/common/search.ts · 253 LOCcommon/search.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- search.ts ×8
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { onUnexpectedExternalError } from '../../../../base/common/errors.js';
7 > import { IDisposable } from '../../../../base/common/lifecycle.js';
8 > import { ISearchConfiguration, ISearchConfigurationProperties } from '../../../services/search/common/search.js';
9 > import { SymbolKind, Location, ProviderResult, SymbolTag } from '../../../../editor/common/languages.js';
10 > import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
11 > import { URI } from '../../../../base/common/uri.js';
12 > import { EditorResourceAccessor, SideBySideEditor } from '../../../common/editor.js';
13 > import { IEditorService } from '../../../services/editor/common/editorService.js';
14 > import { CancellationToken } from '../../../../base/common/cancellation.js';
15 > import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
16 > import { IFileService } from '../../../../platform/files/common/files.js';
17 > import { IRange, Range } from '../../../../editor/common/core/range.js';
18 > import { isNumber } from '../../../../base/common/types.js';
19 > import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
20 > import { compare } from '../../../../base/common/strings.js';
21 > import { groupBy } from '../../../../base/common/arrays.js';
22 > import * as nls from '../../../../nls.js';
23 > import type { IConfigurationNode } from '../../../../platform/configuration/common/configurationRegistry.js';
24 >
25 > export interface IWorkspaceSymbol {
26 > name: string;
27 > containerName?: string;
28 > kind: SymbolKind;
29 > tags?: SymbolTag[];
30 > location: Location;
31 > }
32 >
33 > export interface IWorkspaceSymbolProvider {
34 > provideWorkspaceSymbols(search: string, token: CancellationToken): ProviderResult<IWorkspaceSymbol[]>;
35 > resolveWorkspaceSymbol?(item: IWorkspaceSymbol, token: CancellationToken): ProviderResult<IWorkspaceSymbol>;
36 > }
37 >
38 > export namespace WorkspaceSymbolProviderRegistry {
39 >
40 > const _supports: IWorkspaceSymbolProvider[] = [];
41 >
42 > export function register(provider: IWorkspaceSymbolProvider): IDisposable {
43 let support: IWorkspaceSymbolProvider | undefined = provider;
44 if (support) {
45 _supports.push(support);
46 }
47
48 return {
49 dispose() {
50 if (support) {
51 const idx = _supports.indexOf(support);
52 if (idx >= 0) {
53 _supports.splice(idx, 1);
54 support = undefined;
55 }
56 }
57 }
58 };
59 }
61 > export function all(): IWorkspaceSymbolProvider[] {
62 return _supports.slice(0);
63 }
64 > } search.ts ×8
65 >
66 > export class WorkspaceSymbolItem {
67 > constructor(readonly symbol: IWorkspaceSymbol, readonly provider: IWorkspaceSymbolProvider) { }
68 > }
69 >
70 export async function getWorkspaceSymbols(query: string, token: CancellationToken = CancellationToken.None): Promise<WorkspaceSymbolItem[]> {
71
72 const all: WorkspaceSymbolItem[] = [];
73
74 const promises = WorkspaceSymbolProviderRegistry.all().map(async provider => {
75 try {
76 const value = await provider.provideWorkspaceSymbols(query, token);
77 if (!value) {
78 return;
79 }
80 for (const symbol of value) {
81 all.push(new WorkspaceSymbolItem(symbol, provider));
82 }
83 } catch (err) {
84 onUnexpectedExternalError(err);
85 }
86 });
87
88 await Promise.all(promises);
89
90 if (token.isCancellationRequested) {
91 return [];
92 }
93
94 // de-duplicate entries
95
96 function compareItems(a: WorkspaceSymbolItem, b: WorkspaceSymbolItem): number {
97 let res = compare(a.symbol.name, b.symbol.name);
98 if (res === 0) {
99 res = a.symbol.kind - b.symbol.kind;
100 }
101 if (res === 0) {
102 res = compare(a.symbol.location.uri.toString(), b.symbol.location.uri.toString());
103 }
104 if (res === 0) {
105 if (a.symbol.location.range && b.symbol.location.range) {
106 if (!Range.areIntersecting(a.symbol.location.range, b.symbol.location.range)) {
107 res = Range.compareRangesUsingStarts(a.symbol.location.range, b.symbol.location.range);
108 }
109 } else if (a.provider.resolveWorkspaceSymbol && !b.provider.resolveWorkspaceSymbol) {
110 res = -1;
111 } else if (!a.provider.resolveWorkspaceSymbol && b.provider.resolveWorkspaceSymbol) {
112 res = 1;
113 }
114 }
115 if (res === 0) {
116 res = compare(a.symbol.containerName ?? '', b.symbol.containerName ?? '');
117 }
118 return res;
119 }
120
121 return groupBy(all, compareItems).map(group => group[0]).flat();
122 }
124 > export interface IWorkbenchSearchConfigurationProperties extends ISearchConfigurationProperties {
125 > quickOpen?: {
126 > includeSymbols?: boolean;
127 > includeHistory?: boolean;
128 > history?: {
129 > filterSortOrder?: 'default' | 'recency';
130 > };
131 > };
132 > }
133 >
134 > export interface IWorkbenchSearchConfiguration extends ISearchConfiguration {
135 > search: IWorkbenchSearchConfigurationProperties;
136 > }
137 >
138 > /**
139 > * Helper to return all opened editors with resources not belonging to the currently opened workspace.
140 > */
141 > export function getOutOfWorkspaceEditorResources(accessor: ServicesAccessor): URI[] {
142 const editorService = accessor.get(IEditorService);
143 const contextService = accessor.get(IWorkspaceContextService);
144 const fileService = accessor.get(IFileService);
145
146 const resources = editorService.editors
147 .map(editor => EditorResourceAccessor.getOriginalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY }))
148 .filter(resource => !!resource && !contextService.isInsideWorkspace(resource) && fileService.hasProvider(resource));
149
150 return resources as URI[];
151 }
153 > // Supports patterns of <path><#|:|(><line><#|:|,><col?>> optionally followed by a range suffix <-<endLine><#|:|,><endCol?>>
154 > const LINE_COLON_PATTERN = /\s?[#:\(](?:line )?(\d*)(?:[#:,](\d*))?(?:-(\d*)(?:[#:,](\d*))?)?\)?:?\s*$/;
155 >
156 > export interface IFilterAndRange {
157 > filter: string;
158 > range: IRange;
159 > }
160 >
161 > export function extractRangeFromFilter(filter: string, unless?: string[]): IFilterAndRange | undefined {
162 > // Ignore when the unless character not the first character or is before the line colon pattern
163 > if (!filter || unless?.some(value => {
164 > const unlessCharPos = filter.indexOf(value); search.ts ×1
165 > return unlessCharPos === 0 || unlessCharPos > 0 && !LINE_COLON_PATTERN.test(filter.substring(unlessCharPos + 1));
166 > })) { search.ts ×8
167 > return undefined; search.ts ×1
168 > }
170 > let range: IRange | undefined = undefined;
171 >
172 > // Find Line/Column number from search value using RegExp
173 > const patternMatch = LINE_COLON_PATTERN.exec(filter);
174 >
175 > if (patternMatch) {
176 > const startLineNumber = parseInt(patternMatch[1] ?? '', 10); search.ts ×5
177 >
178 > // Line Number
179 > if (isNumber(startLineNumber)) {
180 > range = {
181 > startLineNumber: startLineNumber,
182 > startColumn: 1,
183 > endLineNumber: startLineNumber,
184 > endColumn: 1
185 > };
186 >
187 > // Column Number
188 > const startColumn = parseInt(patternMatch[2] ?? '', 10);
189 > if (isNumber(startColumn)) {
190 > range = { search.ts ×1
191 > startLineNumber: range.startLineNumber,
192 > startColumn: startColumn,
193 > endLineNumber: range.endLineNumber,
194 > endColumn: startColumn
195 > };
196 > }
198 > // End Line Number (range selection, e.g. "20-40")
199 > const endLineNumber = parseInt(patternMatch[3] ?? '', 10);
200 > if (isNumber(endLineNumber)) {
202 > // End Column Number (e.g. "20:3-40:5"), defaults to the start of the end line
203 > const endColumn = parseInt(patternMatch[4] ?? '', 10);
204 > range = {
205 > startLineNumber: range.startLineNumber,
206 > startColumn: range.startColumn,
207 > endLineNumber: endLineNumber,
208 > endColumn: isNumber(endColumn) ? endColumn : 1
209 > };
210 > }
211 > } search.ts ×5
212
213 // User has typed "something:" or "something#" without a line number, in this case treat as start of file
214 else if (patternMatch[1] === '') {
215 range = {
216 startLineNumber: 1,
217 startColumn: 1,
218 endLineNumber: 1,
219 endColumn: 1
220 };
221 }
222 > } search.ts ×5
224 > if (patternMatch && range) { search.ts ×8
225 > return { search.ts ×5
226 > filter: filter.substr(0, patternMatch.index), // clear range suffix from search value
227 > range
228 > };
229 > }
231 > return undefined;
232 > }
234 > export enum SearchUIState {
235 > Idle,
236 > Searching,
237 > SlowSearch
238 > }
239 >
240 > export const SearchStateKey = new RawContextKey<SearchUIState>('searchState', SearchUIState.Idle);
241 >
242 > export interface NotebookPriorityInfo {
243 > isFromSettings: boolean;
244 > filenamePatterns: string[];
245 > }
246 >
247 > export const searchConfigurationNode: IConfigurationNode = {
248 > id: 'search',
249 > order: 13,
250 > title: nls.localize('searchConfigurationTitle', "Search"),
251 > type: 'object',
252 > properties: {}
253 > };