@lensmap/language-server 0.1.0 → 0.1.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.
@@ -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-BtGyjknt.js"></script>
9
- <link rel="modulepreload" crossorigin href="/assets/styles-HT2Xrmtw.js">
10
- <link rel="stylesheet" crossorigin href="/assets/styles-D4WWbpX1.css">
8
+ <script type="module" crossorigin src="/assets/playground-BSWSEt-v.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/assets/styles-CWsrvT4d.js">
10
+ <link rel="stylesheet" crossorigin href="/assets/styles-B1m3hcTM.css">
11
11
  </head>
12
12
  <body>
13
13
  <div id="root"></div>
@@ -6,9 +6,9 @@
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-B84it-Jd.js"></script>
10
- <link rel="modulepreload" crossorigin href="/assets/styles-HT2Xrmtw.js">
11
- <link rel="stylesheet" crossorigin href="/assets/styles-D4WWbpX1.css">
9
+ <script type="module" crossorigin src="/assets/preview-CJQs7HAo.js"></script>
10
+ <link rel="modulepreload" crossorigin href="/assets/styles-CWsrvT4d.js">
11
+ <link rel="stylesheet" crossorigin href="/assets/styles-B1m3hcTM.css">
12
12
  <link rel="stylesheet" crossorigin href="/assets/preview-fhnbHE6T.css">
13
13
  </head>
14
14
  <body>
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
- ["/api/content", "/api/reveal", "/api/centre"].includes(url.pathname)) {
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?.snapshot().valid || session.snapshot().pending)
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,7 +2,7 @@
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.1.0",
5
+ "version": "0.1.1",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
@@ -30,7 +30,7 @@
30
30
  "lensmap-lsp": "./dist/main.js"
31
31
  },
32
32
  "dependencies": {
33
- "@lensmap/document": "0.1.0",
33
+ "@lensmap/document": "0.1.1",
34
34
  "vscode-languageserver": "11.0.0"
35
35
  },
36
36
  "devDependencies": {