diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 8cd89e119..53e2a414b 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -24,6 +24,19 @@ export class Config { | |||
24 | ] | 24 | ] |
25 | .map(opt => `${Config.rootSection}.${opt}`); | 25 | .map(opt => `${Config.rootSection}.${opt}`); |
26 | 26 | ||
27 | private static readonly extensionVersion: string = (() => { | ||
28 | const packageJsonVersion = vscode | ||
29 | .extensions | ||
30 | .getExtension("matklad.rust-analyzer")! | ||
31 | .packageJSON | ||
32 | .version as string; // n.n.YYYYMMDD | ||
33 | |||
34 | const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; | ||
35 | const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!; | ||
36 | |||
37 | return `${yyyy}-${mm}-${dd}`; | ||
38 | })(); | ||
39 | |||
27 | private cfg!: vscode.WorkspaceConfiguration; | 40 | private cfg!: vscode.WorkspaceConfiguration; |
28 | 41 | ||
29 | constructor(private readonly ctx: vscode.ExtensionContext) { | 42 | constructor(private readonly ctx: vscode.ExtensionContext) { |
@@ -31,7 +44,6 @@ export class Config { | |||
31 | this.refreshConfig(); | 44 | this.refreshConfig(); |
32 | } | 45 | } |
33 | 46 | ||
34 | |||
35 | private refreshConfig() { | 47 | private refreshConfig() { |
36 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); | 48 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); |
37 | console.log("Using configuration:", this.cfg); | 49 | console.log("Using configuration:", this.cfg); |
@@ -68,7 +80,7 @@ export class Config { | |||
68 | * `platform` on GitHub releases. (It is also stored under the same name when | 80 | * `platform` on GitHub releases. (It is also stored under the same name when |
69 | * downloaded by the extension). | 81 | * downloaded by the extension). |
70 | */ | 82 | */ |
71 | get prebuiltLangServerFileName(): null | string { | 83 | get prebuiltServerFileName(): null | string { |
72 | // See possible `arch` values here: | 84 | // See possible `arch` values here: |
73 | // https://nodejs.org/api/process.html#process_process_arch | 85 | // https://nodejs.org/api/process.html#process_process_arch |
74 | 86 | ||
@@ -98,17 +110,17 @@ export class Config { | |||
98 | } | 110 | } |
99 | } | 111 | } |
100 | 112 | ||
101 | get langServerBinarySource(): null | BinarySource { | 113 | get serverSource(): null | BinarySource { |
102 | const langServerPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath"); | 114 | const serverPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath"); |
103 | 115 | ||
104 | if (langServerPath) { | 116 | if (serverPath) { |
105 | return { | 117 | return { |
106 | type: BinarySource.Type.ExplicitPath, | 118 | type: BinarySource.Type.ExplicitPath, |
107 | path: Config.replaceTildeWithHomeDir(langServerPath) | 119 | path: Config.replaceTildeWithHomeDir(serverPath) |
108 | }; | 120 | }; |
109 | } | 121 | } |
110 | 122 | ||
111 | const prebuiltBinaryName = this.prebuiltLangServerFileName; | 123 | const prebuiltBinaryName = this.prebuiltServerFileName; |
112 | 124 | ||
113 | if (!prebuiltBinaryName) return null; | 125 | if (!prebuiltBinaryName) return null; |
114 | 126 | ||
@@ -116,6 +128,8 @@ export class Config { | |||
116 | type: BinarySource.Type.GithubRelease, | 128 | type: BinarySource.Type.GithubRelease, |
117 | dir: this.ctx.globalStoragePath, | 129 | dir: this.ctx.globalStoragePath, |
118 | file: prebuiltBinaryName, | 130 | file: prebuiltBinaryName, |
131 | storage: this.ctx.globalState, | ||
132 | version: Config.extensionVersion, | ||
119 | repo: { | 133 | repo: { |
120 | name: "rust-analyzer", | 134 | name: "rust-analyzer", |
121 | owner: "rust-analyzer", | 135 | owner: "rust-analyzer", |
@@ -153,5 +167,5 @@ export class Config { | |||
153 | } | 167 | } |
154 | 168 | ||
155 | // for internal use | 169 | // for internal use |
156 | get withSysroot() { return this.cfg.get("withSysroot", false); } | 170 | get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; } |
157 | } | 171 | } |