This commit is contained in:
Nick Trogh 2024-05-28 16:26:29 +02:00
Родитель f9239b534c
Коммит 1def158b6b
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -35,9 +35,9 @@ async function main(): Promise<void> {
main().catch(RAL().console.error);
```
All the code does, is create a connection to communicate with the extension host main worker and initialize the connection with the `calculator` world that is generated by the `wit2ts` tool.
All the code does, is create a connection to communicate with the extension host main worker, and initialize the connection with the `calculator` world that is generated by the `wit2ts` tool.
On the extension side, all we need to do, is load the WebAssembly module and bind it to the world. The corresponding calls to perform the calculations need to be awaited since the execution happens asynchronously in the worker (for example, `await api.calc(...)`).
On the extension side, all we need to do, is to load the WebAssembly module and bind it to the world. The corresponding calls to perform the calculations need to be awaited since the execution happens asynchronously in the worker (for example, `await api.calc(...)`).
```typescript
// The channel for printing the result.
@ -84,7 +84,7 @@ When we started working on [WebAssembly support for VS Code for the Web](https:/
Additionally, WebAssembly language servers run on the [WebAssembly Core Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.wasm-wasi-core), which fully supports WASI Preview 1. This means that language servers can access the files in the workspace using the regular filesystem API of their programming language, even if the files are stored remotely, such as in a GitHub repository.
Below is a code snippet of a Rust language server, based on the [example server](https://insiders.vscode.dev/github.com/rust-lang/rust-analyzer/blob/master/lib/lsp-server/examples/goto_def.rs#L1) from the `lsp_server` crate. This language server doesn't perform any language analysis but simply returns a predefined result for a `GotoDefinition` request:
The following code snippet shows a Rust language server, based on the [example server](https://insiders.vscode.dev/github.com/rust-lang/rust-analyzer/blob/master/lib/lsp-server/examples/goto_def.rs#L1) from the `lsp_server` crate. This language server doesn't perform any language analysis but simply returns a predefined result for a `GotoDefinition` request:
```rust
match cast::<GotoDefinition>(req) {
@ -164,7 +164,7 @@ Running the code adds a `Goto Definition` entry to the context menu of plain tex
It is important to note that the `@vscode/wasm-wasi-lsp` npm module automatically transforms document URIs from their workspace value to the one recognized in the WASI Preview 1 host. In the above example, the text document's URI inside VS Code is usually something like `vscode-vfs://github/dbaeumer/plaintext-sample/lorem.txt`, and this value gets transformed into `file:///workspace/lorem.txt`, which is recognized inside the WASI host. This transformation also happens automatically when the language server sends a URI back to VS Code.
Most language server libraries support custom messages, which makes it easy to add features to a language server that are not already present in the [Language Server Protocol Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/). The following code snippet shows how to add a custom message handler for counting the files in a given workspace folder to the Rust language server we used previously:
Most language server libraries support custom messages, which make it easy to add features to a language server that are not already present in the [Language Server Protocol Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/). The following code snippet shows how to add a custom message handler for counting the files in a given workspace folder to the Rust language server we used previously:
```rust
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]