@lensmap/language-server 0.2.0 → 0.3.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.
@@ -0,0 +1,79 @@
1
+ import { DocumentSession, offsetToPosition, parseVocabulary, positionToOffset, } from "@lensmap/document";
2
+ import { isMap, isScalar, parseDocument, visit } from "yaml";
3
+ /** Reuse engine resolution for editor tooling, without publishing a second graph. */
4
+ export function analyzeVocabularyForTooling(uri, supplied, mapSource, vocabularySource) {
5
+ let input = supplied;
6
+ let local;
7
+ if (vocabularySource !== undefined)
8
+ input = parseVocabulary(vocabularySource, uri);
9
+ if (mapSource !== undefined) {
10
+ try {
11
+ const syntax = parseDocument(mapSource, { uniqueKeys: true });
12
+ const declarations = syntax.get("connection_types", true);
13
+ if (!syntax.errors.length && isMap(declarations))
14
+ local = declarations.toJSON();
15
+ }
16
+ catch {
17
+ // Syntax diagnostics belong to the real document; still offer shared names.
18
+ }
19
+ }
20
+ const snapshot = new DocumentSession(uri, JSON.stringify({
21
+ version: "v1",
22
+ nodes: [],
23
+ ...(local ? { connection_types: local } : {}),
24
+ }), 0, input).snapshot();
25
+ return { snapshot, input };
26
+ }
27
+ /** Native YAML scalar decoding preserves quoted/Unicode names exactly. */
28
+ export function typeNameAt(source, at) {
29
+ const syntax = parseDocument(source);
30
+ const offset = positionToOffset(source, at);
31
+ let name;
32
+ visit(syntax, {
33
+ Pair(_key, pair) {
34
+ if (isScalar(pair.key) &&
35
+ (pair.key.value === "type" || pair.key.value === "extends") &&
36
+ isScalar(pair.value) &&
37
+ typeof pair.value.value === "string" &&
38
+ pair.value.range &&
39
+ pair.value.range[0] <= offset &&
40
+ offset <= pair.value.range[1])
41
+ name = pair.value.value;
42
+ },
43
+ });
44
+ return name;
45
+ }
46
+ /** Replace the native scalar, including existing quotes but excluding comments. */
47
+ export function typeValueRangeAt(source, at) {
48
+ const offset = positionToOffset(source, at);
49
+ let range;
50
+ visit(parseDocument(source), {
51
+ Pair(_key, pair) {
52
+ if (isScalar(pair.key) &&
53
+ pair.key.range &&
54
+ (pair.key.value === "type" || pair.key.value === "extends") &&
55
+ isScalar(pair.value) &&
56
+ pair.value.range &&
57
+ pair.value.range[1] > pair.value.range[0] &&
58
+ pair.key.range[1] < offset &&
59
+ offset <= pair.value.range[1]) {
60
+ let end = pair.value.range[1];
61
+ while (end > pair.value.range[0] && /[\r\n]/.test(source[end - 1]))
62
+ end--;
63
+ range = {
64
+ start: offsetToPosition(source, pair.value.range[0]),
65
+ end: offsetToPosition(source, end),
66
+ };
67
+ }
68
+ },
69
+ });
70
+ return range;
71
+ }
72
+ export function declaresType(source, name) {
73
+ try {
74
+ return Boolean(parseDocument(source).getIn(["connection_types", name], true));
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ }
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.2.0",
5
+ "version": "0.3.0",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
@@ -29,19 +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
- },
38
32
  "dependencies": {
39
- "@lensmap/document": "workspace:*",
40
- "vscode-languageserver": "11.0.0"
33
+ "@lensmap/document": "0.3.0",
34
+ "vscode-languageserver": "11.0.0",
35
+ "yaml": "2.9.1"
41
36
  },
42
37
  "devDependencies": {
43
38
  "@types/node": "24.19.2",
44
39
  "typescript": "7.0.2",
45
40
  "vitest": "5.1.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc && node build.ts",
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "vitest run"
46
46
  }
47
- }
47
+ }