From 6e89af1e28ba4d95bb47d4a4a7863161efff2a88 Mon Sep 17 00:00:00 2001 From: l3ops Date: Mon, 14 Nov 2022 11:00:49 +0100 Subject: [PATCH 1/2] feat(vscode): try to resolve the rome package from the workspace root --- editors/vscode/package-lock.json | 139 ++++++++++++++++++++++--------- editors/vscode/package.json | 8 +- editors/vscode/src/main.ts | 122 +++++++++++++++++++++------ 3 files changed, 201 insertions(+), 68 deletions(-) diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index 8176c5713f8..c94280cf87f 100644 --- a/editors/vscode/package-lock.json +++ b/editors/vscode/package-lock.json @@ -8,13 +8,17 @@ "name": "rome", "version": "0.18.1", "license": "MIT", + "dependencies": { + "resolve": "^1.22.1", + "vscode-languageclient": "^8.0.2" + }, "devDependencies": { "@types/node": "^18.0.0", + "@types/resolve": "^1.20.2", "@types/vscode": "^1.70.0", "esbuild": "^0.14.47", "typescript": "^4.8.2", - "vsce": "^2.11.0", - "vscode-languageclient": "^8.0.2" + "vsce": "^2.11.0" }, "engines": { "npm": "^8", @@ -27,6 +31,12 @@ "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==", "dev": true }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true + }, "node_modules/@types/vscode": { "version": "1.70.0", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.70.0.tgz", @@ -89,8 +99,7 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/base64-js": { "version": "1.5.1", @@ -147,7 +156,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -292,8 +300,7 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "node_modules/console-control-strings": { "version": "1.1.0", @@ -844,8 +851,7 @@ "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "node_modules/gauge": { "version": "2.7.4", @@ -907,7 +913,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, "dependencies": { "function-bind": "^1.1.1" }, @@ -1015,6 +1020,17 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, + "node_modules/is-core-module": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz", + "integrity": "sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==", + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -1066,7 +1082,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -1133,7 +1148,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -1291,6 +1305,11 @@ "node": ">=0.10.0" } }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -1397,6 +1416,22 @@ "util-deprecate": "~1.0.1" } }, + "node_modules/resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dependencies": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -1560,6 +1595,17 @@ "node": ">=4" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/tar-fs": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", @@ -1727,7 +1773,6 @@ "version": "8.0.2", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2.tgz", "integrity": "sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ==", - "dev": true, "engines": { "node": ">=14.0.0" } @@ -1736,7 +1781,6 @@ "version": "8.0.2", "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2.tgz", "integrity": "sha512-lHlthJtphG9gibGb/y72CKqQUxwPsMXijJVpHEC2bvbFqxmkj9LwQ3aGU9dwjBLqsX1S4KjShYppLvg1UJDF/Q==", - "dev": true, "dependencies": { "minimatch": "^3.0.4", "semver": "^7.3.5", @@ -1750,7 +1794,6 @@ "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, "dependencies": { "lru-cache": "^6.0.0" }, @@ -1765,7 +1808,6 @@ "version": "3.17.2", "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.2.tgz", "integrity": "sha512-8kYisQ3z/SQ2kyjlNeQxbkkTNmVFoQCqkmGrzLH6A9ecPlgTbp3wDTnUNqaUxYr4vlAcloxx8zwy7G5WdguYNg==", - "dev": true, "dependencies": { "vscode-jsonrpc": "8.0.2", "vscode-languageserver-types": "3.17.2" @@ -1774,8 +1816,7 @@ "node_modules/vscode-languageserver-types": { "version": "3.17.2", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz", - "integrity": "sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==", - "dev": true + "integrity": "sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==" }, "node_modules/wide-align": { "version": "1.1.5", @@ -1817,8 +1858,7 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yauzl": { "version": "2.10.0", @@ -1847,6 +1887,12 @@ "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==", "dev": true }, + "@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true + }, "@types/vscode": { "version": "1.70.0", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.70.0.tgz", @@ -1903,8 +1949,7 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "base64-js": { "version": "1.5.1", @@ -1946,7 +1991,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2053,8 +2097,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "console-control-strings": { "version": "1.1.0", @@ -2370,8 +2413,7 @@ "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "gauge": { "version": "2.7.4", @@ -2424,7 +2466,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, "requires": { "function-bind": "^1.1.1" } @@ -2496,6 +2537,14 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, + "is-core-module": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz", + "integrity": "sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==", + "requires": { + "has": "^1.0.3" + } + }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -2540,7 +2589,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -2588,7 +2636,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2721,6 +2768,11 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -2809,6 +2861,16 @@ "util-deprecate": "~1.0.1" } }, + "resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "requires": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -2920,6 +2982,11 @@ "has-flag": "^3.0.0" } }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" + }, "tar-fs": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", @@ -3060,14 +3127,12 @@ "vscode-jsonrpc": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2.tgz", - "integrity": "sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ==", - "dev": true + "integrity": "sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ==" }, "vscode-languageclient": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2.tgz", "integrity": "sha512-lHlthJtphG9gibGb/y72CKqQUxwPsMXijJVpHEC2bvbFqxmkj9LwQ3aGU9dwjBLqsX1S4KjShYppLvg1UJDF/Q==", - "dev": true, "requires": { "minimatch": "^3.0.4", "semver": "^7.3.5", @@ -3078,7 +3143,6 @@ "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, "requires": { "lru-cache": "^6.0.0" } @@ -3089,7 +3153,6 @@ "version": "3.17.2", "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.2.tgz", "integrity": "sha512-8kYisQ3z/SQ2kyjlNeQxbkkTNmVFoQCqkmGrzLH6A9ecPlgTbp3wDTnUNqaUxYr4vlAcloxx8zwy7G5WdguYNg==", - "dev": true, "requires": { "vscode-jsonrpc": "8.0.2", "vscode-languageserver-types": "3.17.2" @@ -3098,8 +3161,7 @@ "vscode-languageserver-types": { "version": "3.17.2", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz", - "integrity": "sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==", - "dev": true + "integrity": "sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==" }, "wide-align": { "version": "1.1.5", @@ -3135,8 +3197,7 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yauzl": { "version": "2.10.0", diff --git a/editors/vscode/package.json b/editors/vscode/package.json index da010ee8e9f..98a5eb006ae 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -128,10 +128,14 @@ }, "devDependencies": { "@types/node": "^18.0.0", + "@types/resolve": "^1.20.2", "@types/vscode": "^1.70.0", - "typescript": "^4.8.2", - "vsce": "^2.11.0", "esbuild": "^0.14.47", + "typescript": "^4.8.2", + "vsce": "^2.11.0" + }, + "dependencies": { + "resolve": "^1.22.1", "vscode-languageclient": "^8.0.2" } } \ No newline at end of file diff --git a/editors/vscode/src/main.ts b/editors/vscode/src/main.ts index a94fc98f955..9b637941aaf 100644 --- a/editors/vscode/src/main.ts +++ b/editors/vscode/src/main.ts @@ -1,5 +1,6 @@ import { spawn } from "child_process"; import { connect } from "net"; +import { promisify } from "util"; import { ExtensionContext, languages, @@ -15,27 +16,26 @@ import { ServerOptions, StreamInfo, } from "vscode-languageclient/node"; -import { isAbsolute, join } from "path"; -import { existsSync } from "fs"; +import { isAbsolute } from "path"; import { setContextValue } from "./utils"; import { Session } from "./session"; import { syntaxTree } from "./commands/syntaxTree"; import { Commands } from "./commands"; import { StatusBar } from "./statusBar"; +import resolveImpl = require("resolve/async"); +import type * as Resolve from "resolve"; + +const resolveAsync = promisify( + resolveImpl, +); + let client: LanguageClient; const IN_ROME_PROJECT = "inRomeProject"; export async function activate(context: ExtensionContext) { - const command = - process.env.DEBUG_SERVER_PATH || (await getServerPath(context)); - - if (process.env.DEBUG_SERVER_PATH) { - window.showInformationMessage( - `Rome DEBUG_SERVER_PATH detected: ${command}`, - ); - } + const command = await getServerPath(context); if (!command) { await window.showErrorMessage( @@ -115,40 +115,108 @@ type Architecture = "x64" | "arm64"; type PlatformTriplets = { [P in NodeJS.Platform]?: { - [A in Architecture]: string; + [A in Architecture]: { + triplet: string; + package: string; + }; }; }; -const PLATFORM_TRIPLETS: PlatformTriplets = { - win32: { x64: "x86_64-pc-windows-msvc", arm64: "aarch64-pc-windows-msvc" }, - darwin: { x64: "x86_64-apple-darwin", arm64: "aarch64-apple-darwin" }, +const PLATFORMS: PlatformTriplets = { + win32: { + x64: { + triplet: "x86_64-pc-windows-msvc", + package: "@rometools/cli-win32-x64/rome.exe", + }, + arm64: { + triplet: "aarch64-pc-windows-msvc", + package: "@rometools/cli-win32-arm64/rome.exe", + }, + }, + darwin: { + x64: { + triplet: "x86_64-apple-darwin", + package: "@rometools/cli-darwin-x64/rome", + }, + arm64: { + triplet: "aarch64-apple-darwin", + package: "@rometools/cli-darwin-arm64/rome", + }, + }, linux: { - x64: "x86_64-unknown-linux-gnu", - arm64: "aarch64-unknown-linux-gnu", + x64: { + triplet: "x86_64-unknown-linux-gnu", + package: "@rometools/cli-linux-x64/rome", + }, + arm64: { + triplet: "aarch64-unknown-linux-gnu", + package: "@rometools/cli-linux-arm64/rome", + }, }, }; async function getServerPath( context: ExtensionContext, ): Promise { + // Only allow the bundled Rome binary in untrusted workspaces + if (!workspace.isTrusted) { + return getBundledBinary(context); + } + + if (process.env.DEBUG_SERVER_PATH) { + window.showInformationMessage( + `Rome DEBUG_SERVER_PATH detected: ${process.env.DEBUG_SERVER_PATH}`, + ); + return process.env.DEBUG_SERVER_PATH; + } + const config = workspace.getConfiguration(); const explicitPath = config.get("rome.lspBin"); if (typeof explicitPath === "string" && explicitPath !== "") { - if (isAbsolute(explicitPath)) { - return explicitPath; - } else { - for (let i = 0; i < workspace.workspaceFolders.length; i++) { - const workspaceFolder = workspace.workspaceFolders[i]; - const possiblePath = join(workspaceFolder.uri.path, explicitPath); - if (existsSync(possiblePath)) { - return possiblePath; - } + return getWorkspaceRelativePath(explicitPath); + } + + return (await getWorkspaceDependency()) ?? getBundledBinary(context); +} + +// Resolve `path` as relative to the workspace root +async function getWorkspaceRelativePath(path: string) { + if (isAbsolute(path)) { + return path; + } else { + for (let i = 0; i < workspace.workspaceFolders.length; i++) { + const workspaceFolder = workspace.workspaceFolders[i]; + const possiblePath = Uri.joinPath(workspaceFolder.uri, path); + if (await fileExists(possiblePath)) { + return possiblePath.fsPath; } - return undefined; } + return undefined; } +} + +// Tries to resolve a path to `@rometools/cli-*` binary package from the root of the workspace +async function getWorkspaceDependency(): Promise { + const packageName = PLATFORMS[process.platform]?.[process.arch]?.package; + + for (const workspaceFolder of workspace.workspaceFolders) { + try { + const result = await resolveAsync(packageName, { + basedir: workspaceFolder.uri.fsPath, + }); + + if (result) { + return result; + } + } catch {} + } + + return undefined; +} - const triplet = PLATFORM_TRIPLETS[process.platform]?.[process.arch]; +// Returns the path of the binary distribution of Rome included in the bundle of the extension +async function getBundledBinary(context: ExtensionContext) { + const triplet = PLATFORMS[process.platform]?.[process.arch]?.triplet; if (!triplet) { return undefined; } From 7870a8788f86d1fb79dcc29edc4f0407e2c470d4 Mon Sep 17 00:00:00 2001 From: l3ops Date: Mon, 14 Nov 2022 14:38:33 +0100 Subject: [PATCH 2/2] update the extension readme --- editors/vscode/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/editors/vscode/README.md b/editors/vscode/README.md index 95bea307c5d..182896015b6 100644 --- a/editors/vscode/README.md +++ b/editors/vscode/README.md @@ -46,11 +46,11 @@ The extension automatically loads the `rome.json` file from the workspace’s ro ## Rome Resolution -The extension uses the Rome version shipped with the extension. We plan to automatically detect the Rome version from the project in an upcoming release. +The extension tries to use Rome from your project's local dependencies (`node_modules/rome`). We recommend adding Rome as a project dependency to ensure that NPM scripts and the extension use the same Rome version. - +If the project has no dependency on Rome and no explicit path is configured, the extension uses the Rome version included in its bundle. ## Usage