From 473a21c0e9684b19016fd7367b28cc0ff12e928d Mon Sep 17 00:00:00 2001 From: River Riddle Date: Mon, 28 Jun 2021 22:46:05 +0000 Subject: [PATCH] [vscode-mlir] Add support for restarting the server on setting/server changes This revision adds detection for changes to either the mlir-lsp-server binary or the setting, and prompts the user to restart the server. Whether the user gets prompted or not is a configurable setting in the extension, and this setting may updated based on the user response to the prompt. Differential Revision: https://reviews.llvm.org/D104501 --- mlir/utils/vscode/package-lock.json | 298 +++++++++++++++++++++++++++++++++ mlir/utils/vscode/package.json | 25 ++- mlir/utils/vscode/src/config.ts | 16 ++ mlir/utils/vscode/src/configWatcher.ts | 81 +++++++++ mlir/utils/vscode/src/extension.ts | 55 ++---- mlir/utils/vscode/src/mlirContext.ts | 62 +++++++ 6 files changed, 491 insertions(+), 46 deletions(-) create mode 100644 mlir/utils/vscode/src/config.ts create mode 100644 mlir/utils/vscode/src/configWatcher.ts create mode 100644 mlir/utils/vscode/src/mlirContext.ts diff --git a/mlir/utils/vscode/package-lock.json b/mlir/utils/vscode/package-lock.json index 0b6e134..00ede87 100644 --- a/mlir/utils/vscode/package-lock.json +++ b/mlir/utils/vscode/package-lock.json @@ -8,10 +8,12 @@ "name": "mlir", "version": "0.0.1", "dependencies": { + "chokidar": "3.5.2", "vscode-languageclient": "^5.2.1", "vscode-languageserver-types": "3.16.0" }, "devDependencies": { + "@types/chokidar": "2.1.3", "@types/mocha": "^5.2.0", "@types/node": "^8.0.0", "@types/vscode": "1.52.*", @@ -61,6 +63,16 @@ "node": ">= 6" } }, + "node_modules/@types/chokidar": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@types/chokidar/-/chokidar-2.1.3.tgz", + "integrity": "sha512-6qK3xoLLAhQVTucQGHTySwOVA1crHRXnJeLwqK6KIFkkKa2aoMFXh+WEi8PotxDtvN6MQJLyYN9ag9P6NLV81w==", + "deprecated": "This is a stub types definition. chokidar provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "chokidar": "*" + } + }, "node_modules/@types/mocha": { "version": "5.2.7", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", @@ -103,6 +115,18 @@ "node": ">=4" } }, + "node_modules/anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -156,6 +180,14 @@ "node": "*" } }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "engines": { + "node": ">=8" + } + }, "node_modules/bluebird": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", @@ -178,6 +210,17 @@ "concat-map": "0.0.1" } }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -296,6 +339,27 @@ "integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==", "dev": true }, + "node_modules/chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/clang-format": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.4.0.tgz", @@ -509,12 +573,36 @@ "pend": "~1.2.0" } }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/fstream": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", @@ -582,6 +670,17 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", @@ -692,6 +791,17 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/is-core-module": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", @@ -704,6 +814,33 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -841,6 +978,14 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/nth-check": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.0.0.tgz", @@ -944,6 +1089,17 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", "dev": true }, + "node_modules/picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -992,6 +1148,17 @@ "util-deprecate": "~1.0.1" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", @@ -1093,6 +1260,17 @@ "node": ">=8.17.0" } }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/traverse": { "version": "0.3.9", "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", @@ -1381,6 +1559,15 @@ "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", "dev": true }, + "@types/chokidar": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@types/chokidar/-/chokidar-2.1.3.tgz", + "integrity": "sha512-6qK3xoLLAhQVTucQGHTySwOVA1crHRXnJeLwqK6KIFkkKa2aoMFXh+WEi8PotxDtvN6MQJLyYN9ag9P6NLV81w==", + "dev": true, + "requires": { + "chokidar": "*" + } + }, "@types/mocha": { "version": "5.2.7", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", @@ -1417,6 +1604,15 @@ "color-convert": "^1.9.0" } }, + "anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1464,6 +1660,11 @@ "chainsaw": "~0.1.0" } }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" + }, "bluebird": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", @@ -1486,6 +1687,14 @@ "concat-map": "0.0.1" } }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "requires": { + "fill-range": "^7.0.1" + } + }, "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -1576,6 +1785,21 @@ "domutils": "^2.7.0" } }, + "chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "clang-format": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.4.0.tgz", @@ -1733,12 +1957,26 @@ "pend": "~1.2.0" } }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "requires": { + "to-regex-range": "^5.0.1" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "optional": true + }, "fstream": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", @@ -1793,6 +2031,14 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "requires": { + "is-glob": "^4.0.1" + } + }, "graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", @@ -1875,6 +2121,14 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "requires": { + "binary-extensions": "^2.0.0" + } + }, "is-core-module": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", @@ -1884,6 +2138,24 @@ "has": "^1.0.3" } }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -2002,6 +2274,11 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, "nth-check": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.0.0.tgz", @@ -2090,6 +2367,11 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", "dev": true }, + "picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==" + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -2129,6 +2411,14 @@ "util-deprecate": "~1.0.1" } }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "requires": { + "picomatch": "^2.2.1" + } + }, "resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", @@ -2209,6 +2499,14 @@ "rimraf": "^3.0.0" } }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + } + }, "traverse": { "version": "0.3.9", "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", diff --git a/mlir/utils/vscode/package.json b/mlir/utils/vscode/package.json index 6d68130..e580aaa 100644 --- a/mlir/utils/vscode/package.json +++ b/mlir/utils/vscode/package.json @@ -44,9 +44,30 @@ "scope": "resource", "type": "string", "description": "The file path of the mlir-lsp-server executable." + }, + "mlir.onSettingsChanged": { + "type": "string", + "default": "prompt", + "description": "Action taken when a setting change requires a server restart to take effect.", + "enum": [ + "prompt", + "restart", + "ignore" + ], + "enumDescriptions": [ + "Prompt the user for restarting the server", + "Automatically restart the server", + "Do nothing" + ] } } - } + }, + "commands": [ + { + "command": "mlir.restart", + "title": "mlir: Restart language server" + } + ] }, "scripts": { "vscode:prepublish": "tsc -p ./", @@ -56,6 +77,7 @@ "package": "vsce package" }, "devDependencies": { + "@types/chokidar": "2.1.3", "@types/mocha": "^5.2.0", "@types/node": "^8.0.0", "@types/vscode": "1.52.*", @@ -67,6 +89,7 @@ "vscode-test": "^1.3.0" }, "dependencies": { + "chokidar": "3.5.2", "vscode-languageclient": "^5.2.1", "vscode-languageserver-types": "3.16.0" } diff --git a/mlir/utils/vscode/src/config.ts b/mlir/utils/vscode/src/config.ts new file mode 100644 index 0000000..58f45cc --- /dev/null +++ b/mlir/utils/vscode/src/config.ts @@ -0,0 +1,16 @@ +import * as vscode from 'vscode'; + +/** + * Gets the config value `mlir.`. + */ +export function get(key: string): T { + return vscode.workspace.getConfiguration('mlir').get(key); +} + +/** + * Sets the config value `mlir.`. + */ +export function update(key: string, value: T, + target?: vscode.ConfigurationTarget) { + return vscode.workspace.getConfiguration('mlir').update(key, value, target); +} diff --git a/mlir/utils/vscode/src/configWatcher.ts b/mlir/utils/vscode/src/configWatcher.ts new file mode 100644 index 0000000..47d4500 --- /dev/null +++ b/mlir/utils/vscode/src/configWatcher.ts @@ -0,0 +1,81 @@ +import * as chokidar from 'chokidar'; +import * as path from 'path'; +import * as vscode from 'vscode'; + +import * as config from './config'; +import {MLIRContext} from './mlirContext'; + +/** + * Prompt the user to see if we should restart the server. + */ +async function promptRestart(settingName: string, promptMessage: string) { + switch (config.get(settingName)) { + case 'restart': + vscode.commands.executeCommand('mlir.restart'); + break; + case 'ignore': + break; + case 'prompt': + default: + switch (await vscode.window.showInformationMessage( + promptMessage, 'Yes', 'Yes, always', 'No, never')) { + case 'Yes': + vscode.commands.executeCommand('mlir.restart'); + break; + case 'Yes, always': + vscode.commands.executeCommand('mlir.restart'); + config.update(settingName, 'restart', + vscode.ConfigurationTarget.Global); + break; + case 'No, never': + config.update(settingName, 'ignore', + vscode.ConfigurationTarget.Global); + break; + default: + break; + } + break; + } +} + +/** + * Activate the watchers that track configuration changes which decide when to + * restart the server. + */ +export function activate(mlirContext: MLIRContext) { + // When a configuration change happens, check to see if we should restart the + // server. + mlirContext.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => { + const settings: string[] = [ 'server_path' ]; + for (const setting of settings) { + const expandedSetting = `mlir.${setting}`; + if (event.affectsConfiguration(expandedSetting)) { + promptRestart( + 'onSettingsChanged', + `setting '${ + expandedSetting}' has changed. Do you want to reload the server?`); + break; + } + } + })); + + // Track the server file in case it changes. We use `fs` here because the + // server may not be in a workspace directory. + const userDefinedServerPath = config.get('server_path'); + const serverPath = + path.resolve((userDefinedServerPath === '') ? 'mlir-lsp-server' + : userDefinedServerPath); + const fileWatcherConfig = { + disableGlobbing : true, + followSymlinks : true, + ignoreInitial : true, + }; + const fileWatcher = chokidar.watch(serverPath, fileWatcherConfig); + fileWatcher.on('all', (_event, _filename, _details) => { + promptRestart( + 'onSettingsChanged', + 'MLIR language server binary has changed. Do you want to reload the server?'); + }); + mlirContext.subscriptions.push( + new vscode.Disposable(() => { fileWatcher.close(); })); +} diff --git a/mlir/utils/vscode/src/extension.ts b/mlir/utils/vscode/src/extension.ts index db4904e..2220c50 100644 --- a/mlir/utils/vscode/src/extension.ts +++ b/mlir/utils/vscode/src/extension.ts @@ -1,56 +1,21 @@ import * as vscode from 'vscode'; -import * as vscodelc from 'vscode-languageclient'; -let client: vscodelc.LanguageClient; +import {MLIRContext} from './mlirContext'; /** * This method is called when the extension is activated. The extension is * activated the very first time a command is executed. */ export function activate(context: vscode.ExtensionContext) { - // Get the path of the mlir-lsp-server that is used to provide language - // functionality. - const config = vscode.workspace.getConfiguration('mlir'); - const userDefinedServerPath = config.get('server_path'); - const serverPath = (userDefinedServerPath === '') ? 'mlir-lsp-server' - : userDefinedServerPath; + const mlirContext = new MLIRContext(); + context.subscriptions.push(mlirContext); - // Configure the server options. - const serverOptions: vscodelc.ServerOptions = { - run : { - command : serverPath, - transport : vscodelc.TransportKind.stdio, - args : [] - }, - debug : { - command : serverPath, - transport : vscodelc.TransportKind.stdio, - args : [] - } - }; + // Initialize the commands of the extension. + context.subscriptions.push( + vscode.commands.registerCommand('mlir.restart', async () => { + mlirContext.dispose(); + await mlirContext.activate(); + })); - // Configure the client options. - const clientOptions: vscodelc.LanguageClientOptions = { - documentSelector : [ {scheme : 'file', language : 'mlir'} ], - synchronize : { - // Notify the server about file changes to *.mlir files contained in the - // workspace. - fileEvents : vscode.workspace.createFileSystemWatcher('**/*.mlir') - } - }; - - // Create the language client and start the client. - client = new vscodelc.LanguageClient('mlir-lsp', 'MLIR Language Client', - serverOptions, clientOptions); - client.start(); -} - -/** - * This method is called when the extension is deactivated. - */ -export function deactivate(): Thenable|undefined { - if (!client) { - return undefined; - } - return client.stop(); + mlirContext.activate(); } diff --git a/mlir/utils/vscode/src/mlirContext.ts b/mlir/utils/vscode/src/mlirContext.ts new file mode 100644 index 0000000..3b58218 --- /dev/null +++ b/mlir/utils/vscode/src/mlirContext.ts @@ -0,0 +1,62 @@ +import * as vscode from 'vscode'; +import * as vscodelc from 'vscode-languageclient'; + +import * as config from './config'; +import * as configWatcher from './configWatcher'; + +/** + * This class manages all of the MLIR extension state, + * including the language client. + */ +export class MLIRContext implements vscode.Disposable { + subscriptions: vscode.Disposable[] = []; + client!: vscodelc.LanguageClient; + + /** + * Activate the MLIR context, and start the language client. + */ + async activate() { + // Get the path of the mlir-lsp-server that is used to provide language + // functionality. + const userDefinedServerPath = config.get('server_path'); + const serverPath = (userDefinedServerPath === '') ? 'mlir-lsp-server' + : userDefinedServerPath; + + // Configure the server options. + const serverOptions: vscodelc.ServerOptions = { + run : { + command : serverPath, + transport : vscodelc.TransportKind.stdio, + args : [] + }, + debug : { + command : serverPath, + transport : vscodelc.TransportKind.stdio, + args : [] + } + }; + + // Configure the client options. + const clientOptions: vscodelc.LanguageClientOptions = { + documentSelector : [ {scheme : 'file', language : 'mlir'} ], + synchronize : { + // Notify the server about file changes to *.mlir files contained in the + // workspace. + fileEvents : vscode.workspace.createFileSystemWatcher('**/*.mlir') + } + }; + + // Create the language client and start the client. + this.client = new vscodelc.LanguageClient( + 'mlir-lsp', 'MLIR Language Client', serverOptions, clientOptions); + this.subscriptions.push(this.client.start()); + + // Watch for configuration changes. + configWatcher.activate(this); + } + + dispose() { + this.subscriptions.forEach((d) => { d.dispose(); }); + this.subscriptions = []; + } +} -- 2.7.4