monaco-lsp-bridge 0.0.1
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 +21 -0
- package/README.md +61 -0
- package/lib/cjs/error.js +46 -0
- package/lib/cjs/error.js.map +1 -0
- package/lib/cjs/index.js +594 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/protocol.js +21 -0
- package/lib/cjs/protocol.js.map +1 -0
- package/lib/cjs/transport.js +269 -0
- package/lib/cjs/transport.js.map +1 -0
- package/lib/cjs/util.js +264 -0
- package/lib/cjs/util.js.map +1 -0
- package/lib/esm/error.js +40 -0
- package/lib/esm/error.js.map +1 -0
- package/lib/esm/index.js +576 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/protocol.js +15 -0
- package/lib/esm/protocol.js.map +1 -0
- package/lib/esm/transport.js +265 -0
- package/lib/esm/transport.js.map +1 -0
- package/lib/esm/util.js +252 -0
- package/lib/esm/util.js.map +1 -0
- package/lib/ts/error.d.ts +26 -0
- package/lib/ts/error.d.ts.map +1 -0
- package/lib/ts/index.d.ts +78 -0
- package/lib/ts/index.d.ts.map +1 -0
- package/lib/ts/protocol.d.ts +80 -0
- package/lib/ts/protocol.d.ts.map +1 -0
- package/lib/ts/transport.d.ts +74 -0
- package/lib/ts/transport.d.ts.map +1 -0
- package/lib/ts/util.d.ts +21 -0
- package/lib/ts/util.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/error.ts +48 -0
- package/src/index.ts +709 -0
- package/src/protocol.ts +129 -0
- package/src/transport.ts +337 -0
- package/src/util.ts +300 -0
- package/tsconfig.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Daniel Beaven
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# monaco-lsp-bridge
|
|
2
|
+
|
|
3
|
+
A small, typed bridge that wires a Language Server Protocol (LSP) server to the Monaco editor.
|
|
4
|
+
It handles JSON-RPC transport, progress/cancellation, diagnostics → markers, and completion/hover/formatting adapters.
|
|
5
|
+
|
|
6
|
+
[](https://github.com/Pingid/monaco-lsp-bridge/actions?query=workflow:Test)
|
|
7
|
+
[](https://bundlephobia.com/result?p=monaco-lsp-bridge)
|
|
8
|
+
[](https://www.npmjs.com/package/monaco-lsp-bridge)
|
|
9
|
+
[](https://www.npmjs.com/package/monaco-lsp-bridge)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Install the `monaco-lsp-bridge` library using your preferred package manager:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install monaco-lsp-bridge
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import * as monaco from 'monaco-editor'
|
|
23
|
+
import { LspMonacoClient, LspTransport } from 'monaco-lsp-bridge'
|
|
24
|
+
|
|
25
|
+
// 1) Create your Monaco editor
|
|
26
|
+
const editor = monaco.editor.create(document.getElementById('root')!, {
|
|
27
|
+
value: 'function main() {}',
|
|
28
|
+
language: 'javascript',
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// 2) Create a transport to your LSP server (e.g. Web Worker)
|
|
32
|
+
const worker = new Worker(new URL('./server.worker.js', import.meta.url), { type: 'module' })
|
|
33
|
+
const transport = LspTransport.fromWorker(worker)
|
|
34
|
+
|
|
35
|
+
// 3) Start the client
|
|
36
|
+
const client = new LspMonacoClient(transport, {
|
|
37
|
+
languageSelector: { language: 'javascript' }, // or a selector array
|
|
38
|
+
dedicatedServer: true, // sends shutdown/exit on dispose
|
|
39
|
+
})
|
|
40
|
+
client.connect(monaco, editor)
|
|
41
|
+
|
|
42
|
+
// (optional) listen to client events
|
|
43
|
+
const off = client.onEvent((e) => {
|
|
44
|
+
if (e.type === 'error') console.error(e.error)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// Later: dispose
|
|
48
|
+
// await client.dispose()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What it does
|
|
52
|
+
|
|
53
|
+
- Initializes the LSP server and applies reported capabilities.
|
|
54
|
+
- Sends `didOpen`/`didChange`/`didClose` matching server sync mode.
|
|
55
|
+
- Maps diagnostics → Monaco markers.
|
|
56
|
+
- Adapts completion, resolve, hover, and formatting requests.
|
|
57
|
+
- Handles progress (`$/progress`) and cancellation via `AbortSignal`.
|
|
58
|
+
|
|
59
|
+
## 📄 License
|
|
60
|
+
|
|
61
|
+
MIT © [Dan Beaven](https://github.com/Pingid)
|
package/lib/cjs/error.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toLspError = exports.isCancellationError = exports.LspError = exports.LspErrorCode = void 0;
|
|
4
|
+
var LspErrorCode;
|
|
5
|
+
(function (LspErrorCode) {
|
|
6
|
+
// JSON-RPC predefined errors (-32700 to -32600)
|
|
7
|
+
LspErrorCode[LspErrorCode["ParseError"] = -32700] = "ParseError";
|
|
8
|
+
LspErrorCode[LspErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
9
|
+
LspErrorCode[LspErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
10
|
+
LspErrorCode[LspErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
11
|
+
LspErrorCode[LspErrorCode["InternalError"] = -32603] = "InternalError";
|
|
12
|
+
// JSON-RPC reserved server error range (-32000 to -32099)
|
|
13
|
+
LspErrorCode[LspErrorCode["ServerErrorBase"] = -32000] = "ServerErrorBase";
|
|
14
|
+
// LSP-specific errors (-32900 to -32800)
|
|
15
|
+
LspErrorCode[LspErrorCode["RequestCancelled"] = -32800] = "RequestCancelled";
|
|
16
|
+
LspErrorCode[LspErrorCode["ContentModified"] = -32801] = "ContentModified";
|
|
17
|
+
LspErrorCode[LspErrorCode["ServerCancelled"] = -32802] = "ServerCancelled";
|
|
18
|
+
// Client-local errors (positive codes to avoid reserved range conflicts)
|
|
19
|
+
LspErrorCode[LspErrorCode["Timeout"] = 1001] = "Timeout";
|
|
20
|
+
LspErrorCode[LspErrorCode["Disposed"] = 1002] = "Disposed";
|
|
21
|
+
})(LspErrorCode || (exports.LspErrorCode = LspErrorCode = {}));
|
|
22
|
+
class LspError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
data;
|
|
25
|
+
constructor(shape) {
|
|
26
|
+
super(shape.message);
|
|
27
|
+
this.code = shape.code;
|
|
28
|
+
this.data = shape.data;
|
|
29
|
+
this.name = 'LspError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.LspError = LspError;
|
|
33
|
+
const isCancellationError = (e) => typeof e === 'object' &&
|
|
34
|
+
e !== null &&
|
|
35
|
+
'code' in e &&
|
|
36
|
+
(e.code === LspErrorCode.RequestCancelled || e.code === LspErrorCode.ServerCancelled);
|
|
37
|
+
exports.isCancellationError = isCancellationError;
|
|
38
|
+
const toLspError = (e) => e instanceof LspError
|
|
39
|
+
? e
|
|
40
|
+
: new LspError({
|
|
41
|
+
code: Number(e?.code ?? LspErrorCode.InternalError),
|
|
42
|
+
message: String(e?.message ?? 'Error'),
|
|
43
|
+
data: e?.data,
|
|
44
|
+
});
|
|
45
|
+
exports.toLspError = toLspError;
|
|
46
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB,gDAAgD;IAChD,gEAAmB,CAAA;IACnB,wEAAuB,CAAA;IACvB,wEAAuB,CAAA;IACvB,sEAAsB,CAAA;IACtB,sEAAsB,CAAA;IAEtB,0DAA0D;IAC1D,0EAAwB,CAAA;IAExB,yCAAyC;IACzC,4EAAyB,CAAA;IACzB,0EAAwB,CAAA;IACxB,0EAAwB,CAAA;IAExB,yEAAyE;IACzE,wDAAc,CAAA;IACd,0DAAe,CAAA;AACjB,CAAC,EAnBW,YAAY,4BAAZ,YAAY,QAmBvB;AAID,MAAa,QAAS,SAAQ,KAAK;IACjC,IAAI,CAAQ;IACZ,IAAI,CAAU;IACd,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;IACxB,CAAC;CACF;AATD,4BASC;AAEM,MAAM,mBAAmB,GAAG,CAAC,CAAU,EAAE,EAAE,CAChD,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,KAAK,IAAI;IACV,MAAM,IAAK,CAAS;IACpB,CAAE,CAAS,CAAC,IAAI,KAAK,YAAY,CAAC,gBAAgB,IAAK,CAAS,CAAC,IAAI,KAAK,YAAY,CAAC,eAAe,CAAC,CAAA;AAJ5F,QAAA,mBAAmB,uBAIyE;AAElG,MAAM,UAAU,GAAG,CAAC,CAAM,EAAY,EAAE,CAC7C,CAAC,YAAY,QAAQ;IACnB,CAAC,CAAC,CAAC;IACH,CAAC,CAAC,IAAI,QAAQ,CAAC;QACX,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,IAAI,YAAY,CAAC,aAAa,CAAC;QACnD,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,IAAI,OAAO,CAAC;QACtC,IAAI,EAAE,CAAC,EAAE,IAAI;KACd,CAAC,CAAA;AAPK,QAAA,UAAU,cAOf"}
|