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;
18 export interface CargoFeatures {
19 noDefaultFeatures: boolean;
25 public highlightingOn = true;
26 public rainbowHighlightingOn = false;
27 public enableEnhancedTyping = true;
28 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
29 public lruCapacity: null | number = null;
30 public displayInlayHints = true;
31 public maxInlayHintLength: null | number = null;
32 public excludeGlobs = [];
33 public useClientWatching = true;
34 public featureFlags = {};
36 public withSysroot: null | boolean = null;
37 public cargoWatchOptions: CargoWatchOptions = {
38 enableOnStartup: 'ask',
44 public cargoFeatures: CargoFeatures = {
45 noDefaultFeatures: false,
50 private prevEnhancedTyping: null | boolean = null;
51 private prevCargoFeatures: null | CargoFeatures = null;
54 vscode.workspace.onDidChangeConfiguration(_ =>
55 this.userConfigChanged(),
57 this.userConfigChanged();
60 public userConfigChanged() {
61 const config = vscode.workspace.getConfiguration('rust-analyzer');
62 let requireReloadMessage = null;
64 if (config.has('highlightingOn')) {
65 this.highlightingOn = config.get('highlightingOn') as boolean;
68 if (config.has('rainbowHighlightingOn')) {
69 this.rainbowHighlightingOn = config.get(
70 'rainbowHighlightingOn',
74 if (!this.highlightingOn && Server) {
75 Server.highlighter.removeHighlights();
78 if (config.has('enableEnhancedTyping')) {
79 this.enableEnhancedTyping = config.get(
80 'enableEnhancedTyping',
83 if (this.prevEnhancedTyping === null) {
84 this.prevEnhancedTyping = this.enableEnhancedTyping;
86 } else if (this.prevEnhancedTyping === null) {
87 this.prevEnhancedTyping = this.enableEnhancedTyping;
90 if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
91 requireReloadMessage =
92 'Changing enhanced typing setting requires a reload';
93 this.prevEnhancedTyping = this.enableEnhancedTyping;
96 if (config.has('raLspServerPath')) {
97 this.raLspServerPath =
98 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
101 if (config.has('enableCargoWatchOnStartup')) {
102 this.cargoWatchOptions.enableOnStartup = config.get<
103 CargoWatchStartupOptions
104 >('enableCargoWatchOnStartup', 'ask');
107 if (config.has('trace.cargo-watch')) {
108 this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
114 if (config.has('cargo-watch.arguments')) {
115 this.cargoWatchOptions.arguments = config.get<string>(
116 'cargo-watch.arguments',
121 if (config.has('cargo-watch.command')) {
122 this.cargoWatchOptions.command = config.get<string>(
123 'cargo-watch.command',
128 if (config.has('cargo-watch.ignore')) {
129 this.cargoWatchOptions.ignore = config.get<string[]>(
130 'cargo-watch.ignore',
135 if (config.has('lruCapacity')) {
136 this.lruCapacity = config.get('lruCapacity') as number;
139 if (config.has('displayInlayHints')) {
140 this.displayInlayHints = config.get('displayInlayHints') as boolean;
142 if (config.has('maxInlayHintLength')) {
143 this.maxInlayHintLength = config.get(
144 'maxInlayHintLength',
147 if (config.has('excludeGlobs')) {
148 this.excludeGlobs = config.get('excludeGlobs') || [];
150 if (config.has('useClientWatching')) {
151 this.useClientWatching = config.get('useClientWatching') || true;
153 if (config.has('featureFlags')) {
154 this.featureFlags = config.get('featureFlags') || {};
156 if (config.has('withSysroot')) {
157 this.withSysroot = config.get('withSysroot') || false;
160 if (config.has('cargoFeatures.noDefaultFeatures')) {
161 this.cargoFeatures.noDefaultFeatures = config.get(
162 'cargoFeatures.noDefaultFeatures',
166 if (config.has('cargoFeatures.allFeatures')) {
167 this.cargoFeatures.allFeatures = config.get(
168 'cargoFeatures.allFeatures',
172 if (config.has('cargoFeatures.features')) {
173 this.cargoFeatures.features = config.get(
174 'cargoFeatures.features',
180 this.prevCargoFeatures !== null &&
181 (this.cargoFeatures.allFeatures !==
182 this.prevCargoFeatures.allFeatures ||
183 this.cargoFeatures.noDefaultFeatures !==
184 this.prevCargoFeatures.noDefaultFeatures ||
185 this.cargoFeatures.features.length !==
186 this.prevCargoFeatures.features.length ||
187 this.cargoFeatures.features.some(
188 (v, i) => v !== this.prevCargoFeatures!.features[i],
191 requireReloadMessage = 'Changing cargo features requires a reload';
193 this.prevCargoFeatures = { ...this.cargoFeatures };
195 if (requireReloadMessage !== null) {
196 const reloadAction = 'Reload now';
198 .showInformationMessage(requireReloadMessage, reloadAction)
199 .then(selectedAction => {
200 if (selectedAction === reloadAction) {
201 vscode.commands.executeCommand(
202 'workbench.action.reloadWindow',