1 import * as vscode from 'vscode';
3 const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
5 export interface CargoWatchOptions {
12 export interface CargoFeatures {
13 noDefaultFeatures: boolean;
19 public highlightingOn = true;
20 public rainbowHighlightingOn = false;
21 public enableEnhancedTyping = true;
22 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
23 public lruCapacity: null | number = null;
24 public displayInlayHints = true;
25 public maxInlayHintLength: null | number = null;
26 public excludeGlobs = [];
27 public useClientWatching = true;
28 public featureFlags = {};
30 public withSysroot: null | boolean = null;
31 public cargoWatchOptions: CargoWatchOptions = {
37 public cargoFeatures: CargoFeatures = {
38 noDefaultFeatures: false,
43 private prevEnhancedTyping: null | boolean = null;
44 private prevCargoFeatures: null | CargoFeatures = null;
47 vscode.workspace.onDidChangeConfiguration(_ =>
48 this.userConfigChanged(),
50 this.userConfigChanged();
53 public userConfigChanged() {
54 const config = vscode.workspace.getConfiguration('rust-analyzer');
56 let requireReloadMessage = null;
58 if (config.has('highlightingOn')) {
59 this.highlightingOn = config.get('highlightingOn') as boolean;
62 if (config.has('rainbowHighlightingOn')) {
63 this.rainbowHighlightingOn = config.get(
64 'rainbowHighlightingOn',
68 if (config.has('enableEnhancedTyping')) {
69 this.enableEnhancedTyping = config.get(
70 'enableEnhancedTyping',
73 if (this.prevEnhancedTyping === null) {
74 this.prevEnhancedTyping = this.enableEnhancedTyping;
76 } else if (this.prevEnhancedTyping === null) {
77 this.prevEnhancedTyping = this.enableEnhancedTyping;
80 if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
81 requireReloadMessage =
82 'Changing enhanced typing setting requires a reload';
83 this.prevEnhancedTyping = this.enableEnhancedTyping;
86 if (config.has('raLspServerPath')) {
87 this.raLspServerPath =
88 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
91 if (config.has('cargo-watch.enable')) {
92 this.cargoWatchOptions.enable = config.get<boolean>(
98 if (config.has('cargo-watch.arguments')) {
99 this.cargoWatchOptions.arguments = config.get<string[]>(
100 'cargo-watch.arguments',
105 if (config.has('cargo-watch.command')) {
106 this.cargoWatchOptions.command = config.get<string>(
107 'cargo-watch.command',
112 if (config.has('cargo-watch.allTargets')) {
113 this.cargoWatchOptions.allTargets = config.get<boolean>(
114 'cargo-watch.allTargets',
119 if (config.has('lruCapacity')) {
120 this.lruCapacity = config.get('lruCapacity') as number;
123 if (config.has('displayInlayHints')) {
124 this.displayInlayHints = config.get('displayInlayHints') as boolean;
126 if (config.has('maxInlayHintLength')) {
127 this.maxInlayHintLength = config.get(
128 'maxInlayHintLength',
131 if (config.has('excludeGlobs')) {
132 this.excludeGlobs = config.get('excludeGlobs') || [];
134 if (config.has('useClientWatching')) {
135 this.useClientWatching = config.get('useClientWatching') || true;
137 if (config.has('featureFlags')) {
138 this.featureFlags = config.get('featureFlags') || {};
140 if (config.has('withSysroot')) {
141 this.withSysroot = config.get('withSysroot') || false;
144 if (config.has('cargoFeatures.noDefaultFeatures')) {
145 this.cargoFeatures.noDefaultFeatures = config.get(
146 'cargoFeatures.noDefaultFeatures',
150 if (config.has('cargoFeatures.allFeatures')) {
151 this.cargoFeatures.allFeatures = config.get(
152 'cargoFeatures.allFeatures',
156 if (config.has('cargoFeatures.features')) {
157 this.cargoFeatures.features = config.get(
158 'cargoFeatures.features',
164 this.prevCargoFeatures !== null &&
165 (this.cargoFeatures.allFeatures !==
166 this.prevCargoFeatures.allFeatures ||
167 this.cargoFeatures.noDefaultFeatures !==
168 this.prevCargoFeatures.noDefaultFeatures ||
169 this.cargoFeatures.features.length !==
170 this.prevCargoFeatures.features.length ||
171 this.cargoFeatures.features.some(
172 (v, i) => v !== this.prevCargoFeatures!.features[i],
175 requireReloadMessage = 'Changing cargo features requires a reload';
177 this.prevCargoFeatures = { ...this.cargoFeatures };
179 if (requireReloadMessage !== null) {
180 const reloadAction = 'Reload now';
182 .showInformationMessage(requireReloadMessage, reloadAction)
183 .then(selectedAction => {
184 if (selectedAction === reloadAction) {
185 vscode.commands.executeCommand(
186 'workbench.action.reloadWindow',