1 import * as vscode from 'vscode';
3 import { Server } from './server';
5 const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
7 export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled';
8 export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
10 export interface CargoWatchOptions {
11 enableOnStartup: CargoWatchStartupOptions;
14 trace: CargoWatchTraceOptions;
19 export interface CargoFeatures {
20 noDefaultFeatures: boolean;
26 public highlightingOn = true;
27 public rainbowHighlightingOn = false;
28 public enableEnhancedTyping = true;
29 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
30 public lruCapacity: null | number = null;
31 public displayInlayHints = true;
32 public maxInlayHintLength: null | number = null;
33 public excludeGlobs = [];
34 public useClientWatching = true;
35 public featureFlags = {};
37 public withSysroot: null | boolean = null;
38 public cargoWatchOptions: CargoWatchOptions = {
39 enableOnStartup: 'ask',
46 public cargoFeatures: CargoFeatures = {
47 noDefaultFeatures: false,
52 private prevEnhancedTyping: null | boolean = null;
53 private prevCargoFeatures: null | CargoFeatures = null;
56 vscode.workspace.onDidChangeConfiguration(_ =>
57 this.userConfigChanged(),
59 this.userConfigChanged();
62 public userConfigChanged() {
63 const config = vscode.workspace.getConfiguration('rust-analyzer');
64 let requireReloadMessage = null;
66 if (config.has('highlightingOn')) {
67 this.highlightingOn = config.get('highlightingOn') as boolean;
70 if (config.has('rainbowHighlightingOn')) {
71 this.rainbowHighlightingOn = config.get(
72 'rainbowHighlightingOn',
76 if (!this.highlightingOn && Server) {
77 Server.highlighter.removeHighlights();
80 if (config.has('enableEnhancedTyping')) {
81 this.enableEnhancedTyping = config.get(
82 'enableEnhancedTyping',
85 if (this.prevEnhancedTyping === null) {
86 this.prevEnhancedTyping = this.enableEnhancedTyping;
88 } else if (this.prevEnhancedTyping === null) {
89 this.prevEnhancedTyping = this.enableEnhancedTyping;
92 if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
93 requireReloadMessage =
94 'Changing enhanced typing setting requires a reload';
95 this.prevEnhancedTyping = this.enableEnhancedTyping;
98 if (config.has('raLspServerPath')) {
99 this.raLspServerPath =
100 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
103 if (config.has('enableCargoWatchOnStartup')) {
104 this.cargoWatchOptions.enableOnStartup = config.get<
105 CargoWatchStartupOptions
106 >('enableCargoWatchOnStartup', 'ask');
109 if (config.has('trace.cargo-watch')) {
110 this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
116 if (config.has('cargo-watch.arguments')) {
117 this.cargoWatchOptions.arguments = config.get<string>(
118 'cargo-watch.arguments',
123 if (config.has('cargo-watch.command')) {
124 this.cargoWatchOptions.command = config.get<string>(
125 'cargo-watch.command',
130 if (config.has('cargo-watch.ignore')) {
131 this.cargoWatchOptions.ignore = config.get<string[]>(
132 'cargo-watch.ignore',
137 if (config.has('cargo-watch.allTargets')) {
138 this.cargoWatchOptions.allTargets = config.get<boolean>(
139 'cargo-watch.allTargets',
144 if (config.has('lruCapacity')) {
145 this.lruCapacity = config.get('lruCapacity') as number;
148 if (config.has('displayInlayHints')) {
149 this.displayInlayHints = config.get('displayInlayHints') as boolean;
151 if (config.has('maxInlayHintLength')) {
152 this.maxInlayHintLength = config.get(
153 'maxInlayHintLength',
156 if (config.has('excludeGlobs')) {
157 this.excludeGlobs = config.get('excludeGlobs') || [];
159 if (config.has('useClientWatching')) {
160 this.useClientWatching = config.get('useClientWatching') || true;
162 if (config.has('featureFlags')) {
163 this.featureFlags = config.get('featureFlags') || {};
165 if (config.has('withSysroot')) {
166 this.withSysroot = config.get('withSysroot') || false;
169 if (config.has('cargoFeatures.noDefaultFeatures')) {
170 this.cargoFeatures.noDefaultFeatures = config.get(
171 'cargoFeatures.noDefaultFeatures',
175 if (config.has('cargoFeatures.allFeatures')) {
176 this.cargoFeatures.allFeatures = config.get(
177 'cargoFeatures.allFeatures',
181 if (config.has('cargoFeatures.features')) {
182 this.cargoFeatures.features = config.get(
183 'cargoFeatures.features',
189 this.prevCargoFeatures !== null &&
190 (this.cargoFeatures.allFeatures !==
191 this.prevCargoFeatures.allFeatures ||
192 this.cargoFeatures.noDefaultFeatures !==
193 this.prevCargoFeatures.noDefaultFeatures ||
194 this.cargoFeatures.features.length !==
195 this.prevCargoFeatures.features.length ||
196 this.cargoFeatures.features.some(
197 (v, i) => v !== this.prevCargoFeatures!.features[i],
200 requireReloadMessage = 'Changing cargo features requires a reload';
202 this.prevCargoFeatures = { ...this.cargoFeatures };
204 if (requireReloadMessage !== null) {
205 const reloadAction = 'Reload now';
207 .showInformationMessage(requireReloadMessage, reloadAction)
208 .then(selectedAction => {
209 if (selectedAction === reloadAction) {
210 vscode.commands.executeCommand(
211 'workbench.action.reloadWindow',