Update WASM LSP example (#1030)

This commit is contained in:
Dirk Bäumer
2024-05-22 16:38:11 +02:00
committed by GitHub
parent a79d6117b5
commit fe3e3a3f95
11 changed files with 284 additions and 170 deletions

View File

@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
const esbuild = require('esbuild');
/**
* @typedef {import('esbuild').BuildOptions} BuildOptions
*/
/** @type BuildOptions */
const sharedWebOptions = {
bundle: true,
external: ['vscode'],
target: 'es2020',
platform: 'browser',
sourcemap: true,
};
/** @type BuildOptions */
const webOptions = {
entryPoints: ['client/src/extension.ts'],
outfile: 'client/dist/web/extension.js',
format: 'cjs',
...sharedWebOptions,
};
/** @type BuildOptions */
const sharedDesktopOptions = {
bundle: true,
external: ['vscode'],
target: 'es2020',
platform: 'node',
sourcemap: true,
};
/** @type BuildOptions */
const desktopOptions = {
entryPoints: ['client/src/extension.ts'],
outfile: 'client/dist/desktop/extension.js',
format: 'cjs',
...sharedDesktopOptions,
};
function createContexts() {
return Promise.all([
esbuild.context(webOptions),
esbuild.context(desktopOptions),
]);
}
createContexts().then(contexts => {
if (process.argv[2] === '--watch') {
const promises = [];
for (const context of contexts) {
promises.push(context.watch());
}
return Promise.all(promises).then(() => { return undefined; });
} else {
const promises = [];
for (const context of contexts) {
promises.push(context.rebuild());
}
Promise.all(promises).then(async () => {
for (const context of contexts) {
await context.dispose();
}
}).then(() => { return undefined; }).catch(console.error);
}
}).catch(console.error);

View File

@ -9,14 +9,14 @@
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"@vscode/wasm-wasi-lsp": "0.1.0-pre.3"
"@vscode/wasm-wasi-lsp": "0.1.0-pre.6"
},
"devDependencies": {
"@types/node": "^18.14.6",
"@types/vscode": "1.88.0"
"@types/vscode": "1.89.0"
},
"engines": {
"vscode": "^1.88.0"
"vscode": "^1.89.0"
}
},
"node_modules/@types/node": {
@ -29,9 +29,9 @@
}
},
"node_modules/@types/vscode": {
"version": "1.88.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.88.0.tgz",
"integrity": "sha512-rWY+Bs6j/f1lvr8jqZTyp5arRMfovdxolcqGi+//+cPDOh8SBvzXH90e7BiSXct5HJ9HGW6jATchbRTpTJpEkw==",
"version": "1.89.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.89.0.tgz",
"integrity": "sha512-TMfGKLSVxfGfoO8JfIE/neZqv7QLwS4nwPwL/NwMvxtAY2230H2I4Z5xx6836pmJvMAzqooRQ4pmLm7RUicP3A==",
"dev": true
},
"node_modules/@vscode/wasm-wasi": {
@ -52,15 +52,15 @@
}
},
"node_modules/@vscode/wasm-wasi-lsp": {
"version": "0.1.0-pre.3",
"resolved": "https://registry.npmjs.org/@vscode/wasm-wasi-lsp/-/wasm-wasi-lsp-0.1.0-pre.3.tgz",
"integrity": "sha512-3qgroKPvPKNcXd8Nl7DQINqSQtAoQ/6dix/X3b2fgdgJyBkISz/gNK5HfLBBC06lFCZlwP5gpaj1nx64No2y3A==",
"version": "0.1.0-pre.6",
"resolved": "https://registry.npmjs.org/@vscode/wasm-wasi-lsp/-/wasm-wasi-lsp-0.1.0-pre.6.tgz",
"integrity": "sha512-xaxk/NMRSYeRV7V9EG7p82RJM0YvnX5doXz43mQkc2EXOHNw9F3X6uVvoLn6cQLVoqDpv7ZaDD7Ab+lY4YhYCA==",
"engines": {
"node": ">=18.18.2"
},
"peerDependencies": {
"@vscode/wasm-wasi": "0.13.0-pre.1",
"vscode-languageclient": "10.0.0-next.5"
"vscode-languageclient": "10.0.0-next.7"
}
},
"node_modules/ansi-regex": {
@ -251,42 +251,42 @@
"dev": true
},
"node_modules/vscode-jsonrpc": {
"version": "9.0.0-next.2",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-9.0.0-next.2.tgz",
"integrity": "sha512-meIaXAgChCHzWy45QGU8YpCNyqnZQ/sYeCj32OLDDbUYsCF7AvgpdXx3nnZn9yzr8ed0Od9bW+NGphEmXsqvIQ==",
"version": "9.0.0-next.3",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-9.0.0-next.3.tgz",
"integrity": "sha512-Y4msarirF0JA0cH0OnAlqI+jZyPV6E0yTTviQRPH3IrxDv/K01EkM4gmsWS0Fx8wPqvW1GM+Gc/GWZvfoXFurQ==",
"peer": true,
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/vscode-languageclient": {
"version": "10.0.0-next.5",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-10.0.0-next.5.tgz",
"integrity": "sha512-JIf1WE7fvV0RElFM062bAummI433vcxuFwqoYAp+1zTVhta/jznxkTz1zs3Hbj2tiDfclf0TZ0qCxflAP1mY2Q==",
"version": "10.0.0-next.7",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-10.0.0-next.7.tgz",
"integrity": "sha512-LrvbEOidykOP9h0JsZZC13vE/Sj6guR5NHUqq07//nj5JjRgzhJSahY7fzDaN/c/iDWrSPawWGLkGoBYMR6qCQ==",
"peer": true,
"dependencies": {
"minimatch": "^9.0.3",
"semver": "^7.6.0",
"vscode-languageserver-protocol": "3.17.6-next.4"
"vscode-languageserver-protocol": "3.17.6-next.5"
},
"engines": {
"vscode": "^1.86.0"
"vscode": "^1.89.0"
}
},
"node_modules/vscode-languageserver-protocol": {
"version": "3.17.6-next.4",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.6-next.4.tgz",
"integrity": "sha512-/2bleKBxZLyRObS4mkpaWlVI9xGiUqMVmh/ztZ2vL4uP2XyIpraT45JBpn9AtXr0alqKJPKLuKr+/qcYULvm/w==",
"version": "3.17.6-next.5",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.6-next.5.tgz",
"integrity": "sha512-akUqjTI6FKOXBDu/rmFOaxez3BghZjexfqc7dEmVWlb1gCacnK/YVyqFjs7E0Abhyfj0TVPe4pInPY84rWEwjQ==",
"peer": true,
"dependencies": {
"vscode-jsonrpc": "9.0.0-next.2",
"vscode-languageserver-types": "3.17.6-next.3"
"vscode-jsonrpc": "9.0.0-next.3",
"vscode-languageserver-types": "3.17.6-next.4"
}
},
"node_modules/vscode-languageserver-types": {
"version": "3.17.6-next.3",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.6-next.3.tgz",
"integrity": "sha512-l5kNFXFRQGuzriXpuBqFpRmkf6f6A4VoU3h95OsVkqIOoi1k7KbwSo600cIdsKSJWrPg/+vX+QMPcMw1oI7ItA==",
"version": "3.17.6-next.4",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.6-next.4.tgz",
"integrity": "sha512-SeJTpH/S14EbxOAVaOUoGVqPToqpRTld5QO5Ghig3AlbFJTFF9Wu7srHMfa85L0SX1RYAuuCSFKJVVCxDIk1/Q==",
"peer": true
},
"node_modules/wrap-ansi": {

View File

@ -17,15 +17,15 @@
"Language Server"
],
"engines": {
"vscode": "^1.88.0"
"vscode": "^1.89.0"
},
"main": "./out/extension",
"browser": "./dist/web/extension",
"dependencies": {
"@vscode/wasm-wasi-lsp": "0.1.0-pre.3"
"@vscode/wasm-wasi-lsp": "0.1.0-pre.6"
},
"devDependencies": {
"@types/vscode": "1.88.0",
"@types/vscode": "1.89.0",
"@types/node": "^18.14.6"
},
"scripts": {

View File

@ -6,14 +6,14 @@
import { ExtensionContext, Uri, window, workspace, commands } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, RequestType } from 'vscode-languageclient/node';
import { Wasm, ProcessOptions } from '@vscode/wasm-wasi';
import { createStdioOptions, startServer } from '@vscode/wasm-wasi-lsp';
import { createStdioOptions, createUriConverters, startServer } from '@vscode/wasm-wasi-lsp';
let client: LanguageClient;
const channel = window.createOutputChannel('LSP WASM Server');
export async function activate(context: ExtensionContext) {
const wasm: Wasm = await Wasm.load();
const channel = window.createOutputChannel('LSP WASM Server');
const serverOptions: ServerOptions = async () => {
const options: ProcessOptions = {
stdio: createStdioOptions(),
@ -21,7 +21,7 @@ export async function activate(context: ExtensionContext) {
{ kind: 'workspaceFolder' },
]
};
const filename = Uri.joinPath(context.extensionUri, 'server', 'target', 'wasm32-wasi-preview1-threads', 'release', 'server.wasm');
const filename = Uri.joinPath(context.extensionUri, 'server', 'target', 'wasm32-wasip1-threads', 'release', 'server.wasm');
const bits = await workspace.fs.readFile(filename);
const module = await WebAssembly.compile(bits);
const process = await wasm.createProcess('lsp-server', module, { initial: 160, maximum: 160, shared: true }, options);
@ -35,9 +35,9 @@ export async function activate(context: ExtensionContext) {
};
const clientOptions: LanguageClientOptions = {
documentSelector: [ { language: 'bat' } ],
documentSelector: [ { language: 'plaintext' } ],
outputChannel: channel,
diagnosticCollectionName: 'markers',
uriConverters: createUriConverters(),
};
client = new LanguageClient('lspClient', 'LSP Client', serverOptions, clientOptions);
@ -48,13 +48,13 @@ export async function activate(context: ExtensionContext) {
}
type CountFileParams = { folder: string };
const CountFilesRequest = new RequestType<CountFileParams, number, void>('wasm-language-server/countFilesInFolder');
const CountFilesRequest = new RequestType<CountFileParams, number, void>('wasm-language-server/countFiles');
context.subscriptions.push(commands.registerCommand('vscode-samples.wasm-language-server.countFiles', async () => {
// We assume we do have a folder.
const folder = workspace.workspaceFolders![0].uri;
// We need to convert the folder URI to a URI that maps to the mounted WASI file system. This is something
// @vscode/wasm-wasi-lsp does for us.
const result = await client.sendRequest(CountFilesRequest, { folder: client.code2ProtocolConverter.asUri(folder!) });
const result = await client.sendRequest(CountFilesRequest, { folder: client.code2ProtocolConverter.asUri(folder) });
window.showInformationMessage(`The workspace contains ${result} files.`);
}));
}

View File

@ -13,9 +13,9 @@
"@types/node": "^18.14.6",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"esbuild": "^0.20.2",
"esbuild": "^0.21.3",
"eslint": "^8.57.0",
"serve": "^14.2.1",
"serve": "^14.2.3",
"typescript": "^5.4.5"
},
"engines": {
@ -32,9 +32,9 @@
}
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz",
"integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.3.tgz",
"integrity": "sha512-yTgnwQpFVYfvvo4SvRFB0SwrW8YjOxEoT7wfMT7Ol5v7v5LDNvSGo67aExmxOb87nQNeWPVvaGBNfQ7BXcrZ9w==",
"cpu": [
"ppc64"
],
@ -48,9 +48,9 @@
}
},
"node_modules/@esbuild/android-arm": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz",
"integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.21.3.tgz",
"integrity": "sha512-bviJOLMgurLJtF1/mAoJLxDZDL6oU5/ztMHnJQRejbJrSc9FFu0QoUoFhvi6qSKJEw9y5oGyvr9fuDtzJ30rNQ==",
"cpu": [
"arm"
],
@ -64,9 +64,9 @@
}
},
"node_modules/@esbuild/android-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz",
"integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.21.3.tgz",
"integrity": "sha512-c+ty9necz3zB1Y+d/N+mC6KVVkGUUOcm4ZmT5i/Fk5arOaY3i6CA3P5wo/7+XzV8cb4GrI/Zjp8NuOQ9Lfsosw==",
"cpu": [
"arm64"
],
@ -80,9 +80,9 @@
}
},
"node_modules/@esbuild/android-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz",
"integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.21.3.tgz",
"integrity": "sha512-JReHfYCRK3FVX4Ra+y5EBH1b9e16TV2OxrPAvzMsGeES0X2Ndm9ImQRI4Ket757vhc5XBOuGperw63upesclRw==",
"cpu": [
"x64"
],
@ -96,9 +96,9 @@
}
},
"node_modules/@esbuild/darwin-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz",
"integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.3.tgz",
"integrity": "sha512-U3fuQ0xNiAkXOmQ6w5dKpEvXQRSpHOnbw7gEfHCRXPeTKW9sBzVck6C5Yneb8LfJm0l6le4NQfkNPnWMSlTFUQ==",
"cpu": [
"arm64"
],
@ -112,9 +112,9 @@
}
},
"node_modules/@esbuild/darwin-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz",
"integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.21.3.tgz",
"integrity": "sha512-3m1CEB7F07s19wmaMNI2KANLcnaqryJxO1fXHUV5j1rWn+wMxdUYoPyO2TnAbfRZdi7ADRwJClmOwgT13qlP3Q==",
"cpu": [
"x64"
],
@ -128,9 +128,9 @@
}
},
"node_modules/@esbuild/freebsd-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz",
"integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.3.tgz",
"integrity": "sha512-fsNAAl5pU6wmKHq91cHWQT0Fz0vtyE1JauMzKotrwqIKAswwP5cpHUCxZNSTuA/JlqtScq20/5KZ+TxQdovU/g==",
"cpu": [
"arm64"
],
@ -144,9 +144,9 @@
}
},
"node_modules/@esbuild/freebsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz",
"integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.21.3.tgz",
"integrity": "sha512-tci+UJ4zP5EGF4rp8XlZIdq1q1a/1h9XuronfxTMCNBslpCtmk97Q/5qqy1Mu4zIc0yswN/yP/BLX+NTUC1bXA==",
"cpu": [
"x64"
],
@ -160,9 +160,9 @@
}
},
"node_modules/@esbuild/linux-arm": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz",
"integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.21.3.tgz",
"integrity": "sha512-f6kz2QpSuyHHg01cDawj0vkyMwuIvN62UAguQfnNVzbge2uWLhA7TCXOn83DT0ZvyJmBI943MItgTovUob36SQ==",
"cpu": [
"arm"
],
@ -176,9 +176,9 @@
}
},
"node_modules/@esbuild/linux-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz",
"integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.21.3.tgz",
"integrity": "sha512-vvG6R5g5ieB4eCJBQevyDMb31LMHthLpXTc2IGkFnPWS/GzIFDnaYFp558O+XybTmYrVjxnryru7QRleJvmZ6Q==",
"cpu": [
"arm64"
],
@ -192,9 +192,9 @@
}
},
"node_modules/@esbuild/linux-ia32": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz",
"integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.21.3.tgz",
"integrity": "sha512-HjCWhH7K96Na+66TacDLJmOI9R8iDWDDiqe17C7znGvvE4sW1ECt9ly0AJ3dJH62jHyVqW9xpxZEU1jKdt+29A==",
"cpu": [
"ia32"
],
@ -208,9 +208,9 @@
}
},
"node_modules/@esbuild/linux-loong64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz",
"integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.21.3.tgz",
"integrity": "sha512-BGpimEccmHBZRcAhdlRIxMp7x9PyJxUtj7apL2IuoG9VxvU/l/v1z015nFs7Si7tXUwEsvjc1rOJdZCn4QTU+Q==",
"cpu": [
"loong64"
],
@ -224,9 +224,9 @@
}
},
"node_modules/@esbuild/linux-mips64el": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz",
"integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.21.3.tgz",
"integrity": "sha512-5rMOWkp7FQGtAH3QJddP4w3s47iT20hwftqdm7b+loe95o8JU8ro3qZbhgMRy0VuFU0DizymF1pBKkn3YHWtsw==",
"cpu": [
"mips64el"
],
@ -240,9 +240,9 @@
}
},
"node_modules/@esbuild/linux-ppc64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz",
"integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.21.3.tgz",
"integrity": "sha512-h0zj1ldel89V5sjPLo5H1SyMzp4VrgN1tPkN29TmjvO1/r0MuMRwJxL8QY05SmfsZRs6TF0c/IDH3u7XYYmbAg==",
"cpu": [
"ppc64"
],
@ -256,9 +256,9 @@
}
},
"node_modules/@esbuild/linux-riscv64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz",
"integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.21.3.tgz",
"integrity": "sha512-dkAKcTsTJ+CRX6bnO17qDJbLoW37npd5gSNtSzjYQr0svghLJYGYB0NF1SNcU1vDcjXLYS5pO4qOW4YbFama4A==",
"cpu": [
"riscv64"
],
@ -272,9 +272,9 @@
}
},
"node_modules/@esbuild/linux-s390x": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz",
"integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.21.3.tgz",
"integrity": "sha512-vnD1YUkovEdnZWEuMmy2X2JmzsHQqPpZElXx6dxENcIwTu+Cu5ERax6+Ke1QsE814Zf3c6rxCfwQdCTQ7tPuXA==",
"cpu": [
"s390x"
],
@ -288,9 +288,9 @@
}
},
"node_modules/@esbuild/linux-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz",
"integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.3.tgz",
"integrity": "sha512-IOXOIm9WaK7plL2gMhsWJd+l2bfrhfilv0uPTptoRoSb2p09RghhQQp9YY6ZJhk/kqmeRt6siRdMSLLwzuT0KQ==",
"cpu": [
"x64"
],
@ -304,9 +304,9 @@
}
},
"node_modules/@esbuild/netbsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz",
"integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.3.tgz",
"integrity": "sha512-uTgCwsvQ5+vCQnqM//EfDSuomo2LhdWhFPS8VL8xKf+PKTCrcT/2kPPoWMTs22aB63MLdGMJiE3f1PHvCDmUOw==",
"cpu": [
"x64"
],
@ -320,9 +320,9 @@
}
},
"node_modules/@esbuild/openbsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz",
"integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.3.tgz",
"integrity": "sha512-vNAkR17Ub2MgEud2Wag/OE4HTSI6zlb291UYzHez/psiKarp0J8PKGDnAhMBcHFoOHMXHfExzmjMojJNbAStrQ==",
"cpu": [
"x64"
],
@ -336,9 +336,9 @@
}
},
"node_modules/@esbuild/sunos-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz",
"integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.3.tgz",
"integrity": "sha512-W8H9jlGiSBomkgmouaRoTXo49j4w4Kfbl6I1bIdO/vT0+0u4f20ko3ELzV3hPI6XV6JNBVX+8BC+ajHkvffIJA==",
"cpu": [
"x64"
],
@ -352,9 +352,9 @@
}
},
"node_modules/@esbuild/win32-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz",
"integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.21.3.tgz",
"integrity": "sha512-EjEomwyLSCg8Ag3LDILIqYCZAq/y3diJ04PnqGRgq8/4O3VNlXyMd54j/saShaN4h5o5mivOjAzmU6C3X4v0xw==",
"cpu": [
"arm64"
],
@ -368,9 +368,9 @@
}
},
"node_modules/@esbuild/win32-ia32": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz",
"integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.21.3.tgz",
"integrity": "sha512-WGiE/GgbsEwR33++5rzjiYsKyHywE8QSZPF7Rfx9EBfK3Qn3xyR6IjyCr5Uk38Kg8fG4/2phN7sXp4NPWd3fcw==",
"cpu": [
"ia32"
],
@ -384,9 +384,9 @@
}
},
"node_modules/@esbuild/win32-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz",
"integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.3.tgz",
"integrity": "sha512-xRxC0jaJWDLYvcUvjQmHCJSfMrgmUuvsoXgDeU/wTorQ1ngDdUBuFtgY3W1Pc5sprGAvZBtWdJX7RPg/iZZUqA==",
"cpu": [
"x64"
],
@ -785,9 +785,9 @@
"dev": true
},
"node_modules/@zeit/schemas": {
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/@zeit/schemas/-/schemas-2.29.0.tgz",
"integrity": "sha512-g5QiLIfbg3pLuYUJPlisNKY+epQJTcMDsOnVNkscrDP1oi7vmJnzOANYJI/1pZcVJ6umUkBv3aFtlg1UvUHGzA==",
"version": "2.36.0",
"resolved": "https://registry.npmjs.org/@zeit/schemas/-/schemas-2.36.0.tgz",
"integrity": "sha512-7kjMwcChYEzMKjeex9ZFXkt1AyNov9R5HZtjBKVsmVpw7pa7ZtlCGvCBC2vnnXctaYN+aRI61HjIqeetZW5ROg==",
"dev": true
},
"node_modules/accepts": {
@ -1258,9 +1258,9 @@
"dev": true
},
"node_modules/esbuild": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz",
"integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==",
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.3.tgz",
"integrity": "sha512-Kgq0/ZsAPzKrbOjCQcjoSmPoWhlcVnGAUo7jvaLHoxW1Drto0KGkR1xBNg2Cp43b9ImvxmPEJZ9xkfcnqPsfBw==",
"dev": true,
"hasInstallScript": true,
"bin": {
@ -1270,29 +1270,29 @@
"node": ">=12"
},
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.20.2",
"@esbuild/android-arm": "0.20.2",
"@esbuild/android-arm64": "0.20.2",
"@esbuild/android-x64": "0.20.2",
"@esbuild/darwin-arm64": "0.20.2",
"@esbuild/darwin-x64": "0.20.2",
"@esbuild/freebsd-arm64": "0.20.2",
"@esbuild/freebsd-x64": "0.20.2",
"@esbuild/linux-arm": "0.20.2",
"@esbuild/linux-arm64": "0.20.2",
"@esbuild/linux-ia32": "0.20.2",
"@esbuild/linux-loong64": "0.20.2",
"@esbuild/linux-mips64el": "0.20.2",
"@esbuild/linux-ppc64": "0.20.2",
"@esbuild/linux-riscv64": "0.20.2",
"@esbuild/linux-s390x": "0.20.2",
"@esbuild/linux-x64": "0.20.2",
"@esbuild/netbsd-x64": "0.20.2",
"@esbuild/openbsd-x64": "0.20.2",
"@esbuild/sunos-x64": "0.20.2",
"@esbuild/win32-arm64": "0.20.2",
"@esbuild/win32-ia32": "0.20.2",
"@esbuild/win32-x64": "0.20.2"
"@esbuild/aix-ppc64": "0.21.3",
"@esbuild/android-arm": "0.21.3",
"@esbuild/android-arm64": "0.21.3",
"@esbuild/android-x64": "0.21.3",
"@esbuild/darwin-arm64": "0.21.3",
"@esbuild/darwin-x64": "0.21.3",
"@esbuild/freebsd-arm64": "0.21.3",
"@esbuild/freebsd-x64": "0.21.3",
"@esbuild/linux-arm": "0.21.3",
"@esbuild/linux-arm64": "0.21.3",
"@esbuild/linux-ia32": "0.21.3",
"@esbuild/linux-loong64": "0.21.3",
"@esbuild/linux-mips64el": "0.21.3",
"@esbuild/linux-ppc64": "0.21.3",
"@esbuild/linux-riscv64": "0.21.3",
"@esbuild/linux-s390x": "0.21.3",
"@esbuild/linux-x64": "0.21.3",
"@esbuild/netbsd-x64": "0.21.3",
"@esbuild/openbsd-x64": "0.21.3",
"@esbuild/sunos-x64": "0.21.3",
"@esbuild/win32-arm64": "0.21.3",
"@esbuild/win32-ia32": "0.21.3",
"@esbuild/win32-x64": "0.21.3"
}
},
"node_modules/escape-string-regexp": {
@ -2440,13 +2440,13 @@
}
},
"node_modules/serve": {
"version": "14.2.1",
"resolved": "https://registry.npmjs.org/serve/-/serve-14.2.1.tgz",
"integrity": "sha512-48er5fzHh7GCShLnNyPBRPEjs2I6QBozeGr02gaacROiyS/8ARADlj595j39iZXAqBbJHH/ivJJyPRWY9sQWZA==",
"version": "14.2.3",
"resolved": "https://registry.npmjs.org/serve/-/serve-14.2.3.tgz",
"integrity": "sha512-VqUFMC7K3LDGeGnJM9h56D3XGKb6KGgOw0cVNtA26yYXHCcpxf3xwCTUaQoWlVS7i8Jdh3GjQkOB23qsXyjoyQ==",
"dev": true,
"dependencies": {
"@zeit/schemas": "2.29.0",
"ajv": "8.11.0",
"@zeit/schemas": "2.36.0",
"ajv": "8.12.0",
"arg": "5.0.2",
"boxen": "7.0.0",
"chalk": "5.0.1",
@ -2524,9 +2524,9 @@
}
},
"node_modules/serve/node_modules/ajv": {
"version": "8.11.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz",
"integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==",
"version": "8.12.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
"integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
"dev": true,
"dependencies": {
"fast-deep-equal": "^3.1.1",

View File

@ -22,7 +22,7 @@
"main": "./client/out/extension",
"browser": "./client/dist/web/extension",
"activationEvents": [
"onLanguage:bat"
"onLanguage:plaintext"
],
"extensionDependencies": [
"ms-vscode.wasm-wasi-core"
@ -44,13 +44,15 @@
"@types/node": "^18.14.6",
"eslint": "^8.57.0",
"typescript": "^5.4.5",
"esbuild": "^0.20.2",
"serve": "^14.2.1"
"esbuild": "^0.21.3",
"serve": "^14.2.3"
},
"scripts": {
"postinstall": "cd client && npm install && cd ..",
"vscode:prepublish": "npm run build",
"build": "cd client && npm run compile && cd ../server && npm run build && cd ..",
"lint": "cd client && npm run lint && cd .."
"lint": "cd client && npm run lint && cd ..",
"esbuild": "node ./bin/esbuild.js",
"serve": "serve --cors -l 5000 --ssl-cert $HOME/certs/localhost.pem --ssl-key $HOME/certs/localhost-key.pem"
}
}

View File

@ -6,7 +6,7 @@
"author": "Microsoft Corporation",
"license": "MIT",
"scripts": {
"build": "cargo rustc --release --target wasm32-wasi-preview1-threads -- -Clink-arg=--initial-memory=10485760 -Clink-arg=--max-memory=10485760",
"build": "cargo rustc --release --target wasm32-wasip1-threads -- -Clink-arg=--initial-memory=10485760 -Clink-arg=--max-memory=10485760",
"test:wasm": "node ./bin/send.js | wasmtime --wasm-features=threads --wasi-modules=experimental-wasi-threads target/wasm32-wasi-preview1-threads/release/server.wasm"
}
}

View File

@ -2,18 +2,27 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use std::fs;
use std::error::Error;
use serde::{ Deserialize, Serialize };
use walkdir::WalkDir;
use lsp_types::{
request::GotoDefinition, GotoDefinitionResponse, InitializeParams,
ServerCapabilities, Location, OneOf
GotoDefinitionResponse, InitializeParams, Location, OneOf, ServerCapabilities, Url,
request::{ GotoDefinition, Request }
};
use lsp_server::{ Connection, ExtractError, Message, RequestId, Response };
fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
// Note that we must have our logging only write out to stderr.
// Note that we must have our logging only write out to stderr since the communication with the client
// is done via stdin/stdout. If we write to stdout, we will corrupt the communication.
eprintln!("Starting WASM based LSP server");
// This is a workaround for a deadlock issue in WASI libc.
// See https://github.com/WebAssembly/wasi-libc/pull/491
fs::metadata("/workspace").unwrap();
// Create the transport. Includes the stdio (stdin and stdout) versions but this could
// also be implemented to use sockets or HTTP.
let (connection, io_threads) = Connection::stdio();
@ -33,6 +42,19 @@ fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
Ok(())
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CountFilesParams {
pub folder: Url,
}
pub enum CountFilesRequest {}
impl Request for CountFilesRequest {
type Params = CountFilesParams;
type Result = u32;
const METHOD: &'static str = "wasm-language-server/countFiles";
}
fn main_loop(connection: Connection, params: serde_json::Value) -> Result<(), Box<dyn Error + Sync + Send>> {
let _params: InitializeParams = serde_json::from_value(params).unwrap();
for msg in &connection.receiver {
@ -41,10 +63,14 @@ fn main_loop(connection: Connection, params: serde_json::Value) -> Result<(), Bo
if connection.handle_shutdown(&req)? {
return Ok(());
}
match cast::<GotoDefinition>(req) {
match cast::<GotoDefinition>(req.clone()) {
Ok((id, params)) => {
eprintln!("Received gotoDefinition request #{id}");
let loc = Location::new(params.text_document_position_params.text_document.uri, lsp_types::Range::new(lsp_types::Position::new(0, 0), lsp_types::Position::new(0, 0)));
let uri = params.text_document_position_params.text_document.uri;
eprintln!("Received gotoDefinition request #{} {}", id, uri.to_string());
let loc = Location::new(
uri,
lsp_types::Range::new(lsp_types::Position::new(0, 0), lsp_types::Position::new(0, 0))
);
let mut vec = Vec::new();
vec.push(loc);
let result = Some(GotoDefinitionResponse::Array(vec));
@ -56,12 +82,22 @@ fn main_loop(connection: Connection, params: serde_json::Value) -> Result<(), Bo
Err(err @ ExtractError::JsonError { .. }) => panic!("{err:?}"),
Err(ExtractError::MethodMismatch(req)) => req,
};
match cast::<CountFilesRequest>(req.clone()) {
Ok((id, params)) => {
eprintln!("Received countFiles request #{} {}", id, params.folder);
let result = count_files_in_directory(&params.folder.path());
let json = serde_json::to_value(&result).unwrap();
let resp = Response { id, result: Some(json), error: None };
connection.sender.send(Message::Response(resp))?;
continue;
}
Err(err @ ExtractError::JsonError { .. }) => panic!("{err:?}"),
Err(ExtractError::MethodMismatch(req)) => req,
};
}
Message::Response(resp) => {
eprintln!("got response: {resp:?}");
Message::Response(_resp) => {
}
Message::Notification(not) => {
eprintln!("Received notification: {not:?}");
Message::Notification(_not) => {
}
}
}
@ -74,4 +110,12 @@ where
R::Params: serde::de::DeserializeOwned,
{
req.extract(R::METHOD)
}
fn count_files_in_directory(path: &str) -> usize {
WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.filter(|entry| entry.file_type().is_file())
.count()
}

View File

@ -0,0 +1,8 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est laborum.

View File

@ -1,10 +0,0 @@
REM @ECHO OFF
cd c:\source
REM This is the location of the files that you want to sort
FOR %%f IN (*.doc *.txt) DO XCOPY c:\source\"%%f" c:\text /m /y
REM This moves any files with a .doc or
REM .txt extension from . c:\source to c:\textkkk
REM %%f is a variable
FOR %%f IN (*.jpg *.png *.bmp) DO XCOPY C:\source\"%%f" c:\images /m /y
REM This moves any files with a .jpg, .png,
REM or .bmp extension from c:\source to c:\images;;

View File

@ -1 +0,0 @@
Some text.