]> git.lizzy.rs Git - rust.git/blob - editors/code/src/config.ts
Adds config option for cargo-watch `--ignore` flag
[rust.git] / editors / code / src / config.ts
1 import * as vscode from 'vscode';
2
3 import { Server } from './server';
4
5 const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
6
7 export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled';
8 export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
9
10 export interface CargoWatchOptions {
11     enableOnStartup: CargoWatchStartupOptions;
12     arguments: string;
13     command: string;
14     trace: CargoWatchTraceOptions;
15     ignore: string[];
16 }
17
18 export class Config {
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',
31         trace: 'off',
32         arguments: '',
33         command: '',
34         ignore: []
35     };
36
37     private prevEnhancedTyping: null | boolean = null;
38
39     constructor() {
40         vscode.workspace.onDidChangeConfiguration(_ =>
41             this.userConfigChanged()
42         );
43         this.userConfigChanged();
44     }
45
46     public userConfigChanged() {
47         const config = vscode.workspace.getConfiguration('rust-analyzer');
48         if (config.has('highlightingOn')) {
49             this.highlightingOn = config.get('highlightingOn') as boolean;
50         }
51
52         if (config.has('rainbowHighlightingOn')) {
53             this.rainbowHighlightingOn = config.get(
54                 'rainbowHighlightingOn'
55             ) as boolean;
56         }
57
58         if (config.has('showWorkspaceLoadedNotification')) {
59             this.showWorkspaceLoadedNotification = config.get(
60                 'showWorkspaceLoadedNotification'
61             ) as boolean;
62         }
63
64         if (!this.highlightingOn && Server) {
65             Server.highlighter.removeHighlights();
66         }
67
68         if (config.has('enableEnhancedTyping')) {
69             this.enableEnhancedTyping = config.get(
70                 'enableEnhancedTyping'
71             ) as boolean;
72
73             if (this.prevEnhancedTyping === null) {
74                 this.prevEnhancedTyping = this.enableEnhancedTyping;
75             }
76         } else if (this.prevEnhancedTyping === null) {
77             this.prevEnhancedTyping = this.enableEnhancedTyping;
78         }
79
80         if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
81             const reloadAction = 'Reload now';
82             vscode.window
83                 .showInformationMessage(
84                     'Changing enhanced typing setting requires a reload',
85                     reloadAction
86                 )
87                 .then(selectedAction => {
88                     if (selectedAction === reloadAction) {
89                         vscode.commands.executeCommand(
90                             'workbench.action.reloadWindow'
91                         );
92                     }
93                 });
94             this.prevEnhancedTyping = this.enableEnhancedTyping;
95         }
96
97         if (config.has('raLspServerPath')) {
98             this.raLspServerPath =
99                 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
100         }
101
102         if (config.has('enableCargoWatchOnStartup')) {
103             this.cargoWatchOptions.enableOnStartup = config.get<
104                 CargoWatchStartupOptions
105             >('enableCargoWatchOnStartup', 'ask');
106         }
107
108         if (config.has('trace.cargo-watch')) {
109             this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
110                 'trace.cargo-watch',
111                 'off'
112             );
113         }
114
115         if (config.has('cargo-watch.arguments')) {
116             this.cargoWatchOptions.arguments = config.get<string>(
117                 'cargo-watch.arguments',
118                 ''
119             );
120         }
121
122         if (config.has('cargo-watch.command')) {
123             this.cargoWatchOptions.command = config.get<string>(
124                 'cargo-watch.command',
125                 ''
126             );
127         }
128
129         if (config.has('cargo-watch.ignore')) {
130             this.cargoWatchOptions.ignore = config.get<string[]>(
131                 'cargo-watch.ignore',
132                 []
133             );
134         }
135
136         if (config.has('lruCapacity')) {
137             this.lruCapacity = config.get('lruCapacity') as number;
138         }
139
140         if (config.has('displayInlayHints')) {
141             this.displayInlayHints = config.get('displayInlayHints') as boolean;
142         }
143         if (config.has('excludeGlobs')) {
144             this.excludeGlobs = config.get('excludeGlobs') || [];
145         }
146         if (config.has('useClientWatching')) {
147             this.useClientWatching = config.get('useClientWatching') || false;
148         }
149         if (config.has('featureFlags')) {
150             this.featureFlags = config.get('featureFlags') || {};
151         }
152     }
153 }