2018-10-07 15:59:02 -05:00
|
|
|
import * as vscode from 'vscode';
|
2019-10-24 10:25:23 -05:00
|
|
|
import * as scopes from './scopes';
|
Introducing a Scopes Mapper to map from RA scopes to TextMate scopes with fallbacks.
Current scopes defined:
```
['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control']],
['function', ['entity.name.function']],
['parameter', ['variable.parameter']],
['type', ['entity.name.type']],
['builtin', ['variable.language', 'support.type', 'support.type']],
['text', ['string', 'string.quoted', 'string.regexp']],
['attribute', ['keyword']],
['literal', ['string', 'string.quoted', 'string.regexp']],
['macro', ['support.other']],
['variable.mut', ['variable']],
['field', ['variable.object.property']],
['module', ['entity.name.section']]
```
Need to complement with further fallbacks as some themes fail.
2019-10-27 11:57:11 -05:00
|
|
|
import * as scopesMapper from './scopes_mapper';
|
2019-06-24 05:33:37 -05:00
|
|
|
import { Server } from './server';
|
2018-10-07 15:59:02 -05:00
|
|
|
|
2019-01-18 04:59:08 -06:00
|
|
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
|
|
|
|
2019-04-02 00:07:40 -05:00
|
|
|
export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled';
|
|
|
|
export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
|
|
|
|
|
|
|
|
export interface CargoWatchOptions {
|
2019-04-02 01:43:02 -05:00
|
|
|
enableOnStartup: CargoWatchStartupOptions;
|
2019-06-24 05:35:11 -05:00
|
|
|
arguments: string;
|
|
|
|
command: string;
|
2019-04-02 01:43:02 -05:00
|
|
|
trace: CargoWatchTraceOptions;
|
2019-10-17 08:22:39 -05:00
|
|
|
ignore: string[];
|
2019-04-02 01:43:02 -05:00
|
|
|
}
|
2019-03-21 06:56:25 -05:00
|
|
|
|
2018-10-07 15:59:02 -05:00
|
|
|
export class Config {
|
2018-10-08 16:38:33 -05:00
|
|
|
public highlightingOn = true;
|
2019-05-27 04:26:15 -05:00
|
|
|
public rainbowHighlightingOn = false;
|
2019-02-07 04:37:36 -06:00
|
|
|
public enableEnhancedTyping = true;
|
2019-01-18 04:59:08 -06:00
|
|
|
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
2019-06-07 12:49:29 -05:00
|
|
|
public lruCapacity: null | number = null;
|
2019-07-23 08:38:21 -05:00
|
|
|
public displayInlayHints = true;
|
2019-10-18 06:40:03 -05:00
|
|
|
public maxInlayHintLength: null | number = null;
|
2019-08-06 06:34:28 -05:00
|
|
|
public excludeGlobs = [];
|
2019-09-06 08:25:24 -05:00
|
|
|
public useClientWatching = false;
|
2019-08-22 06:44:16 -05:00
|
|
|
public featureFlags = {};
|
2019-04-02 01:43:02 -05:00
|
|
|
public cargoWatchOptions: CargoWatchOptions = {
|
|
|
|
enableOnStartup: 'ask',
|
|
|
|
trace: 'off',
|
2019-06-24 05:50:34 -05:00
|
|
|
arguments: '',
|
2019-10-17 08:22:39 -05:00
|
|
|
command: '',
|
|
|
|
ignore: []
|
2019-04-02 01:43:02 -05:00
|
|
|
};
|
2018-10-07 15:59:02 -05:00
|
|
|
|
2019-02-07 04:37:36 -06:00
|
|
|
private prevEnhancedTyping: null | boolean = null;
|
|
|
|
|
2018-10-08 16:38:33 -05:00
|
|
|
constructor() {
|
|
|
|
vscode.workspace.onDidChangeConfiguration(_ =>
|
|
|
|
this.userConfigChanged()
|
|
|
|
);
|
|
|
|
this.userConfigChanged();
|
2018-10-08 16:36:47 -05:00
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
|
2018-10-08 16:38:33 -05:00
|
|
|
public userConfigChanged() {
|
2019-01-28 05:43:07 -06:00
|
|
|
const config = vscode.workspace.getConfiguration('rust-analyzer');
|
2019-10-24 10:25:23 -05:00
|
|
|
|
|
|
|
Server.highlighter.removeHighlights();
|
|
|
|
|
2019-11-04 16:59:11 -06:00
|
|
|
if (config.has('highlightingOn')) {
|
2018-10-08 16:38:33 -05:00
|
|
|
this.highlightingOn = config.get('highlightingOn') as boolean;
|
2019-11-04 16:59:11 -06:00
|
|
|
if (this.highlightingOn) {
|
|
|
|
scopes.load();
|
|
|
|
scopesMapper.load();
|
|
|
|
}
|
2018-10-08 16:38:33 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:26:15 -05:00
|
|
|
if (config.has('rainbowHighlightingOn')) {
|
|
|
|
this.rainbowHighlightingOn = config.get(
|
|
|
|
'rainbowHighlightingOn'
|
|
|
|
) as boolean;
|
|
|
|
}
|
|
|
|
|
2019-01-05 09:28:41 -06:00
|
|
|
|
2019-02-07 04:37:36 -06:00
|
|
|
if (config.has('enableEnhancedTyping')) {
|
2019-02-07 04:54:41 -06:00
|
|
|
this.enableEnhancedTyping = config.get(
|
|
|
|
'enableEnhancedTyping'
|
|
|
|
) as boolean;
|
2019-02-07 04:37:36 -06:00
|
|
|
|
|
|
|
if (this.prevEnhancedTyping === null) {
|
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
} else if (this.prevEnhancedTyping === null) {
|
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
|
|
|
|
const reloadAction = 'Reload now';
|
2019-02-07 04:54:41 -06:00
|
|
|
vscode.window
|
|
|
|
.showInformationMessage(
|
|
|
|
'Changing enhanced typing setting requires a reload',
|
|
|
|
reloadAction
|
|
|
|
)
|
2019-02-07 04:37:36 -06:00
|
|
|
.then(selectedAction => {
|
|
|
|
if (selectedAction === reloadAction) {
|
2019-02-07 04:54:41 -06:00
|
|
|
vscode.commands.executeCommand(
|
|
|
|
'workbench.action.reloadWindow'
|
|
|
|
);
|
2019-02-07 04:37:36 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
|
2019-01-05 09:28:41 -06:00
|
|
|
if (config.has('raLspServerPath')) {
|
2019-01-18 04:59:08 -06:00
|
|
|
this.raLspServerPath =
|
|
|
|
RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
|
2019-01-05 09:28:41 -06:00
|
|
|
}
|
2019-03-18 16:35:47 -05:00
|
|
|
|
|
|
|
if (config.has('enableCargoWatchOnStartup')) {
|
2019-04-02 01:43:02 -05:00
|
|
|
this.cargoWatchOptions.enableOnStartup = config.get<
|
|
|
|
CargoWatchStartupOptions
|
|
|
|
>('enableCargoWatchOnStartup', 'ask');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.has('trace.cargo-watch')) {
|
|
|
|
this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
|
|
|
|
'trace.cargo-watch',
|
|
|
|
'off'
|
|
|
|
);
|
|
|
|
}
|
2019-04-02 00:07:40 -05:00
|
|
|
|
2019-06-24 05:50:34 -05:00
|
|
|
if (config.has('cargo-watch.arguments')) {
|
|
|
|
this.cargoWatchOptions.arguments = config.get<string>(
|
|
|
|
'cargo-watch.arguments',
|
2019-04-02 01:43:02 -05:00
|
|
|
''
|
|
|
|
);
|
2019-03-18 16:35:47 -05:00
|
|
|
}
|
2019-06-24 05:02:20 -05:00
|
|
|
|
2019-06-24 05:50:34 -05:00
|
|
|
if (config.has('cargo-watch.command')) {
|
|
|
|
this.cargoWatchOptions.command = config.get<string>(
|
|
|
|
'cargo-watch.command',
|
2019-06-24 05:02:20 -05:00
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-17 08:22:39 -05:00
|
|
|
if (config.has('cargo-watch.ignore')) {
|
|
|
|
this.cargoWatchOptions.ignore = config.get<string[]>(
|
|
|
|
'cargo-watch.ignore',
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-07 12:49:29 -05:00
|
|
|
if (config.has('lruCapacity')) {
|
|
|
|
this.lruCapacity = config.get('lruCapacity') as number;
|
|
|
|
}
|
2019-07-23 08:38:21 -05:00
|
|
|
|
|
|
|
if (config.has('displayInlayHints')) {
|
|
|
|
this.displayInlayHints = config.get('displayInlayHints') as boolean;
|
|
|
|
}
|
2019-10-18 06:40:03 -05:00
|
|
|
if (config.has('maxInlayHintLength')) {
|
|
|
|
this.maxInlayHintLength = config.get(
|
|
|
|
'maxInlayHintLength'
|
|
|
|
) as number;
|
|
|
|
}
|
2019-08-06 06:34:28 -05:00
|
|
|
if (config.has('excludeGlobs')) {
|
|
|
|
this.excludeGlobs = config.get('excludeGlobs') || [];
|
|
|
|
}
|
2019-09-06 08:25:24 -05:00
|
|
|
if (config.has('useClientWatching')) {
|
|
|
|
this.useClientWatching = config.get('useClientWatching') || false;
|
|
|
|
}
|
2019-08-22 06:44:16 -05:00
|
|
|
if (config.has('featureFlags')) {
|
|
|
|
this.featureFlags = config.get('featureFlags') || {};
|
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
}
|