2018-10-07 15:59:02 -05:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
import { Server } from './server';
|
|
|
|
|
2019-01-18 04:59:08 -06:00
|
|
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
|
|
|
|
2018-10-07 15:59:02 -05:00
|
|
|
export class Config {
|
2018-10-08 16:38:33 -05:00
|
|
|
public highlightingOn = true;
|
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-03-06 03:34:38 -06:00
|
|
|
public showWorkspaceLoadedNotification = true;
|
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');
|
2018-10-08 16:38:33 -05:00
|
|
|
if (config.has('highlightingOn')) {
|
|
|
|
this.highlightingOn = config.get('highlightingOn') as boolean;
|
|
|
|
}
|
|
|
|
|
2019-03-06 03:34:38 -06:00
|
|
|
if (config.has('showWorkspaceLoadedNotification')) {
|
|
|
|
this.showWorkspaceLoadedNotification = config.get(
|
|
|
|
'showWorkspaceLoadedNotification'
|
|
|
|
) as boolean;
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:38:33 -05:00
|
|
|
if (!this.highlightingOn && Server) {
|
|
|
|
Server.highlighter.removeHighlights();
|
|
|
|
}
|
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
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
}
|