resources.ts ×13

Frontier kind: Joint frontier

unlabeled · c_ff405d253784

1 test · 24391 LOC · 125 files · introduces 1 test · 163 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges163 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
2975 ranges24391 lines · 125 files · Browse complete extent
All tests (intent)
1 testBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 163 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/common/resources.ts 163 introduced LOC · 13 ranges

Open complete file

33
34 constructor(
35 > private getExpression: (folder?: URI) => IExpression | undefined, resources.ts
36 > private shouldUpdate: (event: IConfigurationChangeEvent) => boolean,
37 > @IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
38 > @IConfigurationService private readonly configurationService: IConfigurationService
39 > ) {
40 > super();
41 >
42 > this.updateExpressions(false);
43 >
44 > this.registerListeners();
45 > }
46
47 private registerListeners(): void {
48 > this._register(this.configurationService.onDidChangeConfiguration(e => { resources.ts
49 > if (this.shouldUpdate(e)) {
50 > this.updateExpressions(true);
51 > }
52 > }));
53 >
54 > this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.updateExpressions(true)));
55 > }
56
57 private updateExpressions(fromEvent: boolean): void {
58 > let changed = false; resources.ts
59 >
60 > // Add expressions per workspaces that got added
61 > for (const folder of this.contextService.getWorkspace().folders) {
62 > const folderUriStr = folder.uri.toString();
63 >
64 > const newExpression = this.doGetExpression(folder.uri);
65 > const currentExpression = this.mapFolderToConfiguredExpression.get(folderUriStr);
66 >
67 > if (newExpression) {
68 > if (!currentExpression || !equals(currentExpression.expression, newExpression.expression)) {
69 > changed = true;
70 >
71 > this.mapFolderToParsedExpression.set(folderUriStr, parse(newExpression.expression));
72 > this.mapFolderToConfiguredExpression.set(folderUriStr, newExpression);
73 > }
74 > } else {
75 > if (currentExpression) {
76 > changed = true;
77 >
78 > this.mapFolderToParsedExpression.delete(folderUriStr);
79 > this.mapFolderToConfiguredExpression.delete(folderUriStr);
80 > }
81 > }
82 > }
83 >
84 > // Remove expressions per workspace no longer present
85 > const foldersMap = new ResourceSet(this.contextService.getWorkspace().folders.map(folder => folder.uri));
86 > for (const [folder] of this.mapFolderToConfiguredExpression) {
87 > if (folder === ResourceGlobMatcher.NO_FOLDER) {
88 > continue; // always keep this one
89 > }
90 >
91 > if (!foldersMap.has(URI.parse(folder))) {
92 this.mapFolderToParsedExpression.delete(folder);
93 this.mapFolderToConfiguredExpression.delete(folder);
95 changed = true;
96 }
97 > } resources.ts
98 >
99 > // Always set for resources outside workspace as well
100 > const globalNewExpression = this.doGetExpression(undefined);
101 > const globalCurrentExpression = this.mapFolderToConfiguredExpression.get(ResourceGlobMatcher.NO_FOLDER);
102 > if (globalNewExpression) {
103 > if (!globalCurrentExpression || !equals(globalCurrentExpression.expression, globalNewExpression.expression)) {
104 > changed = true;
105 >
106 > this.mapFolderToParsedExpression.set(ResourceGlobMatcher.NO_FOLDER, parse(globalNewExpression.expression));
107 > this.mapFolderToConfiguredExpression.set(ResourceGlobMatcher.NO_FOLDER, globalNewExpression);
108 > }
109 > } else {
110 > if (globalCurrentExpression) {
111 > changed = true;
112 >
113 > this.mapFolderToParsedExpression.delete(ResourceGlobMatcher.NO_FOLDER);
114 > this.mapFolderToConfiguredExpression.delete(ResourceGlobMatcher.NO_FOLDER);
115 > }
116 > }
117 >
118 > if (fromEvent && changed) {
119 > this._onExpressionChange.fire();
120 > }
121 > }
122
123 private doGetExpression(resource: URI | undefined): IConfiguredExpression | undefined {
124 > const expression = this.getExpression(resource); resources.ts
125 > if (!expression) {
126 > return undefined;
127 > }
128 >
129 > const keys = Object.keys(expression);
130 > if (keys.length === 0) {
131 return undefined;
132 }
133 > resources.ts
134 > let hasAbsolutePath = false;
135 >
136 > // Check the expression for absolute paths/globs
137 > // and specifically for Windows, make sure the
138 > // drive letter is lowercased, because we later
139 > // check with `URI.fsPath` which is always putting
140 > // the drive letter lowercased.
141 >
142 > const massagedExpression: IExpression = Object.create(null);
143 > for (const key of keys) {
144 > if (!hasAbsolutePath) {
145 > hasAbsolutePath = isAbsolute(key);
146 > }
147 >
148 > let massagedKey = key;
149 >
150 > const driveLetter = getDriveLetter(massagedKey, true /* probe for windows */);
151 > if (driveLetter) {
152 > const driveLetterLower = driveLetter.toLowerCase();
153 > if (driveLetter !== driveLetter.toLowerCase()) {
154 > massagedKey = `${driveLetterLower}${massagedKey.substring(1)}`;
155 > }
156 > }
157 >
158 > massagedExpression[massagedKey] = expression[key];
159 > }
160 >
161 > return {
162 > expression: massagedExpression,
163 > hasAbsolutePath
164 > };
165 > }
166
167 matches(
168 > resource: URI, resources.ts
169 > hasSibling?: (name: string) => boolean
170 > ): boolean {
171 > if (this.mapFolderToParsedExpression.size === 0) {
172 > return false; // return early: no expression for this matcher
173 > }
174 >
175 > const folder = this.contextService.getWorkspaceFolder(resource);
176 > let expressionForFolder: ParsedExpression | undefined;
177 > let expressionConfigForFolder: IConfiguredExpression | undefined;
178 > if (folder && this.mapFolderToParsedExpression.has(folder.uri.toString())) {
179 expressionForFolder = this.mapFolderToParsedExpression.get(folder.uri.toString());
180 expressionConfigForFolder = this.mapFolderToConfiguredExpression.get(folder.uri.toString());
181 > } else { resources.ts
182 > expressionForFolder = this.mapFolderToParsedExpression.get(ResourceGlobMatcher.NO_FOLDER);
183 > expressionConfigForFolder = this.mapFolderToConfiguredExpression.get(ResourceGlobMatcher.NO_FOLDER);
184 > }
185 >
186 > if (!expressionForFolder) {
187 return false; // return early: no expression for this resource
188 }
189 > resources.ts
190 > // If the resource if from a workspace, convert its absolute path to a relative
191 > // path so that glob patterns have a higher probability to match. For example
192 > // a glob pattern of "src/**" will not match on an absolute path "/folder/src/file.txt"
193 > // but can match on "src/file.txt"
194 >
195 > let resourcePathToMatch: string | undefined;
196 > if (folder) {
197 resourcePathToMatch = relativePath(folder.uri, resource);
198 > } else { resources.ts
199 > resourcePathToMatch = this.uriToPath(resource);
200 > }
201 >
202 > if (typeof resourcePathToMatch === 'string' && !!expressionForFolder(resourcePathToMatch, undefined, hasSibling)) {
203 > return true;
204 > }
205 >
206 > // If the configured expression has an absolute path, we also check for absolute paths
207 > // to match, otherwise we potentially miss out on matches. We only do that if we previously
208 > // matched on the relative path.
209 >
210 > if (resourcePathToMatch !== this.uriToPath(resource) && expressionConfigForFolder?.hasAbsolutePath) {
211 return !!expressionForFolder(this.uriToPath(resource), undefined, hasSibling);
212 }
213 > resources.ts
214 > return false;
215 > }
216
217 private uriToPath(uri: URI): string {
218 > if (uri.scheme === Schemas.file) { resources.ts
219 > return uri.fsPath;
220 > }
221
222 return uri.path;
223 > } resources.ts
224 }