@adecore/lsp 0.17.0-beta.1 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +36 -22
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,33 +1,47 @@
|
|
|
1
1
|
# @adecore/lsp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@adecore/lsp)
|
|
4
|
+
[](https://adecore.dev/lsp/)
|
|
4
5
|
|
|
5
|
-
A
|
|
6
|
+
A client for the Language Server Protocol 3.17, without a DOM and without Node or Bun APIs, so it runs in a backend, a utility process or a page. It also defines `LanguageService`, the interface [`@adecore/editor-react`](https://adecore.dev/editor-react/) asks its features through. It starts no server: the app hands it a transport.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Install
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
```sh
|
|
11
|
+
bun add @adecore/lsp
|
|
12
|
+
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
## Use
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `JsonRpcConnection`: correlation, `$/cancelRequest`, a request timeout (30 seconds, `0` turns it off) and the requests a server sends. `LspError` carries a JSON-RPC code; `ErrorCodes` names the ones used here.
|
|
16
|
-
- Transports: `createStreamTransport` over a `ByteStream` (a child's stdin and stdout, which the host adapts), `ContentLengthDecoder` and `encodeMessage` for the framing, `createMemoryTransportPair` and `connectWebSocket`.
|
|
17
|
-
- Edits: `applyTextEdits` and `planWorkspaceEdit` (simultaneous edits and a multi-file plan, which refuses file operations), `applyContentChanges` (sequential), `minimalChange`, `offsetAt`, `positionAt` and `endPosition`.
|
|
18
|
-
- File renames: `willRenameFiles` and `didRenameFiles` of `LspSession` take the files that move (`RenamedFile`, which says whether each is a folder) and pass on only those that the filters of the server take, from its capabilities and its registrations (`fileOperationFilters`, `renamesTaken`: scheme, glob on the path the file leaves, `matches`, `ignoreCase`). The session declares `resourceOperations: ['rename']`, `workspace.fileOperations` and the `refactor.move` kind in `initialize`.
|
|
19
|
-
- `bridgeVueTypeScript` relays Vue's `tsserver/request` to the TypeScript server, and `vueServerOrder` says which of the two servers of a `.vue` document to ask first.
|
|
20
|
-
- `pathToFileUri` and `fileUriToPath`.
|
|
21
|
-
- `LanguageService`: what the editor asks of the language side (open, change and close a document, every feature above, `executeCommand`, `supports`, `providerOptions`, `onProvidersChanged` and `onDiagnostics`). Results stay in LSP shapes. A request takes `signal` and `parallel`, which lets many requests of one feature run side by side instead of each taking over from the one before. A host adapts server sessions or its own transport to this interface. Server discovery, process startup, authorization and saving remain outside the library.
|
|
22
|
-
- `@adecore/lsp/testing`: `FakeLanguageServer`, a server on the far end of a transport that answers the handshake, mirrors document text and answers whatever a test registers, and `createMemoryTransportPair`.
|
|
16
|
+
```ts
|
|
17
|
+
import { LspSession, createStreamTransport, pathToFileUri } from '@adecore/lsp';
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
const session = new LspSession(createStreamTransport(stream), { rootUri: pathToFileUri('/work') });
|
|
20
|
+
await session.initialize();
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const document = session.openDocument({ uri: pathToFileUri('/work/example.ts'), languageId: 'typescript', text });
|
|
23
|
+
await document.updateText(nextText);
|
|
24
|
+
const hover = await document.hover({ line: 0, character: 6 });
|
|
25
|
+
```
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
An answer for a text that changed in the meantime rejects with `StaleResultError`.
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
## Entry points
|
|
30
|
+
|
|
31
|
+
| Import | What it holds |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `@adecore/lsp` | `LspSession`, `LspDocument`, the transports, the edit and URI helpers, the Vue bridge and the protocol types |
|
|
34
|
+
| `@adecore/lsp/testing` | `FakeLanguageServer` and `createMemoryTransportPair` |
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
|
|
38
|
+
| Page | What it covers |
|
|
39
|
+
|---|---|
|
|
40
|
+
| [Sessions and transports](https://adecore.dev/lsp/sessions) | Stdio, WebSocket and memory transports, the handshake, capabilities and errors |
|
|
41
|
+
| [Documents and edits](https://adecore.dev/lsp/documents) | Versions, requests, stale answers, edit helpers, workspace edits and renames |
|
|
42
|
+
| [Language service](https://adecore.dev/lsp/language-service) | The interface for editor features, and Vue with TypeScript |
|
|
43
|
+
| [Testing](https://adecore.dev/lsp/testing) | A fake server in memory |
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
FSL-1.1-MIT
|