Skip to content

Commit ea4705b

Browse files
author
Akash Satheesan
committed
fix(vscode): redo extra extension paths
1 parent 8c72047 commit ea4705b

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

lib/vscode/src/vs/platform/environment/common/argv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export interface NativeParsedArgs {
3939
'extensions-dir'?: string;
4040
'extensions-download-dir'?: string;
4141
'builtin-extensions-dir'?: string;
42+
'extra-extensions-dir'?: string[]; // NOTE@coder: added extra extensions dir
43+
'extra-builtin-extensions-dir'?: string[]; // NOTE@coder: added extra builtin extensions dir
4244
extensionDevelopmentPath?: string[]; // undefined or array of 1 or more local paths or URIs
4345
extensionTestsPath?: string; // either a local path or a URI
4446
extensionDevelopmentKind?: string[];

lib/vscode/src/vs/platform/environment/common/environment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export interface INativeEnvironmentService extends IEnvironmentService {
124124
extensionsPath: string;
125125
extensionsDownloadPath: string;
126126
builtinExtensionsPath: string;
127+
// NOTE@coder: add extraExtensionPaths/extraBuiltinExtensionPaths
128+
extraExtensionPaths: string[];
129+
extraBuiltinExtensionPaths: string[];
127130

128131
// --- smoke test support
129132
driverHandle?: string;

lib/vscode/src/vs/platform/environment/common/environmentService.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ import { URI } from 'vs/base/common/uri';
1515
import { ExtensionKind } from 'vs/platform/extensions/common/extensions';
1616
import { env } from 'vs/base/common/process';
1717

18+
// NOTE@coder: add parsePathArg
19+
function parsePathArg(arg: string | undefined, process: NodeJS.Process): string | undefined {
20+
if (!arg) {
21+
return undefined;
22+
}
23+
24+
// Determine if the arg is relative or absolute, if relative use the original CWD
25+
// (VSCODE_CWD), not the potentially overridden one (process.cwd()).
26+
const resolved = resolve(arg);
27+
28+
if (normalize(arg) === resolved) {
29+
return resolved;
30+
}
31+
32+
return resolve(process.env['VSCODE_CWD'] || process.cwd(), arg);
33+
}
34+
35+
1836
export interface INativeEnvironmentPaths {
1937

2038
/**
@@ -157,6 +175,19 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
157175
return joinPath(this.userHome, this.productService.dataFolderName, 'extensions').fsPath;
158176
}
159177

178+
/**
179+
* NOTE@coder: add extraExtensionPaths and extraBuiltinExtensionPaths
180+
*/
181+
@memoize
182+
get extraExtensionPaths(): string[] {
183+
return (this._args['extra-extensions-dir'] || []).map((p) => <string>parsePathArg(p, process));
184+
}
185+
186+
@memoize
187+
get extraBuiltinExtensionPaths(): string[] {
188+
return (this._args['extra-builtin-extensions-dir'] || []).map((p) => <string>parsePathArg(p, process));
189+
}
190+
160191
@memoize
161192
get extensionDevelopmentLocationURI(): URI[] | undefined {
162193
const extensionDevelopmentPaths = this.args.extensionDevelopmentPath;

lib/vscode/src/vs/platform/environment/node/argv.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
5252
'extensions-dir': { type: 'string', deprecates: 'extensionHomePath', cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") },
5353
'extensions-download-dir': { type: 'string' },
5454
'builtin-extensions-dir': { type: 'string' },
55+
// NOTE@coder: add extra-extensions-dir and extra-builtin-extensions-dir
56+
'extra-extensions-dir': { type: 'string[]', cat: 'o', description: 'Path to an extra user extension directory.' },
57+
'extra-builtin-extensions-dir': { type: 'string[]', cat: 'o', description: 'Path to an extra builtin extension directory.' },
5558
'list-extensions': { type: 'boolean', cat: 'e', description: localize('listExtensions', "List the installed extensions.") },
5659
'show-versions': { type: 'boolean', cat: 'e', description: localize('showVersions', "Show versions of installed extensions, when using --list-extensions.") },
5760
'category': { type: 'string', cat: 'e', description: localize('category', "Filters installed extensions by provided category, when using --list-extensions."), args: 'category' },

lib/vscode/src/vs/platform/extensionManagement/node/extensionsScanner.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class ExtensionsScanner extends Disposable {
9797
}
9898

9999
async scanAllUserExtensions(): Promise<ILocalExtension[]> {
100-
return this.scanExtensionsInDir(this.extensionsPath, ExtensionType.User);
100+
return this.scanExtensionsInDirs([this.extensionsPath, ...this.environmentService.extraExtensionPaths], ExtensionType.User);
101101
}
102102

103103
async extractUserExtension(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, token: CancellationToken): Promise<ILocalExtension> {
@@ -314,7 +314,7 @@ export class ExtensionsScanner extends Disposable {
314314
}
315315

316316
private async scanDefaultSystemExtensions(): Promise<ILocalExtension[]> {
317-
const result = await this.scanExtensionsInDir(this.systemExtensionsPath, ExtensionType.System);
317+
const result = await this.scanExtensionsInDirs([this.systemExtensionsPath, ...this.environmentService.extraBuiltinExtensionPaths], ExtensionType.System);
318318
this.logService.trace('Scanned system extensions:', result.length);
319319
return result;
320320
}
@@ -418,4 +418,9 @@ export class ExtensionsScanner extends Disposable {
418418
}
419419
});
420420
}
421+
422+
private async scanExtensionsInDirs(dirs: string[], type: ExtensionType): Promise<ILocalExtension[]>{
423+
const results = await Promise.all(dirs.map((path) => this.scanExtensionsInDir(path, type)));
424+
return results.reduce((flat, current) => flat.concat(current), []);
425+
}
421426
}

0 commit comments

Comments
 (0)