diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 87 |
1 files changed, 30 insertions, 57 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index e131f09df..ec2790b63 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -1,18 +1,11 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | 2 | ||
3 | import { Server } from './server'; | ||
4 | |||
5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 3 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
6 | 4 | ||
7 | export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled'; | ||
8 | export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose'; | ||
9 | |||
10 | export interface CargoWatchOptions { | 5 | export interface CargoWatchOptions { |
11 | enableOnStartup: CargoWatchStartupOptions; | 6 | enable: boolean; |
12 | arguments: string; | 7 | arguments: string[]; |
13 | command: string; | 8 | command: string; |
14 | trace: CargoWatchTraceOptions; | ||
15 | ignore: string[]; | ||
16 | allTargets: boolean; | 9 | allTargets: boolean; |
17 | } | 10 | } |
18 | 11 | ||
@@ -23,27 +16,25 @@ export interface CargoFeatures { | |||
23 | } | 16 | } |
24 | 17 | ||
25 | export class Config { | 18 | export class Config { |
26 | public highlightingOn = true; | 19 | highlightingOn = true; |
27 | public rainbowHighlightingOn = false; | 20 | rainbowHighlightingOn = false; |
28 | public enableEnhancedTyping = true; | 21 | enableEnhancedTyping = true; |
29 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | 22 | raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; |
30 | public lruCapacity: null | number = null; | 23 | lruCapacity: null | number = null; |
31 | public displayInlayHints = true; | 24 | displayInlayHints = true; |
32 | public maxInlayHintLength: null | number = null; | 25 | maxInlayHintLength: null | number = null; |
33 | public excludeGlobs = []; | 26 | excludeGlobs = []; |
34 | public useClientWatching = true; | 27 | useClientWatching = true; |
35 | public featureFlags = {}; | 28 | featureFlags = {}; |
36 | // for internal use | 29 | // for internal use |
37 | public withSysroot: null | boolean = null; | 30 | withSysroot: null | boolean = null; |
38 | public cargoWatchOptions: CargoWatchOptions = { | 31 | cargoWatchOptions: CargoWatchOptions = { |
39 | enableOnStartup: 'ask', | 32 | enable: true, |
40 | trace: 'off', | 33 | arguments: [], |
41 | arguments: '', | ||
42 | command: '', | 34 | command: '', |
43 | ignore: [], | ||
44 | allTargets: true, | 35 | allTargets: true, |
45 | }; | 36 | }; |
46 | public cargoFeatures: CargoFeatures = { | 37 | cargoFeatures: CargoFeatures = { |
47 | noDefaultFeatures: false, | 38 | noDefaultFeatures: false, |
48 | allFeatures: true, | 39 | allFeatures: true, |
49 | features: [], | 40 | features: [], |
@@ -52,15 +43,14 @@ export class Config { | |||
52 | private prevEnhancedTyping: null | boolean = null; | 43 | private prevEnhancedTyping: null | boolean = null; |
53 | private prevCargoFeatures: null | CargoFeatures = null; | 44 | private prevCargoFeatures: null | CargoFeatures = null; |
54 | 45 | ||
55 | constructor() { | 46 | constructor(ctx: vscode.ExtensionContext) { |
56 | vscode.workspace.onDidChangeConfiguration(_ => | 47 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions); |
57 | this.userConfigChanged(), | 48 | this.refresh(); |
58 | ); | ||
59 | this.userConfigChanged(); | ||
60 | } | 49 | } |
61 | 50 | ||
62 | public userConfigChanged() { | 51 | private refresh() { |
63 | const config = vscode.workspace.getConfiguration('rust-analyzer'); | 52 | const config = vscode.workspace.getConfiguration('rust-analyzer'); |
53 | |||
64 | let requireReloadMessage = null; | 54 | let requireReloadMessage = null; |
65 | 55 | ||
66 | if (config.has('highlightingOn')) { | 56 | if (config.has('highlightingOn')) { |
@@ -73,10 +63,6 @@ export class Config { | |||
73 | ) as boolean; | 63 | ) as boolean; |
74 | } | 64 | } |
75 | 65 | ||
76 | if (!this.highlightingOn && Server) { | ||
77 | Server.highlighter.removeHighlights(); | ||
78 | } | ||
79 | |||
80 | if (config.has('enableEnhancedTyping')) { | 66 | if (config.has('enableEnhancedTyping')) { |
81 | this.enableEnhancedTyping = config.get( | 67 | this.enableEnhancedTyping = config.get( |
82 | 'enableEnhancedTyping', | 68 | 'enableEnhancedTyping', |
@@ -100,23 +86,17 @@ export class Config { | |||
100 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); | 86 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); |
101 | } | 87 | } |
102 | 88 | ||
103 | if (config.has('enableCargoWatchOnStartup')) { | 89 | if (config.has('cargo-watch.enable')) { |
104 | this.cargoWatchOptions.enableOnStartup = config.get< | 90 | this.cargoWatchOptions.enable = config.get<boolean>( |
105 | CargoWatchStartupOptions | 91 | 'cargo-watch.enable', |
106 | >('enableCargoWatchOnStartup', 'ask'); | 92 | true, |
107 | } | ||
108 | |||
109 | if (config.has('trace.cargo-watch')) { | ||
110 | this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>( | ||
111 | 'trace.cargo-watch', | ||
112 | 'off', | ||
113 | ); | 93 | ); |
114 | } | 94 | } |
115 | 95 | ||
116 | if (config.has('cargo-watch.arguments')) { | 96 | if (config.has('cargo-watch.arguments')) { |
117 | this.cargoWatchOptions.arguments = config.get<string>( | 97 | this.cargoWatchOptions.arguments = config.get<string[]>( |
118 | 'cargo-watch.arguments', | 98 | 'cargo-watch.arguments', |
119 | '', | 99 | [], |
120 | ); | 100 | ); |
121 | } | 101 | } |
122 | 102 | ||
@@ -127,13 +107,6 @@ export class Config { | |||
127 | ); | 107 | ); |
128 | } | 108 | } |
129 | 109 | ||
130 | if (config.has('cargo-watch.ignore')) { | ||
131 | this.cargoWatchOptions.ignore = config.get<string[]>( | ||
132 | 'cargo-watch.ignore', | ||
133 | [], | ||
134 | ); | ||
135 | } | ||
136 | |||
137 | if (config.has('cargo-watch.allTargets')) { | 110 | if (config.has('cargo-watch.allTargets')) { |
138 | this.cargoWatchOptions.allTargets = config.get<boolean>( | 111 | this.cargoWatchOptions.allTargets = config.get<boolean>( |
139 | 'cargo-watch.allTargets', | 112 | 'cargo-watch.allTargets', |
@@ -190,9 +163,9 @@ export class Config { | |||
190 | (this.cargoFeatures.allFeatures !== | 163 | (this.cargoFeatures.allFeatures !== |
191 | this.prevCargoFeatures.allFeatures || | 164 | this.prevCargoFeatures.allFeatures || |
192 | this.cargoFeatures.noDefaultFeatures !== | 165 | this.cargoFeatures.noDefaultFeatures !== |
193 | this.prevCargoFeatures.noDefaultFeatures || | 166 | this.prevCargoFeatures.noDefaultFeatures || |
194 | this.cargoFeatures.features.length !== | 167 | this.cargoFeatures.features.length !== |
195 | this.prevCargoFeatures.features.length || | 168 | this.prevCargoFeatures.features.length || |
196 | this.cargoFeatures.features.some( | 169 | this.cargoFeatures.features.some( |
197 | (v, i) => v !== this.prevCargoFeatures!.features[i], | 170 | (v, i) => v !== this.prevCargoFeatures!.features[i], |
198 | )) | 171 | )) |