diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 106 |
1 files changed, 45 insertions, 61 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 602538ea1..7668c20b7 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -1,29 +1,10 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import { log } from "./util"; | 2 | import { log } from "./util"; |
3 | 3 | ||
4 | export interface InlayHintOptions { | ||
5 | typeHints: boolean; | ||
6 | parameterHints: boolean; | ||
7 | maxLength: number | null; | ||
8 | } | ||
9 | |||
10 | export interface CargoWatchOptions { | ||
11 | enable: boolean; | ||
12 | arguments: string[]; | ||
13 | command: string; | ||
14 | allTargets: boolean; | ||
15 | } | ||
16 | |||
17 | export interface CargoFeatures { | ||
18 | noDefaultFeatures: boolean; | ||
19 | allFeatures: boolean; | ||
20 | features: string[]; | ||
21 | loadOutDirsFromCheck: boolean; | ||
22 | } | ||
23 | |||
24 | export type UpdatesChannel = "stable" | "nightly"; | 4 | export type UpdatesChannel = "stable" | "nightly"; |
25 | 5 | ||
26 | export const NIGHTLY_TAG = "nightly"; | 6 | export const NIGHTLY_TAG = "nightly"; |
7 | |||
27 | export class Config { | 8 | export class Config { |
28 | readonly extensionId = "matklad.rust-analyzer"; | 9 | readonly extensionId = "matklad.rust-analyzer"; |
29 | 10 | ||
@@ -44,25 +25,24 @@ export class Config { | |||
44 | enableProposedApi: boolean | undefined; | 25 | enableProposedApi: boolean | undefined; |
45 | } = vscode.extensions.getExtension(this.extensionId)!.packageJSON; | 26 | } = vscode.extensions.getExtension(this.extensionId)!.packageJSON; |
46 | 27 | ||
47 | private cfg!: vscode.WorkspaceConfiguration; | 28 | readonly globalStoragePath: string; |
48 | 29 | ||
49 | constructor(private readonly ctx: vscode.ExtensionContext) { | 30 | constructor(ctx: vscode.ExtensionContext) { |
50 | vscode.workspace.onDidChangeConfiguration(this.onConfigChange, this, ctx.subscriptions); | 31 | this.globalStoragePath = ctx.globalStoragePath; |
51 | this.refreshConfig(); | 32 | vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions); |
33 | this.refreshLogging(); | ||
52 | } | 34 | } |
53 | 35 | ||
54 | private refreshConfig() { | 36 | private refreshLogging() { |
55 | this.cfg = vscode.workspace.getConfiguration(this.rootSection); | 37 | log.setEnabled(this.traceExtension); |
56 | const enableLogging = this.cfg.get("trace.extension") as boolean; | ||
57 | log.setEnabled(enableLogging); | ||
58 | log.debug( | 38 | log.debug( |
59 | "Extension version:", this.package.version, | 39 | "Extension version:", this.package.version, |
60 | "using configuration:", this.cfg | 40 | "using configuration:", this.cfg |
61 | ); | 41 | ); |
62 | } | 42 | } |
63 | 43 | ||
64 | private async onConfigChange(event: vscode.ConfigurationChangeEvent) { | 44 | private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) { |
65 | this.refreshConfig(); | 45 | this.refreshLogging(); |
66 | 46 | ||
67 | const requiresReloadOpt = this.requiresReloadOpts.find( | 47 | const requiresReloadOpt = this.requiresReloadOpts.find( |
68 | opt => event.affectsConfiguration(opt) | 48 | opt => event.affectsConfiguration(opt) |
@@ -80,49 +60,53 @@ export class Config { | |||
80 | } | 60 | } |
81 | } | 61 | } |
82 | 62 | ||
83 | get globalStoragePath(): string { return this.ctx.globalStoragePath; } | ||
84 | |||
85 | // We don't do runtime config validation here for simplicity. More on stackoverflow: | 63 | // We don't do runtime config validation here for simplicity. More on stackoverflow: |
86 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension | 64 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension |
87 | 65 | ||
88 | get serverPath() { return this.cfg.get("serverPath") as null | string; } | 66 | private get cfg(): vscode.WorkspaceConfiguration { |
89 | get channel() { return this.cfg.get<"stable" | "nightly">("updates.channel")!; } | 67 | return vscode.workspace.getConfiguration(this.rootSection); |
90 | get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } | 68 | } |
91 | get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } | 69 | |
92 | get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } | 70 | get serverPath() { return this.cfg.get<null | string>("serverPath")!; } |
93 | get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } | 71 | get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; } |
94 | get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; } | 72 | get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; } |
95 | get inlayHints(): InlayHintOptions { | 73 | get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; } |
74 | get highlightingOn() { return this.cfg.get<boolean>("highlightingOn")!; } | ||
75 | get rainbowHighlightingOn() { return this.cfg.get<boolean>("rainbowHighlightingOn")!; } | ||
76 | get lruCapacity() { return this.cfg.get<null | number>("lruCapacity")!; } | ||
77 | get excludeGlobs() { return this.cfg.get<string[]>("excludeGlobs")!; } | ||
78 | get useClientWatching() { return this.cfg.get<boolean>("useClientWatching")!; } | ||
79 | get featureFlags() { return this.cfg.get<Record<string, boolean>>("featureFlags")!; } | ||
80 | get rustfmtArgs() { return this.cfg.get<string[]>("rustfmtArgs")!; } | ||
81 | get loadOutDirsFromCheck() { return this.cfg.get<boolean>("loadOutDirsFromCheck")!; } | ||
82 | get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; } | ||
83 | |||
84 | // for internal use | ||
85 | get withSysroot() { return this.cfg.get<boolean>("withSysroot", true)!; } | ||
86 | |||
87 | get inlayHints() { | ||
96 | return { | 88 | return { |
97 | typeHints: this.cfg.get("inlayHints.typeHints") as boolean, | 89 | typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!, |
98 | parameterHints: this.cfg.get("inlayHints.parameterHints") as boolean, | 90 | parameterHints: this.cfg.get<boolean>("inlayHints.parameterHints")!, |
99 | maxLength: this.cfg.get("inlayHints.maxLength") as null | number, | 91 | maxLength: this.cfg.get<null | number>("inlayHints.maxLength")!, |
100 | }; | 92 | }; |
101 | } | 93 | } |
102 | get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; } | ||
103 | get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; } | ||
104 | get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; } | ||
105 | get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; } | ||
106 | get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; } | ||
107 | 94 | ||
108 | get cargoWatchOptions(): CargoWatchOptions { | 95 | get cargoWatchOptions() { |
109 | return { | 96 | return { |
110 | enable: this.cfg.get("cargo-watch.enable") as boolean, | 97 | enable: this.cfg.get<boolean>("cargo-watch.enable")!, |
111 | arguments: this.cfg.get("cargo-watch.arguments") as string[], | 98 | arguments: this.cfg.get<string[]>("cargo-watch.arguments")!, |
112 | allTargets: this.cfg.get("cargo-watch.allTargets") as boolean, | 99 | allTargets: this.cfg.get<boolean>("cargo-watch.allTargets")!, |
113 | command: this.cfg.get("cargo-watch.command") as string, | 100 | command: this.cfg.get<string>("cargo-watch.command")!, |
114 | }; | 101 | }; |
115 | } | 102 | } |
116 | 103 | ||
117 | get cargoFeatures(): CargoFeatures { | 104 | get cargoFeatures() { |
118 | return { | 105 | return { |
119 | noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean, | 106 | noDefaultFeatures: this.cfg.get<boolean>("cargoFeatures.noDefaultFeatures")!, |
120 | allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean, | 107 | allFeatures: this.cfg.get<boolean>("cargoFeatures.allFeatures")!, |
121 | features: this.cfg.get("cargoFeatures.features") as string[], | 108 | features: this.cfg.get<string[]>("cargoFeatures.features")!, |
122 | loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean, | 109 | loadOutDirsFromCheck: this.cfg.get<boolean>("cargoFeatures.loadOutDirsFromCheck")!, |
123 | }; | 110 | }; |
124 | } | 111 | } |
125 | |||
126 | // for internal use | ||
127 | get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; } | ||
128 | } | 112 | } |