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 maxInlayHintLength: null | number = null;
27 public excludeGlobs = [];
28 public useClientWatching = false;
29 public featureFlags = {};
30 public cargoWatchOptions: CargoWatchOptions = {
31 enableOnStartup: 'ask',
38 private prevEnhancedTyping: null | boolean = null;
41 vscode.workspace.onDidChangeConfiguration(_ =>
42 this.userConfigChanged()
44 this.userConfigChanged();
47 public userConfigChanged() {
48 const config = vscode.workspace.getConfiguration('rust-analyzer');
49 if (config.has('highlightingOn')) {
50 this.highlightingOn = config.get('highlightingOn') as boolean;
53 if (config.has('rainbowHighlightingOn')) {
54 this.rainbowHighlightingOn = config.get(
55 'rainbowHighlightingOn'
59 if (config.has('showWorkspaceLoadedNotification')) {
60 this.showWorkspaceLoadedNotification = config.get(
61 'showWorkspaceLoadedNotification'
65 if (!this.highlightingOn && Server) {
66 Server.highlighter.removeHighlights();
69 if (config.has('enableEnhancedTyping')) {
70 this.enableEnhancedTyping = config.get(
71 'enableEnhancedTyping'
74 if (this.prevEnhancedTyping === null) {
75 this.prevEnhancedTyping = this.enableEnhancedTyping;
77 } else if (this.prevEnhancedTyping === null) {
78 this.prevEnhancedTyping = this.enableEnhancedTyping;
81 if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
82 const reloadAction = 'Reload now';
84 .showInformationMessage(
85 'Changing enhanced typing setting requires a reload',
88 .then(selectedAction => {
89 if (selectedAction === reloadAction) {
90 vscode.commands.executeCommand(
91 'workbench.action.reloadWindow'
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('lruCapacity')) {
138 this.lruCapacity = config.get('lruCapacity') as number;
141 if (config.has('displayInlayHints')) {
142 this.displayInlayHints = config.get('displayInlayHints') as boolean;
144 if (config.has('maxInlayHintLength')) {
145 this.maxInlayHintLength = config.get(
149 if (config.has('excludeGlobs')) {
150 this.excludeGlobs = config.get('excludeGlobs') || [];
152 if (config.has('useClientWatching')) {
153 this.useClientWatching = config.get('useClientWatching') || false;
155 if (config.has('featureFlags')) {
156 this.featureFlags = config.get('featureFlags') || {};