rust-analyzer/editors/code/src/config.ts

66 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-10-07 20:59:02 +00:00
import * as vscode from 'vscode';
import { Server } from './server';
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
2018-10-07 20:59:02 +00:00
export class Config {
2018-10-08 21:38:33 +00:00
public highlightingOn = true;
public enableEnhancedTyping = true;
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
2018-10-07 20:59:02 +00:00
private prevEnhancedTyping: null | boolean = null;
2018-10-08 21:38:33 +00:00
constructor() {
vscode.workspace.onDidChangeConfiguration(_ =>
this.userConfigChanged()
);
this.userConfigChanged();
2018-10-08 21:36:47 +00:00
}
2018-10-07 20:59:02 +00:00
2018-10-08 21:38:33 +00:00
public userConfigChanged() {
2019-01-28 11:43:07 +00:00
const config = vscode.workspace.getConfiguration('rust-analyzer');
2018-10-08 21:38:33 +00:00
if (config.has('highlightingOn')) {
this.highlightingOn = config.get('highlightingOn') as boolean;
}
if (!this.highlightingOn && Server) {
Server.highlighter.removeHighlights();
}
if (config.has('enableEnhancedTyping')) {
2019-02-07 10:54:41 +00:00
this.enableEnhancedTyping = config.get(
'enableEnhancedTyping'
) as boolean;
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 10:54:41 +00:00
vscode.window
.showInformationMessage(
'Changing enhanced typing setting requires a reload',
reloadAction
)
.then(selectedAction => {
if (selectedAction === reloadAction) {
2019-02-07 10:54:41 +00:00
vscode.commands.executeCommand(
'workbench.action.reloadWindow'
);
}
});
this.prevEnhancedTyping = this.enableEnhancedTyping;
}
if (config.has('raLspServerPath')) {
this.raLspServerPath =
RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
}
2018-10-07 20:59:02 +00:00
}
}