1 import * as chokidar from 'chokidar';
2 import * as vscode from 'vscode';
4 import * as config from './config';
5 import {MLIRContext} from './mlirContext';
8 * Prompt the user to see if we should restart the server.
10 async function promptRestart(settingName: string, promptMessage: string) {
11 switch (config.get<string>(settingName)) {
13 vscode.commands.executeCommand('mlir.restart');
19 switch (await vscode.window.showInformationMessage(
20 promptMessage, 'Yes', 'Yes, always', 'No, never')) {
22 vscode.commands.executeCommand('mlir.restart');
25 vscode.commands.executeCommand('mlir.restart');
26 config.update<string>(settingName, 'restart',
27 vscode.ConfigurationTarget.Global);
30 config.update<string>(settingName, 'ignore',
31 vscode.ConfigurationTarget.Global);
41 * Activate watchers that track configuration changes for the given workspace
42 * folder, or null if the workspace is top-level.
44 export async function activate(
45 mlirContext: MLIRContext, workspaceFolder: vscode.WorkspaceFolder,
46 serverSettings: string[], serverPaths: string[]) {
47 // When a configuration change happens, check to see if we should restart the
49 mlirContext.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => {
50 for (const serverSetting of serverSettings) {
51 const expandedSetting = `mlir.${serverSetting}`;
52 if (event.affectsConfiguration(expandedSetting, workspaceFolder)) {
56 expandedSetting}' has changed. Do you want to reload the server?`);
61 // Setup watchers for the provided server paths.
62 const fileWatcherConfig = {
63 disableGlobbing : true,
64 followSymlinks : true,
66 awaitWriteFinish : true,
68 for (const serverPath of serverPaths) {
69 if (serverPath === '') {
73 // If the server path actually exists, track it in case it changes.
74 const fileWatcher = chokidar.watch(serverPath, fileWatcherConfig);
75 fileWatcher.on('all', (event, _filename, _details) => {
76 if (event != 'unlink') {
79 'MLIR language server file has changed. Do you want to reload the server?');
82 mlirContext.subscriptions.push(
83 new vscode.Disposable(() => { fileWatcher.close(); }));