@nowline/lsp-worker 0.4.0
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 +190 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +148 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/message-bridge.d.ts +2 -0
- package/dist/message-bridge.d.ts.map +1 -0
- package/dist/message-bridge.js +8 -0
- package/dist/message-bridge.js.map +1 -0
- package/dist/worker.d.ts +25 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +59 -0
- package/dist/worker.js.map +1 -0
- package/package.json +73 -0
- package/src/client.ts +240 -0
- package/src/index.ts +15 -0
- package/src/message-bridge.ts +13 -0
- package/src/worker.ts +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Lolay, Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type CompletionItem, type Definition, type Hover, type Location, type Position, type PublishDiagnosticsParams, type TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol';
|
|
2
|
+
import { type MessageReader, type MessageWriter } from './message-bridge.js';
|
|
3
|
+
export interface CreateNowlineLanguageClientOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Worker handle (or anything matching the
|
|
6
|
+
* `BrowserMessageReader/Writer` shape — `MessagePort`,
|
|
7
|
+
* `DedicatedWorkerGlobalScope`). The client wires both the
|
|
8
|
+
* incoming reader and the outgoing writer against this single
|
|
9
|
+
* port, matching the dedicated-worker / message-channel pattern.
|
|
10
|
+
*/
|
|
11
|
+
worker: Worker | MessagePort;
|
|
12
|
+
/**
|
|
13
|
+
* Caller can pre-build a transport and skip the default
|
|
14
|
+
* `BrowserMessageReader/Writer` (useful for tests + alternate
|
|
15
|
+
* transports like SharedWorker). When supplied, `worker` is
|
|
16
|
+
* ignored.
|
|
17
|
+
*/
|
|
18
|
+
transport?: {
|
|
19
|
+
reader: MessageReader;
|
|
20
|
+
writer: MessageWriter;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Optional root URI for the workspace. Browser IDEs usually leave
|
|
24
|
+
* this as the synthetic default; only set if a virtual workspace
|
|
25
|
+
* is genuinely backed by a hierarchy worth advertising.
|
|
26
|
+
*/
|
|
27
|
+
rootUri?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface NowlineLanguageClient {
|
|
30
|
+
/** Open a document with the server. Must be called before any other request. */
|
|
31
|
+
didOpen(params: {
|
|
32
|
+
uri: string;
|
|
33
|
+
languageId?: string;
|
|
34
|
+
version?: number;
|
|
35
|
+
text: string;
|
|
36
|
+
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Push an incremental change. Per spec, callers must send a
|
|
39
|
+
* `range` + `text` pair — whole-document `text` updates are
|
|
40
|
+
* rejected by the underlying server because it advertises
|
|
41
|
+
* `TextDocumentSyncKind.Incremental`.
|
|
42
|
+
*/
|
|
43
|
+
didChange(params: {
|
|
44
|
+
uri: string;
|
|
45
|
+
version: number;
|
|
46
|
+
changes: TextDocumentContentChangeEvent[];
|
|
47
|
+
}): void;
|
|
48
|
+
didClose(uri: string): void;
|
|
49
|
+
onDiagnostics(listener: (params: PublishDiagnosticsParams) => void): {
|
|
50
|
+
dispose(): void;
|
|
51
|
+
};
|
|
52
|
+
completion(uri: string, position: Position): Promise<CompletionItem[]>;
|
|
53
|
+
hover(uri: string, position: Position): Promise<Hover | null>;
|
|
54
|
+
definition(uri: string, position: Position): Promise<Definition | null>;
|
|
55
|
+
references(uri: string, position: Position): Promise<Location[]>;
|
|
56
|
+
/** Discard listeners and close the underlying connection. */
|
|
57
|
+
dispose(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a Nowline LSP client bound to the supplied Worker (or
|
|
61
|
+
* MessagePort). The client autonegotiates the LSP `initialize`
|
|
62
|
+
* handshake on construction and resolves the returned object once the
|
|
63
|
+
* server has reported its capabilities.
|
|
64
|
+
*
|
|
65
|
+
* The returned `Promise` rejects if the server reports a
|
|
66
|
+
* non-incremental `textDocument/sync` capability — the wire-protocol
|
|
67
|
+
* guard from `specs/lsp.md` § Browser worker packaging.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createNowlineLanguageClient(options: CreateNowlineLanguageClientOptions): Promise<NowlineLanguageClient>;
|
|
70
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,KAAK,cAAc,EAEnB,KAAK,UAAU,EAKf,KAAK,KAAK,EAMV,KAAK,QAAQ,EACb,KAAK,QAAQ,EAGb,KAAK,wBAAwB,EAI7B,KAAK,8BAA8B,EAEtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAGH,KAAK,aAAa,EAClB,KAAK,aAAa,EACrB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,kCAAkC;IAC/C;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,CAAC;IAC7D;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IAClC,gFAAgF;IAChF,OAAO,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5F;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,8BAA8B,EAAE,CAAC;KAC7C,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,wBAAwB,KAAK,IAAI,GAAG;QAAE,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC;IACzF,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACvE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC9D,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACxE,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjE,6DAA6D;IAC7D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAC7C,OAAO,EAAE,kCAAkC,GAC5C,OAAO,CAAC,qBAAqB,CAAC,CAwIhC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Main-thread client for the Nowline LSP worker. Wraps `vscode-jsonrpc`'s
|
|
2
|
+
// `MessageConnection` into a tiny imperative API that browser editors
|
|
3
|
+
// (CodeMirror, Monaco, raw textareas, etc.) can drive without depending
|
|
4
|
+
// on `vscode-languageclient` (which assumes a VS Code host).
|
|
5
|
+
//
|
|
6
|
+
// The adapter exposes the LSP surface specified in `specs/lsp.md`
|
|
7
|
+
// (publishDiagnostics, completion, hover, definition, references) plus
|
|
8
|
+
// the lifecycle bits a browser IDE needs (initialize, didOpen,
|
|
9
|
+
// didChange, didClose, shutdown / dispose).
|
|
10
|
+
import { CompletionRequest, DefinitionRequest, DidChangeTextDocumentNotification, DidCloseTextDocumentNotification, DidOpenTextDocumentNotification, HoverRequest, InitializedNotification, InitializeRequest, PublishDiagnosticsNotification, ReferencesRequest, TextDocumentSyncKind, } from 'vscode-languageserver-protocol';
|
|
11
|
+
import { createProtocolConnection } from 'vscode-languageserver-protocol/browser.js';
|
|
12
|
+
import { BrowserMessageReader, BrowserMessageWriter, } from './message-bridge.js';
|
|
13
|
+
/**
|
|
14
|
+
* Build a Nowline LSP client bound to the supplied Worker (or
|
|
15
|
+
* MessagePort). The client autonegotiates the LSP `initialize`
|
|
16
|
+
* handshake on construction and resolves the returned object once the
|
|
17
|
+
* server has reported its capabilities.
|
|
18
|
+
*
|
|
19
|
+
* The returned `Promise` rejects if the server reports a
|
|
20
|
+
* non-incremental `textDocument/sync` capability — the wire-protocol
|
|
21
|
+
* guard from `specs/lsp.md` § Browser worker packaging.
|
|
22
|
+
*/
|
|
23
|
+
export async function createNowlineLanguageClient(options) {
|
|
24
|
+
const transport = options.transport ?? {
|
|
25
|
+
reader: new BrowserMessageReader(options.worker),
|
|
26
|
+
writer: new BrowserMessageWriter(options.worker),
|
|
27
|
+
};
|
|
28
|
+
const connection = createProtocolConnection(transport.reader, transport.writer);
|
|
29
|
+
connection.listen();
|
|
30
|
+
const initParams = {
|
|
31
|
+
processId: null,
|
|
32
|
+
rootUri: options.rootUri ?? null,
|
|
33
|
+
capabilities: {
|
|
34
|
+
textDocument: {
|
|
35
|
+
synchronization: { dynamicRegistration: false, willSave: false, didSave: false },
|
|
36
|
+
publishDiagnostics: { relatedInformation: false },
|
|
37
|
+
completion: { completionItem: { snippetSupport: false } },
|
|
38
|
+
hover: { contentFormat: ['markdown', 'plaintext'] },
|
|
39
|
+
definition: {},
|
|
40
|
+
references: {},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
workspaceFolders: null,
|
|
44
|
+
};
|
|
45
|
+
const initResult = await connection.sendRequest(InitializeRequest.type, initParams);
|
|
46
|
+
const capabilities = initResult.capabilities;
|
|
47
|
+
const sync = capabilities.textDocumentSync;
|
|
48
|
+
const kind = typeof sync === 'object' && sync !== null ? sync.change : sync;
|
|
49
|
+
if (kind !== TextDocumentSyncKind.Incremental) {
|
|
50
|
+
await connection.dispose();
|
|
51
|
+
throw new Error(`@nowline/lsp-worker: server advertised textDocument/sync = ${kind ?? 'undefined'}, ` +
|
|
52
|
+
`expected Incremental (${TextDocumentSyncKind.Incremental}). ` +
|
|
53
|
+
'Whole-document didChange semantics are not supported by this client.');
|
|
54
|
+
}
|
|
55
|
+
// sendNotification returns a Promise that resolves when the writer
|
|
56
|
+
// flushes; we deliberately fire-and-forget here. The init handshake
|
|
57
|
+
// is already awaited above, so any subsequent notify is timing-only.
|
|
58
|
+
void connection.sendNotification(InitializedNotification.type, {});
|
|
59
|
+
const diagListeners = new Set();
|
|
60
|
+
connection.onNotification(PublishDiagnosticsNotification.type, (params) => {
|
|
61
|
+
for (const l of diagListeners) {
|
|
62
|
+
try {
|
|
63
|
+
l(params);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error('[nowline-lsp-worker] diagnostics listener threw:', err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
didOpen({ uri, languageId = 'nowline', version = 1, text }) {
|
|
72
|
+
// Fire-and-forget: notifications have no response, and the
|
|
73
|
+
// wire ordering between sendNotification calls is preserved
|
|
74
|
+
// by the underlying MessageWriter, so awaiting the flush
|
|
75
|
+
// would only stall callers without adding correctness.
|
|
76
|
+
void connection.sendNotification(DidOpenTextDocumentNotification.type, {
|
|
77
|
+
textDocument: { uri, languageId, version, text },
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
didChange({ uri, version, changes }) {
|
|
81
|
+
for (const change of changes) {
|
|
82
|
+
if (!('range' in change)) {
|
|
83
|
+
throw new Error('@nowline/lsp-worker: didChange requires a range + text delta — ' +
|
|
84
|
+
'whole-document updates are rejected per TextDocumentSyncKind.Incremental.');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
void connection.sendNotification(DidChangeTextDocumentNotification.type, {
|
|
88
|
+
textDocument: { uri, version },
|
|
89
|
+
contentChanges: changes,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
didClose(uri) {
|
|
93
|
+
void connection.sendNotification(DidCloseTextDocumentNotification.type, {
|
|
94
|
+
textDocument: { uri },
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
onDiagnostics(listener) {
|
|
98
|
+
diagListeners.add(listener);
|
|
99
|
+
return {
|
|
100
|
+
dispose() {
|
|
101
|
+
diagListeners.delete(listener);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
async completion(uri, position) {
|
|
106
|
+
const result = await connection.sendRequest(CompletionRequest.type, {
|
|
107
|
+
textDocument: { uri },
|
|
108
|
+
position,
|
|
109
|
+
});
|
|
110
|
+
if (!result)
|
|
111
|
+
return [];
|
|
112
|
+
return Array.isArray(result) ? result : result.items;
|
|
113
|
+
},
|
|
114
|
+
async hover(uri, position) {
|
|
115
|
+
return (await connection.sendRequest(HoverRequest.type, {
|
|
116
|
+
textDocument: { uri },
|
|
117
|
+
position,
|
|
118
|
+
}));
|
|
119
|
+
},
|
|
120
|
+
async definition(uri, position) {
|
|
121
|
+
return (await connection.sendRequest(DefinitionRequest.type, {
|
|
122
|
+
textDocument: { uri },
|
|
123
|
+
position,
|
|
124
|
+
}));
|
|
125
|
+
},
|
|
126
|
+
async references(uri, position) {
|
|
127
|
+
const params = {
|
|
128
|
+
textDocument: { uri },
|
|
129
|
+
position,
|
|
130
|
+
context: { includeDeclaration: true },
|
|
131
|
+
};
|
|
132
|
+
return ((await connection.sendRequest(ReferencesRequest.type, params)) ??
|
|
133
|
+
[]);
|
|
134
|
+
},
|
|
135
|
+
async dispose() {
|
|
136
|
+
diagListeners.clear();
|
|
137
|
+
try {
|
|
138
|
+
await connection.sendRequest('shutdown', undefined);
|
|
139
|
+
await connection.sendNotification('exit', undefined);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Best-effort; the worker may have already terminated.
|
|
143
|
+
}
|
|
144
|
+
connection.dispose();
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type CreateNowlineLanguageClientOptions, createNowlineLanguageClient, type NowlineLanguageClient, } from './client.js';
|
|
2
|
+
export { BrowserMessageReader, BrowserMessageWriter, type MessageReader, type MessageWriter, } from './message-bridge.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,kCAAkC,EACvC,2BAA2B,EAC3B,KAAK,qBAAqB,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Default export of `@nowline/lsp-worker` is the main-thread client
|
|
2
|
+
// adapter. Consumers spawning the worker import the worker entry
|
|
3
|
+
// explicitly via `@nowline/lsp-worker/worker`.
|
|
4
|
+
export { createNowlineLanguageClient, } from './client.js';
|
|
5
|
+
export { BrowserMessageReader, BrowserMessageWriter, } from './message-bridge.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,iEAAiE;AACjE,+CAA+C;AAE/C,OAAO,EAEH,2BAA2B,GAE9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,oBAAoB,EACpB,oBAAoB,GAGvB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-bridge.d.ts","sourceRoot":"","sources":["../src/message-bridge.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,GACrB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Bridge between LSP JSON-RPC and `postMessage`-style transports
|
|
2
|
+
// (Worker, MessagePort, DedicatedWorkerGlobalScope, MessageChannel,
|
|
3
|
+
// etc.). Thin re-export of the browser primitives `vscode-jsonrpc`
|
|
4
|
+
// already ships so consumers don't have to depend on it directly and
|
|
5
|
+
// so we have a single seam to swap in a custom implementation later
|
|
6
|
+
// if tree-shaking ever becomes a concern.
|
|
7
|
+
export { BrowserMessageReader, BrowserMessageWriter, } from 'vscode-jsonrpc/browser.js';
|
|
8
|
+
//# sourceMappingURL=message-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-bridge.js","sourceRoot":"","sources":["../src/message-bridge.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,oEAAoE;AACpE,mEAAmE;AACnE,qEAAqE;AACrE,oEAAoE;AACpE,0CAA0C;AAE1C,OAAO,EACH,oBAAoB,EACpB,oBAAoB,GAGvB,MAAM,2BAA2B,CAAC"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type MessageReader, type MessageWriter } from './message-bridge.js';
|
|
2
|
+
/**
|
|
3
|
+
* Boot the Nowline language server inside a Dedicated Worker scope.
|
|
4
|
+
* Call this from a Web Worker entry script:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { startNowlineLspWorker } from '@nowline/lsp-worker/worker';
|
|
8
|
+
* startNowlineLspWorker();
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* The worker bridge is hard-coded to `self` for the dedicated worker
|
|
12
|
+
* case; multi-port / shared-worker setups can call
|
|
13
|
+
* `startNowlineLspWorkerOn(reader, writer)` with their own
|
|
14
|
+
* reader/writer pair instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function startNowlineLspWorker(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Lower-level entry: feed the LSP a pre-built reader/writer pair so
|
|
19
|
+
* tests (and consumers that own their own transport) can drive the
|
|
20
|
+
* server without spinning up a real `Worker`. Any `MessageReader` /
|
|
21
|
+
* `MessageWriter` pair from `vscode-jsonrpc` works — including
|
|
22
|
+
* `BrowserMessageReader`/`Writer` over a `MessageChannel` `MessagePort`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function startNowlineLspWorkerOn(reader: MessageReader, writer: MessageWriter): void;
|
|
25
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAsBA,OAAO,EAGH,KAAK,aAAa,EAClB,KAAK,aAAa,EACrB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAO1F"}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Worker-side entry for the browser-packaged Nowline LSP. Boots the
|
|
2
|
+
// Langium-based language server, wires its transport to the worker's
|
|
3
|
+
// `postMessage` / `addEventListener('message', ...)` pair via
|
|
4
|
+
// `BrowserMessageReader` / `BrowserMessageWriter`, and locks the
|
|
5
|
+
// `textDocument/sync` capability to incremental (range delta) updates.
|
|
6
|
+
//
|
|
7
|
+
// Consumers spawn this worker from the main thread (e.g.
|
|
8
|
+
// `new Worker(workerUrl, { type: 'module' })`) and then wrap a
|
|
9
|
+
// `createNowlineLanguageClient({ worker })` around it from
|
|
10
|
+
// `./client.ts` to get a CodeMirror-friendly API.
|
|
11
|
+
//
|
|
12
|
+
// File system: `EmptyFileSystem` from `langium` — the worker can't
|
|
13
|
+
// read disk, and the Nowline include resolver routes through its own
|
|
14
|
+
// injected `readFile` callback anyway. Any LSP request that would
|
|
15
|
+
// trigger a default-module `FileSystemProvider.readFile` call against
|
|
16
|
+
// the empty provider returns `''`, which Langium treats as a missing
|
|
17
|
+
// document rather than crashing.
|
|
18
|
+
import { createNowlineLspServices } from '@nowline/lsp';
|
|
19
|
+
import { EmptyFileSystem } from 'langium';
|
|
20
|
+
import { startLanguageServer } from 'langium/lsp';
|
|
21
|
+
import { createConnection } from 'vscode-languageserver/browser.js';
|
|
22
|
+
import { BrowserMessageReader, BrowserMessageWriter, } from './message-bridge.js';
|
|
23
|
+
/**
|
|
24
|
+
* Boot the Nowline language server inside a Dedicated Worker scope.
|
|
25
|
+
* Call this from a Web Worker entry script:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { startNowlineLspWorker } from '@nowline/lsp-worker/worker';
|
|
29
|
+
* startNowlineLspWorker();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The worker bridge is hard-coded to `self` for the dedicated worker
|
|
33
|
+
* case; multi-port / shared-worker setups can call
|
|
34
|
+
* `startNowlineLspWorkerOn(reader, writer)` with their own
|
|
35
|
+
* reader/writer pair instead.
|
|
36
|
+
*/
|
|
37
|
+
export function startNowlineLspWorker() {
|
|
38
|
+
// `self` inside a worker is the DedicatedWorkerGlobalScope, which
|
|
39
|
+
// `BrowserMessageReader`/`Writer` accept directly.
|
|
40
|
+
const reader = new BrowserMessageReader(self);
|
|
41
|
+
const writer = new BrowserMessageWriter(self);
|
|
42
|
+
startNowlineLspWorkerOn(reader, writer);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lower-level entry: feed the LSP a pre-built reader/writer pair so
|
|
46
|
+
* tests (and consumers that own their own transport) can drive the
|
|
47
|
+
* server without spinning up a real `Worker`. Any `MessageReader` /
|
|
48
|
+
* `MessageWriter` pair from `vscode-jsonrpc` works — including
|
|
49
|
+
* `BrowserMessageReader`/`Writer` over a `MessageChannel` `MessagePort`.
|
|
50
|
+
*/
|
|
51
|
+
export function startNowlineLspWorkerOn(reader, writer) {
|
|
52
|
+
const connection = createConnection(reader, writer);
|
|
53
|
+
const { shared } = createNowlineLspServices({
|
|
54
|
+
connection,
|
|
55
|
+
fileSystemProvider: EmptyFileSystem.fileSystemProvider,
|
|
56
|
+
});
|
|
57
|
+
startLanguageServer(shared);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,qEAAqE;AACrE,8DAA8D;AAC9D,iEAAiE;AACjE,uEAAuE;AACvE,EAAE;AACF,yDAAyD;AACzD,+DAA+D;AAC/D,2DAA2D;AAC3D,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,qEAAqE;AACrE,kEAAkE;AAClE,sEAAsE;AACtE,qEAAqE;AACrE,iCAAiC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EACH,oBAAoB,EACpB,oBAAoB,GAGvB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB;IACjC,kEAAkE;IAClE,mDAAmD;IACnD,MAAM,MAAM,GAAG,IAAI,oBAAoB,CAAC,IAAkC,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,IAAI,oBAAoB,CAAC,IAAkC,CAAC,CAAC;IAC5E,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAqB,EAAE,MAAqB;IAChF,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,EAAE,GAAG,wBAAwB,CAAC;QACxC,UAAU;QACV,kBAAkB,EAAE,eAAe,CAAC,kBAAkB;KACzD,CAAC,CAAC;IACH,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nowline/lsp-worker",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Web Worker packaging of the Nowline LSP. Ships a worker entry that wires @nowline/lsp over postMessage, plus a CodeMirror-friendly client adapter for browser IDEs.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22",
|
|
8
|
+
"pnpm": ">=11"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./worker": {
|
|
20
|
+
"types": "./dist/worker.d.ts",
|
|
21
|
+
"import": "./dist/worker.js"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./dist/client.d.ts",
|
|
25
|
+
"import": "./dist/client.js"
|
|
26
|
+
},
|
|
27
|
+
"./message-bridge": {
|
|
28
|
+
"types": "./dist/message-bridge.d.ts",
|
|
29
|
+
"import": "./dist/message-bridge.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/",
|
|
34
|
+
"src/"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/lolay/nowline.git",
|
|
39
|
+
"directory": "packages/lsp-worker"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/lolay/nowline",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/lolay/nowline/issues"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"nowline",
|
|
47
|
+
"lsp",
|
|
48
|
+
"language-server",
|
|
49
|
+
"web-worker",
|
|
50
|
+
"browser"
|
|
51
|
+
],
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"langium": "~4.2.4",
|
|
54
|
+
"vscode-jsonrpc": "8.2.0",
|
|
55
|
+
"vscode-languageserver": "~9.0.1",
|
|
56
|
+
"vscode-languageserver-protocol": "~3.17.5",
|
|
57
|
+
"@nowline/core": "0.4.0",
|
|
58
|
+
"@nowline/lsp": "0.4.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^25.9.1",
|
|
62
|
+
"happy-dom": "^20.9.0",
|
|
63
|
+
"typescript": "^6.0.3",
|
|
64
|
+
"vitest": "^4.1.7"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsc -b tsconfig.json",
|
|
68
|
+
"watch": "tsc -b tsconfig.json --watch",
|
|
69
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"test:watch": "vitest"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Main-thread client for the Nowline LSP worker. Wraps `vscode-jsonrpc`'s
|
|
2
|
+
// `MessageConnection` into a tiny imperative API that browser editors
|
|
3
|
+
// (CodeMirror, Monaco, raw textareas, etc.) can drive without depending
|
|
4
|
+
// on `vscode-languageclient` (which assumes a VS Code host).
|
|
5
|
+
//
|
|
6
|
+
// The adapter exposes the LSP surface specified in `specs/lsp.md`
|
|
7
|
+
// (publishDiagnostics, completion, hover, definition, references) plus
|
|
8
|
+
// the lifecycle bits a browser IDE needs (initialize, didOpen,
|
|
9
|
+
// didChange, didClose, shutdown / dispose).
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
type CompletionItem,
|
|
13
|
+
CompletionRequest,
|
|
14
|
+
type Definition,
|
|
15
|
+
DefinitionRequest,
|
|
16
|
+
DidChangeTextDocumentNotification,
|
|
17
|
+
DidCloseTextDocumentNotification,
|
|
18
|
+
DidOpenTextDocumentNotification,
|
|
19
|
+
type Hover,
|
|
20
|
+
HoverRequest,
|
|
21
|
+
InitializedNotification,
|
|
22
|
+
type InitializeParams,
|
|
23
|
+
InitializeRequest,
|
|
24
|
+
type InitializeResult,
|
|
25
|
+
type Location,
|
|
26
|
+
type Position,
|
|
27
|
+
type ProtocolConnection,
|
|
28
|
+
PublishDiagnosticsNotification,
|
|
29
|
+
type PublishDiagnosticsParams,
|
|
30
|
+
type ReferenceParams,
|
|
31
|
+
ReferencesRequest,
|
|
32
|
+
type ServerCapabilities,
|
|
33
|
+
type TextDocumentContentChangeEvent,
|
|
34
|
+
TextDocumentSyncKind,
|
|
35
|
+
} from 'vscode-languageserver-protocol';
|
|
36
|
+
import { createProtocolConnection } from 'vscode-languageserver-protocol/browser.js';
|
|
37
|
+
import {
|
|
38
|
+
BrowserMessageReader,
|
|
39
|
+
BrowserMessageWriter,
|
|
40
|
+
type MessageReader,
|
|
41
|
+
type MessageWriter,
|
|
42
|
+
} from './message-bridge.js';
|
|
43
|
+
|
|
44
|
+
export interface CreateNowlineLanguageClientOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Worker handle (or anything matching the
|
|
47
|
+
* `BrowserMessageReader/Writer` shape — `MessagePort`,
|
|
48
|
+
* `DedicatedWorkerGlobalScope`). The client wires both the
|
|
49
|
+
* incoming reader and the outgoing writer against this single
|
|
50
|
+
* port, matching the dedicated-worker / message-channel pattern.
|
|
51
|
+
*/
|
|
52
|
+
worker: Worker | MessagePort;
|
|
53
|
+
/**
|
|
54
|
+
* Caller can pre-build a transport and skip the default
|
|
55
|
+
* `BrowserMessageReader/Writer` (useful for tests + alternate
|
|
56
|
+
* transports like SharedWorker). When supplied, `worker` is
|
|
57
|
+
* ignored.
|
|
58
|
+
*/
|
|
59
|
+
transport?: { reader: MessageReader; writer: MessageWriter };
|
|
60
|
+
/**
|
|
61
|
+
* Optional root URI for the workspace. Browser IDEs usually leave
|
|
62
|
+
* this as the synthetic default; only set if a virtual workspace
|
|
63
|
+
* is genuinely backed by a hierarchy worth advertising.
|
|
64
|
+
*/
|
|
65
|
+
rootUri?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface NowlineLanguageClient {
|
|
69
|
+
/** Open a document with the server. Must be called before any other request. */
|
|
70
|
+
didOpen(params: { uri: string; languageId?: string; version?: number; text: string }): void;
|
|
71
|
+
/**
|
|
72
|
+
* Push an incremental change. Per spec, callers must send a
|
|
73
|
+
* `range` + `text` pair — whole-document `text` updates are
|
|
74
|
+
* rejected by the underlying server because it advertises
|
|
75
|
+
* `TextDocumentSyncKind.Incremental`.
|
|
76
|
+
*/
|
|
77
|
+
didChange(params: {
|
|
78
|
+
uri: string;
|
|
79
|
+
version: number;
|
|
80
|
+
changes: TextDocumentContentChangeEvent[];
|
|
81
|
+
}): void;
|
|
82
|
+
didClose(uri: string): void;
|
|
83
|
+
onDiagnostics(listener: (params: PublishDiagnosticsParams) => void): { dispose(): void };
|
|
84
|
+
completion(uri: string, position: Position): Promise<CompletionItem[]>;
|
|
85
|
+
hover(uri: string, position: Position): Promise<Hover | null>;
|
|
86
|
+
definition(uri: string, position: Position): Promise<Definition | null>;
|
|
87
|
+
references(uri: string, position: Position): Promise<Location[]>;
|
|
88
|
+
/** Discard listeners and close the underlying connection. */
|
|
89
|
+
dispose(): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Build a Nowline LSP client bound to the supplied Worker (or
|
|
94
|
+
* MessagePort). The client autonegotiates the LSP `initialize`
|
|
95
|
+
* handshake on construction and resolves the returned object once the
|
|
96
|
+
* server has reported its capabilities.
|
|
97
|
+
*
|
|
98
|
+
* The returned `Promise` rejects if the server reports a
|
|
99
|
+
* non-incremental `textDocument/sync` capability — the wire-protocol
|
|
100
|
+
* guard from `specs/lsp.md` § Browser worker packaging.
|
|
101
|
+
*/
|
|
102
|
+
export async function createNowlineLanguageClient(
|
|
103
|
+
options: CreateNowlineLanguageClientOptions,
|
|
104
|
+
): Promise<NowlineLanguageClient> {
|
|
105
|
+
const transport = options.transport ?? {
|
|
106
|
+
reader: new BrowserMessageReader(options.worker),
|
|
107
|
+
writer: new BrowserMessageWriter(options.worker),
|
|
108
|
+
};
|
|
109
|
+
const connection: ProtocolConnection = createProtocolConnection(
|
|
110
|
+
transport.reader,
|
|
111
|
+
transport.writer,
|
|
112
|
+
);
|
|
113
|
+
connection.listen();
|
|
114
|
+
|
|
115
|
+
const initParams: InitializeParams = {
|
|
116
|
+
processId: null,
|
|
117
|
+
rootUri: options.rootUri ?? null,
|
|
118
|
+
capabilities: {
|
|
119
|
+
textDocument: {
|
|
120
|
+
synchronization: { dynamicRegistration: false, willSave: false, didSave: false },
|
|
121
|
+
publishDiagnostics: { relatedInformation: false },
|
|
122
|
+
completion: { completionItem: { snippetSupport: false } },
|
|
123
|
+
hover: { contentFormat: ['markdown', 'plaintext'] },
|
|
124
|
+
definition: {},
|
|
125
|
+
references: {},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
workspaceFolders: null,
|
|
129
|
+
};
|
|
130
|
+
const initResult: InitializeResult = await connection.sendRequest(
|
|
131
|
+
InitializeRequest.type,
|
|
132
|
+
initParams,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const capabilities: ServerCapabilities = initResult.capabilities;
|
|
136
|
+
const sync = capabilities.textDocumentSync;
|
|
137
|
+
const kind = typeof sync === 'object' && sync !== null ? sync.change : sync;
|
|
138
|
+
if (kind !== TextDocumentSyncKind.Incremental) {
|
|
139
|
+
await connection.dispose();
|
|
140
|
+
throw new Error(
|
|
141
|
+
`@nowline/lsp-worker: server advertised textDocument/sync = ${kind ?? 'undefined'}, ` +
|
|
142
|
+
`expected Incremental (${TextDocumentSyncKind.Incremental}). ` +
|
|
143
|
+
'Whole-document didChange semantics are not supported by this client.',
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// sendNotification returns a Promise that resolves when the writer
|
|
148
|
+
// flushes; we deliberately fire-and-forget here. The init handshake
|
|
149
|
+
// is already awaited above, so any subsequent notify is timing-only.
|
|
150
|
+
void connection.sendNotification(InitializedNotification.type, {});
|
|
151
|
+
|
|
152
|
+
const diagListeners = new Set<(params: PublishDiagnosticsParams) => void>();
|
|
153
|
+
connection.onNotification(PublishDiagnosticsNotification.type, (params) => {
|
|
154
|
+
for (const l of diagListeners) {
|
|
155
|
+
try {
|
|
156
|
+
l(params);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error('[nowline-lsp-worker] diagnostics listener threw:', err);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
didOpen({ uri, languageId = 'nowline', version = 1, text }) {
|
|
165
|
+
// Fire-and-forget: notifications have no response, and the
|
|
166
|
+
// wire ordering between sendNotification calls is preserved
|
|
167
|
+
// by the underlying MessageWriter, so awaiting the flush
|
|
168
|
+
// would only stall callers without adding correctness.
|
|
169
|
+
void connection.sendNotification(DidOpenTextDocumentNotification.type, {
|
|
170
|
+
textDocument: { uri, languageId, version, text },
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
didChange({ uri, version, changes }) {
|
|
174
|
+
for (const change of changes) {
|
|
175
|
+
if (!('range' in change)) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'@nowline/lsp-worker: didChange requires a range + text delta — ' +
|
|
178
|
+
'whole-document updates are rejected per TextDocumentSyncKind.Incremental.',
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
void connection.sendNotification(DidChangeTextDocumentNotification.type, {
|
|
183
|
+
textDocument: { uri, version },
|
|
184
|
+
contentChanges: changes,
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
didClose(uri) {
|
|
188
|
+
void connection.sendNotification(DidCloseTextDocumentNotification.type, {
|
|
189
|
+
textDocument: { uri },
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
onDiagnostics(listener) {
|
|
193
|
+
diagListeners.add(listener);
|
|
194
|
+
return {
|
|
195
|
+
dispose() {
|
|
196
|
+
diagListeners.delete(listener);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
async completion(uri, position) {
|
|
201
|
+
const result = await connection.sendRequest(CompletionRequest.type, {
|
|
202
|
+
textDocument: { uri },
|
|
203
|
+
position,
|
|
204
|
+
});
|
|
205
|
+
if (!result) return [];
|
|
206
|
+
return Array.isArray(result) ? result : result.items;
|
|
207
|
+
},
|
|
208
|
+
async hover(uri, position) {
|
|
209
|
+
return (await connection.sendRequest(HoverRequest.type, {
|
|
210
|
+
textDocument: { uri },
|
|
211
|
+
position,
|
|
212
|
+
})) as Hover | null;
|
|
213
|
+
},
|
|
214
|
+
async definition(uri, position) {
|
|
215
|
+
return (await connection.sendRequest(DefinitionRequest.type, {
|
|
216
|
+
textDocument: { uri },
|
|
217
|
+
position,
|
|
218
|
+
})) as Definition | null;
|
|
219
|
+
},
|
|
220
|
+
async references(uri, position) {
|
|
221
|
+
const params: ReferenceParams = {
|
|
222
|
+
textDocument: { uri },
|
|
223
|
+
position,
|
|
224
|
+
context: { includeDeclaration: true },
|
|
225
|
+
};
|
|
226
|
+
return ((await connection.sendRequest(ReferencesRequest.type, params)) ??
|
|
227
|
+
[]) as Location[];
|
|
228
|
+
},
|
|
229
|
+
async dispose() {
|
|
230
|
+
diagListeners.clear();
|
|
231
|
+
try {
|
|
232
|
+
await connection.sendRequest('shutdown', undefined);
|
|
233
|
+
await connection.sendNotification('exit', undefined);
|
|
234
|
+
} catch {
|
|
235
|
+
// Best-effort; the worker may have already terminated.
|
|
236
|
+
}
|
|
237
|
+
connection.dispose();
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Default export of `@nowline/lsp-worker` is the main-thread client
|
|
2
|
+
// adapter. Consumers spawning the worker import the worker entry
|
|
3
|
+
// explicitly via `@nowline/lsp-worker/worker`.
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
type CreateNowlineLanguageClientOptions,
|
|
7
|
+
createNowlineLanguageClient,
|
|
8
|
+
type NowlineLanguageClient,
|
|
9
|
+
} from './client.js';
|
|
10
|
+
export {
|
|
11
|
+
BrowserMessageReader,
|
|
12
|
+
BrowserMessageWriter,
|
|
13
|
+
type MessageReader,
|
|
14
|
+
type MessageWriter,
|
|
15
|
+
} from './message-bridge.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Bridge between LSP JSON-RPC and `postMessage`-style transports
|
|
2
|
+
// (Worker, MessagePort, DedicatedWorkerGlobalScope, MessageChannel,
|
|
3
|
+
// etc.). Thin re-export of the browser primitives `vscode-jsonrpc`
|
|
4
|
+
// already ships so consumers don't have to depend on it directly and
|
|
5
|
+
// so we have a single seam to swap in a custom implementation later
|
|
6
|
+
// if tree-shaking ever becomes a concern.
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
BrowserMessageReader,
|
|
10
|
+
BrowserMessageWriter,
|
|
11
|
+
type MessageReader,
|
|
12
|
+
type MessageWriter,
|
|
13
|
+
} from 'vscode-jsonrpc/browser.js';
|
package/src/worker.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Worker-side entry for the browser-packaged Nowline LSP. Boots the
|
|
2
|
+
// Langium-based language server, wires its transport to the worker's
|
|
3
|
+
// `postMessage` / `addEventListener('message', ...)` pair via
|
|
4
|
+
// `BrowserMessageReader` / `BrowserMessageWriter`, and locks the
|
|
5
|
+
// `textDocument/sync` capability to incremental (range delta) updates.
|
|
6
|
+
//
|
|
7
|
+
// Consumers spawn this worker from the main thread (e.g.
|
|
8
|
+
// `new Worker(workerUrl, { type: 'module' })`) and then wrap a
|
|
9
|
+
// `createNowlineLanguageClient({ worker })` around it from
|
|
10
|
+
// `./client.ts` to get a CodeMirror-friendly API.
|
|
11
|
+
//
|
|
12
|
+
// File system: `EmptyFileSystem` from `langium` — the worker can't
|
|
13
|
+
// read disk, and the Nowline include resolver routes through its own
|
|
14
|
+
// injected `readFile` callback anyway. Any LSP request that would
|
|
15
|
+
// trigger a default-module `FileSystemProvider.readFile` call against
|
|
16
|
+
// the empty provider returns `''`, which Langium treats as a missing
|
|
17
|
+
// document rather than crashing.
|
|
18
|
+
|
|
19
|
+
import { createNowlineLspServices } from '@nowline/lsp';
|
|
20
|
+
import { EmptyFileSystem } from 'langium';
|
|
21
|
+
import { startLanguageServer } from 'langium/lsp';
|
|
22
|
+
import { createConnection } from 'vscode-languageserver/browser.js';
|
|
23
|
+
import {
|
|
24
|
+
BrowserMessageReader,
|
|
25
|
+
BrowserMessageWriter,
|
|
26
|
+
type MessageReader,
|
|
27
|
+
type MessageWriter,
|
|
28
|
+
} from './message-bridge.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Boot the Nowline language server inside a Dedicated Worker scope.
|
|
32
|
+
* Call this from a Web Worker entry script:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { startNowlineLspWorker } from '@nowline/lsp-worker/worker';
|
|
36
|
+
* startNowlineLspWorker();
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* The worker bridge is hard-coded to `self` for the dedicated worker
|
|
40
|
+
* case; multi-port / shared-worker setups can call
|
|
41
|
+
* `startNowlineLspWorkerOn(reader, writer)` with their own
|
|
42
|
+
* reader/writer pair instead.
|
|
43
|
+
*/
|
|
44
|
+
export function startNowlineLspWorker(): void {
|
|
45
|
+
// `self` inside a worker is the DedicatedWorkerGlobalScope, which
|
|
46
|
+
// `BrowserMessageReader`/`Writer` accept directly.
|
|
47
|
+
const reader = new BrowserMessageReader(self as DedicatedWorkerGlobalScope);
|
|
48
|
+
const writer = new BrowserMessageWriter(self as DedicatedWorkerGlobalScope);
|
|
49
|
+
startNowlineLspWorkerOn(reader, writer);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Lower-level entry: feed the LSP a pre-built reader/writer pair so
|
|
54
|
+
* tests (and consumers that own their own transport) can drive the
|
|
55
|
+
* server without spinning up a real `Worker`. Any `MessageReader` /
|
|
56
|
+
* `MessageWriter` pair from `vscode-jsonrpc` works — including
|
|
57
|
+
* `BrowserMessageReader`/`Writer` over a `MessageChannel` `MessagePort`.
|
|
58
|
+
*/
|
|
59
|
+
export function startNowlineLspWorkerOn(reader: MessageReader, writer: MessageWriter): void {
|
|
60
|
+
const connection = createConnection(reader, writer);
|
|
61
|
+
const { shared } = createNowlineLspServices({
|
|
62
|
+
connection,
|
|
63
|
+
fileSystemProvider: EmptyFileSystem.fileSystemProvider,
|
|
64
|
+
});
|
|
65
|
+
startLanguageServer(shared);
|
|
66
|
+
}
|