Skip to content

Commit 63f3c04

Browse files
committed
Move user data directory logic out of patch
1 parent 8a0f1d8 commit 63f3c04

File tree

2 files changed

+35
-106
lines changed

2 files changed

+35
-106
lines changed

scripts/vscode.patch

+15-103
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ index 0000000000..56331ff1fc
934934
+require('../../bootstrap-amd').load('vs/server/entry');
935935
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
936936
new file mode 100644
937-
index 0000000000..3bfef75d81
937+
index 0000000000..f3e358096f
938938
--- /dev/null
939939
+++ b/src/vs/server/ipc.d.ts
940-
@@ -0,0 +1,91 @@
940+
@@ -0,0 +1,102 @@
941941
+/**
942942
+ * External interfaces for integration into code-server over IPC. No vs imports
943943
+ * should be made in this file.
@@ -976,6 +976,17 @@ index 0000000000..3bfef75d81
976976
+}
977977
+
978978
+export interface Args {
979+
+ 'user-data-dir'?: string;
980+
+
981+
+ 'extensions-dir'?: string;
982+
+ 'builtin-extensions-dir'?: string;
983+
+ 'extra-extensions-dir'?: string[];
984+
+ 'extra-builtin-extensions-dir'?: string[];
985+
+
986+
+ log?: string;
987+
+ trace?: boolean;
988+
+ verbose?: boolean;
989+
+
979990
+ _: string[];
980991
+}
981992
+
@@ -1378,87 +1389,6 @@ index 0000000000..9c240b992d
13781389
+ this._$onMessage.fire(message);
13791390
+ }
13801391
+}
1381-
diff --git a/src/vs/server/node/cli.ts b/src/vs/server/node/cli.ts
1382-
new file mode 100644
1383-
index 0000000000..117cc4900a
1384-
--- /dev/null
1385-
+++ b/src/vs/server/node/cli.ts
1386-
@@ -0,0 +1,75 @@
1387-
+import * as os from 'os';
1388-
+import * as path from 'path';
1389-
+import { main as vsCli } from 'vs/code/node/cliProcessMain';
1390-
+import { validatePaths } from 'vs/code/node/paths';
1391-
+import { ParsedArgs } from 'vs/platform/environment/common/environment';
1392-
+import { buildHelpMessage, buildVersionMessage, OPTIONS } from 'vs/platform/environment/node/argv';
1393-
+import { parseMainProcessArgv } from 'vs/platform/environment/node/argvHelper';
1394-
+import product from 'vs/platform/product/common/product';
1395-
+import { logger } from 'vs/server/node/logger';
1396-
+import { xdgLocalDir } from 'vs/server/node/util';
1397-
+
1398-
+export const parseArgs = (rawArgs: string[]): ParsedArgs => {
1399-
+ // Remove options that won't work or don't make sense.
1400-
+ for (let key in OPTIONS) {
1401-
+ switch (key) {
1402-
+ case 'add':
1403-
+ case 'diff':
1404-
+ case 'file-uri':
1405-
+ case 'folder-uri':
1406-
+ case 'goto':
1407-
+ case 'new-window':
1408-
+ case 'reuse-window':
1409-
+ case 'wait':
1410-
+ case 'disable-gpu':
1411-
+ // TODO: pretty sure these don't work but not 100%.
1412-
+ case 'prof-startup':
1413-
+ case 'inspect-extensions':
1414-
+ case 'inspect-brk-extensions':
1415-
+ delete OPTIONS[key];
1416-
+ break;
1417-
+ }
1418-
+ }
1419-
+
1420-
+ const args = parseMainProcessArgv(rawArgs);
1421-
+ if (!args['user-data-dir']) {
1422-
+ args['user-data-dir'] = xdgLocalDir;
1423-
+ }
1424-
+ if (!args['extensions-dir']) {
1425-
+ args['extensions-dir'] = path.join(args['user-data-dir'], 'extensions');
1426-
+ }
1427-
+
1428-
+ if (!args.verbose && !args.log && process.env.LOG_LEVEL) {
1429-
+ args.log = process.env.LOG_LEVEL;
1430-
+ }
1431-
+
1432-
+ return validatePaths(args);
1433-
+};
1434-
+
1435-
+export const startCli = (args: ParsedArgs): boolean | Promise<void> => {
1436-
+ if (args.help) {
1437-
+ const executable = `${product.applicationName}${os.platform() === 'win32' ? '.exe' : ''}`;
1438-
+ console.log(buildHelpMessage(product.nameLong, executable, product.version, OPTIONS, false));
1439-
+ return true;
1440-
+ }
1441-
+
1442-
+ if (args.version) {
1443-
+ buildVersionMessage(product.version, product.commit).split('\n').map((line) => logger.info(line));
1444-
+ return true;
1445-
+ }
1446-
+
1447-
+ const shouldSpawnCliProcess = (): boolean => {
1448-
+ return !!args['install-source']
1449-
+ || !!args['list-extensions']
1450-
+ || !!args['install-extension']
1451-
+ || !!args['uninstall-extension']
1452-
+ || !!args['locate-extension']
1453-
+ || !!args['telemetry'];
1454-
+ };
1455-
+
1456-
+ if (shouldSpawnCliProcess()) {
1457-
+ return vsCli(args);
1458-
+ }
1459-
+
1460-
+ return false;
1461-
+};
14621392
diff --git a/src/vs/server/node/connection.ts b/src/vs/server/node/connection.ts
14631393
new file mode 100644
14641394
index 0000000000..3b42933419
@@ -2468,12 +2398,10 @@ index 0000000000..fc69441cf0
24682398
+};
24692399
diff --git a/src/vs/server/node/util.ts b/src/vs/server/node/util.ts
24702400
new file mode 100644
2471-
index 0000000000..ac950994b9
2401+
index 0000000000..06b080044c
24722402
--- /dev/null
24732403
+++ b/src/vs/server/node/util.ts
2474-
@@ -0,0 +1,27 @@
2475-
+import * as path from 'path';
2476-
+import * as os from 'os';
2404+
@@ -0,0 +1,9 @@
24772405
+import { getPathFromAmdModule } from 'vs/base/common/amd';
24782406
+import { URITransformer, IRawURITransformer } from 'vs/base/common/uriIpc';
24792407
+
@@ -2483,22 +2411,6 @@ index 0000000000..ac950994b9
24832411
+ const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
24842412
+ return new URITransformer(rawURITransformer);
24852413
+};
2486-
+
2487-
+const getXdgDataDir = (): string => {
2488-
+ switch (process.platform) {
2489-
+ case 'win32':
2490-
+ return path.join(process.env.XDG_DATA_HOME || path.join(os.homedir(), 'AppData/Local'), 'code-server/Data');
2491-
+ case 'darwin':
2492-
+ return path.join(
2493-
+ process.env.XDG_DATA_HOME || path.join(os.homedir(), 'Library/Application Support'),
2494-
+ 'code-server'
2495-
+ );
2496-
+ default:
2497-
+ return path.join(process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local/share'), 'code-server');
2498-
+ }
2499-
+};
2500-
+
2501-
+export const xdgLocalDir = getXdgDataDir();
25022414
diff --git a/src/vs/workbench/api/browser/extensionHost.contribution.ts b/src/vs/workbench/api/browser/extensionHost.contribution.ts
25032415
index 2905c52411..6ecfae2634 100644
25042416
--- a/src/vs/workbench/api/browser/extensionHost.contribution.ts

src/node/cli.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { AuthType } from "./http"
1+
import * as path from "path"
2+
import { logger, Level } from "@coder/logger"
23
import { Args as VsArgs } from "../../lib/vscode/src/vs/server/ipc"
4+
import { AuthType } from "./http"
5+
import { xdgLocalDir } from "./util"
36

47
export interface Args extends VsArgs {
58
auth?: AuthType
@@ -19,9 +22,23 @@ export interface Args extends VsArgs {
1922
// TODO: Implement proper CLI parser.
2023
export const parse = (): Args => {
2124
const last = process.argv[process.argv.length - 1]
25+
const userDataDir = xdgLocalDir
26+
const verbose = process.argv.includes("--verbose")
27+
const trace = process.argv.includes("--trace")
28+
29+
if (verbose || trace) {
30+
process.env.LOG_LEVEL = "trace"
31+
logger.level = Level.Trace
32+
}
33+
2234
return {
23-
version: process.argv.includes("--version"),
24-
json: process.argv.includes("--json"),
35+
"extensions-dir": path.join(userDataDir, "extensions"),
36+
"user-data-dir": userDataDir,
2537
_: last && !last.startsWith("-") ? [last] : [],
38+
json: process.argv.includes("--json"),
39+
log: process.env.LOG_LEVEL,
40+
trace,
41+
verbose,
42+
version: process.argv.includes("--version"),
2643
}
2744
}

0 commit comments

Comments
 (0)