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 public highlightingOn = true;
20 public rainbowHighlightingOn = false;
21 public enableEnhancedTyping = true;
22 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
23 public showWorkspaceLoadedNotification = true;
24 public lruCapacity: null | number = null;
25 public displayInlayHints = true;
26 public excludeGlobs = [];
27 public useClientWatching = false;
28 public featureFlags = {};
29 public cargoWatchOptions: CargoWatchOptions = {
30 enableOnStartup: 'ask',
37 private prevEnhancedTyping: null | boolean = null;
40 vscode.workspace.onDidChangeConfiguration(_ =>
41 this.userConfigChanged()
43 this.userConfigChanged();
46 public userConfigChanged() {
47 const config = vscode.workspace.getConfiguration('rust-analyzer');
48 if (config.has('highlightingOn')) {
49 this.highlightingOn = config.get('highlightingOn') as boolean;
52 if (config.has('rainbowHighlightingOn')) {
53 this.rainbowHighlightingOn = config.get(
54 'rainbowHighlightingOn'
58 if (config.has('showWorkspaceLoadedNotification')) {
59 this.showWorkspaceLoadedNotification = config.get(
60 'showWorkspaceLoadedNotification'
64 if (!this.highlightingOn && Server) {
65 Server.highlighter.removeHighlights();
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 const reloadAction = 'Reload now';
83 .showInformationMessage(
84 'Changing enhanced typing setting requires a reload',
87 .then(selectedAction => {
88 if (selectedAction === reloadAction) {
89 vscode.commands.executeCommand(
90 'workbench.action.reloadWindow'
94 this.prevEnhancedTyping = this.enableEnhancedTyping;
97 if (config.has('raLspServerPath')) {
98 this.raLspServerPath =
99 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
102 if (config.has('enableCargoWatchOnStartup')) {
103 this.cargoWatchOptions.enableOnStartup = config.get<
104 CargoWatchStartupOptions
105 >('enableCargoWatchOnStartup', 'ask');
108 if (config.has('trace.cargo-watch')) {
109 this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
115 if (config.has('cargo-watch.arguments')) {
116 this.cargoWatchOptions.arguments = config.get<string>(
117 'cargo-watch.arguments',
122 if (config.has('cargo-watch.command')) {
123 this.cargoWatchOptions.command = config.get<string>(
124 'cargo-watch.command',
129 if (config.has('cargo-watch.ignore')) {
130 this.cargoWatchOptions.ignore = config.get<string[]>(
131 'cargo-watch.ignore',
136 if (config.has('lruCapacity')) {
137 this.lruCapacity = config.get('lruCapacity') as number;
140 if (config.has('displayInlayHints')) {
141 this.displayInlayHints = config.get('displayInlayHints') as boolean;
143 if (config.has('excludeGlobs')) {
144 this.excludeGlobs = config.get('excludeGlobs') || [];
146 if (config.has('useClientWatching')) {
147 this.useClientWatching = config.get('useClientWatching') || false;
149 if (config.has('featureFlags')) {
150 this.featureFlags = config.get('featureFlags') || {};