@lensmap/language-server 0.1.0 → 0.2.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/README.md +1 -1
- package/dist/preview/assets/playground-BCY9v6Ap.js +215 -0
- package/dist/preview/assets/preview-BRCvwAxB.js +1 -0
- package/dist/preview/assets/{preview-fhnbHE6T.css → preview-DDOSTiJj.css} +1 -1
- package/dist/preview/assets/styles-9bHR-mQh.css +1 -0
- package/dist/preview/assets/styles-Bnie2-Dn.js +190 -0
- package/dist/preview/index.html +3 -3
- package/dist/preview/preview.html +4 -4
- package/dist/server.js +60 -3
- package/package.json +10 -9
- package/LICENSE +0 -21
- package/dist/preview/assets/playground-BtGyjknt.js +0 -383
- package/dist/preview/assets/preview-B84it-Jd.js +0 -1
- package/dist/preview/assets/styles-D4WWbpX1.css +0 -1
- package/dist/preview/assets/styles-HT2Xrmtw.js +0 -22
package/dist/preview/index.html
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta name="theme-color" content="#10171f" />
|
|
7
7
|
<title>Lensmap · Spatial lens lab</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/playground-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/assets/styles-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/styles-
|
|
8
|
+
<script type="module" crossorigin src="/assets/playground-BCY9v6Ap.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/styles-Bnie2-Dn.js">
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/styles-9bHR-mQh.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
<meta name="theme-color" content="#10171f" />
|
|
7
7
|
<meta name="referrer" content="no-referrer" />
|
|
8
8
|
<title>Lensmap · Editor preview</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/preview-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/styles-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="/assets/styles-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/preview-
|
|
9
|
+
<script type="module" crossorigin src="/assets/preview-BRCvwAxB.js"></script>
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/styles-Bnie2-Dn.js">
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/styles-9bHR-mQh.css">
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/preview-DDOSTiJj.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
package/dist/server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
|
2
2
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
3
3
|
import { createServer, } from "node:http";
|
|
4
4
|
import { extname, resolve, sep } from "node:path";
|
|
5
|
-
import { DocumentSession, positionToOffset, } from "@lensmap/document";
|
|
5
|
+
import { ConnectionTypeSchema, connectionWording, DocumentSession, positionToOffset, } from "@lensmap/document";
|
|
6
6
|
import { CodeActionKind, CompletionItemKind, createConnection, StreamMessageReader, StreamMessageWriter, TextDocumentSyncKind, } from "vscode-languageserver/node";
|
|
7
7
|
class HttpError extends Error {
|
|
8
8
|
status;
|
|
@@ -87,6 +87,7 @@ export async function startServer(options) {
|
|
|
87
87
|
let closed = false;
|
|
88
88
|
let shutdown = false;
|
|
89
89
|
let canApply = false;
|
|
90
|
+
let canShowDocument = false;
|
|
90
91
|
let writeQueue = Promise.resolve();
|
|
91
92
|
let closePromise;
|
|
92
93
|
let origin = "";
|
|
@@ -317,7 +318,12 @@ export async function startServer(options) {
|
|
|
317
318
|
return;
|
|
318
319
|
}
|
|
319
320
|
if (method === "POST" &&
|
|
320
|
-
[
|
|
321
|
+
[
|
|
322
|
+
"/api/content",
|
|
323
|
+
"/api/reveal",
|
|
324
|
+
"/api/centre",
|
|
325
|
+
"/api/open-destination",
|
|
326
|
+
].includes(url.pathname)) {
|
|
321
327
|
const payload = await body(request);
|
|
322
328
|
if (url.pathname === "/api/content") {
|
|
323
329
|
const result = await edit(payload);
|
|
@@ -332,6 +338,47 @@ export async function startServer(options) {
|
|
|
332
338
|
json(response, 200, await reveal(text(payload.uri), text(payload.key)));
|
|
333
339
|
return;
|
|
334
340
|
}
|
|
341
|
+
if (url.pathname === "/api/open-destination") {
|
|
342
|
+
if (Object.keys(payload).some((key) => !["uri", "key", "baseRevision", "attachmentId"].includes(key)))
|
|
343
|
+
throw new HttpError(400, "Provide attached thought identity, not an opening URL.");
|
|
344
|
+
const uri = text(payload.uri);
|
|
345
|
+
const snapshot = current(uri).session.snapshot();
|
|
346
|
+
if (payload.baseRevision !== snapshot.revision ||
|
|
347
|
+
typeof payload.attachmentId !== "string" ||
|
|
348
|
+
payload.attachmentId !== snapshot.attachmentId)
|
|
349
|
+
throw new HttpError(409, "The source or attachment changed; select the portal again.");
|
|
350
|
+
const destination = snapshot.graph?.nodes.find((node) => node.key === text(payload.key))?.destination;
|
|
351
|
+
if (destination?.kind !== "external_link")
|
|
352
|
+
throw new HttpError(404, "No external destination on this thought.");
|
|
353
|
+
if (Array.from(destination.url).some((c) => c.charCodeAt(0) <= 32 || c.charCodeAt(0) === 127))
|
|
354
|
+
throw new HttpError(400, "The destination address contains invalid whitespace or control characters.");
|
|
355
|
+
let target;
|
|
356
|
+
try {
|
|
357
|
+
target = new URL(destination.url, uri);
|
|
358
|
+
decodeURI(target.pathname);
|
|
359
|
+
decodeURIComponent(target.hash.slice(1));
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
throw new HttpError(400, "The destination address is invalid.");
|
|
363
|
+
}
|
|
364
|
+
if (!["http:", "https:", "file:"].includes(target.protocol) ||
|
|
365
|
+
target.username ||
|
|
366
|
+
target.password)
|
|
367
|
+
throw new HttpError(400, "This destination scheme or embedded credentials are unsupported.");
|
|
368
|
+
if (!canShowDocument)
|
|
369
|
+
throw new HttpError(501, "This editor does not provide a destination opener.");
|
|
370
|
+
// Let the editor handle URLs and files using its own preferences.
|
|
371
|
+
// The preview-launching OS opener is intentionally not reused.
|
|
372
|
+
const result = await connection.window.showDocument({
|
|
373
|
+
uri: target.href,
|
|
374
|
+
external: false,
|
|
375
|
+
takeFocus: true,
|
|
376
|
+
});
|
|
377
|
+
if (!result.success)
|
|
378
|
+
throw new HttpError(502, "The editor could not open this destination.");
|
|
379
|
+
json(response, 200, { opened: true });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
335
382
|
const key = focus(text(payload.uri), position(payload.position), true, typeof payload.baseRevision === "number"
|
|
336
383
|
? payload.baseRevision
|
|
337
384
|
: undefined);
|
|
@@ -417,6 +464,8 @@ export async function startServer(options) {
|
|
|
417
464
|
};
|
|
418
465
|
connection.onInitialize((params) => {
|
|
419
466
|
canApply = params.capabilities.workspace?.applyEdit === true;
|
|
467
|
+
canShowDocument =
|
|
468
|
+
params.capabilities.window?.showDocument?.support === true;
|
|
420
469
|
return {
|
|
421
470
|
capabilities: {
|
|
422
471
|
positionEncoding: "utf-16",
|
|
@@ -525,9 +574,17 @@ export async function startServer(options) {
|
|
|
525
574
|
});
|
|
526
575
|
connection.onCompletion(({ textDocument, position: at }) => {
|
|
527
576
|
const session = entries.get(textDocument.uri)?.session;
|
|
528
|
-
if (!session
|
|
577
|
+
if (!session)
|
|
529
578
|
return [];
|
|
530
579
|
const line = session.source.split(/\r?\n/)[at.line]?.slice(0, at.character) ?? "";
|
|
580
|
+
if (/^\s*(?:-\s*)?type:\s*[^#]*$/.test(line))
|
|
581
|
+
return ConnectionTypeSchema.options.map((type) => ({
|
|
582
|
+
label: type,
|
|
583
|
+
kind: CompletionItemKind.EnumMember,
|
|
584
|
+
detail: connectionWording(type, "outgoing"),
|
|
585
|
+
}));
|
|
586
|
+
if (!session.snapshot().valid || session.snapshot().pending)
|
|
587
|
+
return [];
|
|
531
588
|
if (!/^\s*(?:-\s*)?node_id:\s*[^#]*$/.test(line))
|
|
532
589
|
return [];
|
|
533
590
|
return (session.snapshot().graph?.nodes.flatMap((node) => node.id === undefined
|
package/package.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"name": "@lensmap/language-server",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Experimental Lensmap language server with an authenticated loopback browser preview",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public",
|
|
11
|
-
"tag": "
|
|
11
|
+
"tag": "latest",
|
|
12
12
|
"registry": "https://registry.npmjs.org/"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
@@ -29,18 +29,19 @@
|
|
|
29
29
|
"bin": {
|
|
30
30
|
"lensmap-lsp": "./dist/main.js"
|
|
31
31
|
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc && node build.ts",
|
|
34
|
+
"prepack": "pnpm -w exec turbo run build --filter=@lensmap/language-server",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run"
|
|
37
|
+
},
|
|
32
38
|
"dependencies": {
|
|
33
|
-
"@lensmap/document": "
|
|
39
|
+
"@lensmap/document": "workspace:*",
|
|
34
40
|
"vscode-languageserver": "11.0.0"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
43
|
"@types/node": "24.19.2",
|
|
38
44
|
"typescript": "7.0.2",
|
|
39
45
|
"vitest": "5.1.0"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "tsc && node build.ts",
|
|
43
|
-
"typecheck": "tsc --noEmit",
|
|
44
|
-
"test": "vitest run"
|
|
45
46
|
}
|
|
46
|
-
}
|
|
47
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Lensmap contributors
|
|
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.
|