@likec4/language-server 0.37.1 → 0.40.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/dist/Rpc.d.ts +6 -0
- package/dist/Rpc.js +130 -0
- package/dist/ast.d.ts +0 -97
- package/dist/ast.js +127 -143
- package/dist/elementRef.d.ts +1 -2
- package/dist/elementRef.js +31 -44
- package/dist/generated/ast.d.ts +4 -5
- package/dist/generated/ast.js +310 -315
- package/dist/generated/grammar.d.ts +0 -2
- package/dist/generated/grammar.js +2 -3177
- package/dist/generated/module.d.ts +1 -6
- package/dist/generated/module.js +13 -18
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -3
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +39 -42
- package/dist/lsp/CodeLensProvider.d.ts +0 -1
- package/dist/lsp/CodeLensProvider.js +28 -32
- package/dist/lsp/DocumentLinkProvider.d.ts +0 -1
- package/dist/lsp/DocumentLinkProvider.js +26 -33
- package/dist/lsp/DocumentSymbolProvider.d.ts +0 -1
- package/dist/lsp/DocumentSymbolProvider.js +165 -167
- package/dist/lsp/HoverProvider.d.ts +0 -1
- package/dist/lsp/HoverProvider.js +35 -48
- package/dist/lsp/SemanticTokenProvider.d.ts +0 -1
- package/dist/lsp/SemanticTokenProvider.js +153 -201
- package/dist/lsp/index.d.ts +0 -1
- package/dist/lsp/index.js +5 -6
- package/dist/model/fqn-computation.d.ts +0 -1
- package/dist/model/fqn-computation.js +39 -40
- package/dist/model/fqn-index.d.ts +0 -1
- package/dist/model/fqn-index.js +112 -142
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.js +5 -6
- package/dist/model/model-builder.d.ts +10 -6
- package/dist/model/model-builder.js +242 -177
- package/dist/model/model-locator.d.ts +1 -2
- package/dist/model/model-locator.js +102 -100
- package/dist/model/model-parser.d.ts +2 -7
- package/dist/model/model-parser.js +296 -287
- package/dist/module.d.ts +4 -2
- package/dist/module.js +69 -60
- package/dist/protocol.d.ts +16 -20
- package/dist/protocol.js +14 -22
- package/dist/references/index.d.ts +0 -1
- package/dist/references/index.js +2 -3
- package/dist/references/scope-computation.d.ts +2 -3
- package/dist/references/scope-computation.js +68 -70
- package/dist/references/scope-provider.d.ts +1 -2
- package/dist/references/scope-provider.js +126 -116
- package/dist/shared/WorkspaceManager.d.ts +2 -4
- package/dist/shared/WorkspaceManager.js +13 -16
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.js +1 -2
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +1 -2
- package/dist/test/testServices.d.ts +6 -7
- package/dist/test/testServices.js +64 -61
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -3
- package/dist/validation/element.d.ts +0 -2
- package/dist/validation/element.js +28 -39
- package/dist/validation/index.d.ts +0 -1
- package/dist/validation/index.js +36 -46
- package/dist/validation/relation.d.ts +0 -2
- package/dist/validation/relation.js +43 -47
- package/dist/validation/specification.d.ts +0 -2
- package/dist/validation/specification.js +21 -30
- package/dist/validation/view.d.ts +0 -2
- package/dist/validation/view.js +16 -22
- package/package.json +20 -13
- package/contrib/likec4.monarch.ts +0 -48
- package/contrib/likec4.tmLanguage.json +0 -73
- package/dist/registerProtocolHandlers.d.ts +0 -3
- package/dist/registerProtocolHandlers.js +0 -112
package/dist/validation/index.js
CHANGED
|
@@ -1,49 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { logger } from
|
|
3
|
-
import { elementChecks } from
|
|
4
|
-
import { relationChecks } from
|
|
5
|
-
import { elementKindChecks, tagChecks } from
|
|
6
|
-
import { viewChecks } from
|
|
1
|
+
import * as vscodeUri from "vscode-uri";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
import { elementChecks } from "./element.js";
|
|
4
|
+
import { relationChecks } from "./relation.js";
|
|
5
|
+
import { elementKindChecks, tagChecks } from "./specification.js";
|
|
6
|
+
import { viewChecks } from "./view.js";
|
|
7
7
|
export function registerValidationChecks(services) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (deleted.length > 0) {
|
|
36
|
-
message.push(` deleted:`);
|
|
37
|
-
deleted.forEach(u => message.push(` - ${Utils.basename(u)}`));
|
|
38
|
-
}
|
|
39
|
-
logger.debug(message.join('\n'));
|
|
40
|
-
for (const uri of deleted) {
|
|
41
|
-
void connection.sendDiagnostics({
|
|
42
|
-
uri: uri.toString(),
|
|
43
|
-
diagnostics: []
|
|
44
|
-
});
|
|
45
|
-
}
|
|
8
|
+
logger.info("registerValidationChecks");
|
|
9
|
+
const registry = services.validation.ValidationRegistry;
|
|
10
|
+
registry.register({
|
|
11
|
+
ElementView: viewChecks(services),
|
|
12
|
+
Element: elementChecks(services),
|
|
13
|
+
ElementKind: elementKindChecks(services),
|
|
14
|
+
Relation: relationChecks(services),
|
|
15
|
+
Tag: tagChecks(services)
|
|
16
|
+
});
|
|
17
|
+
const connection = services.shared.lsp.Connection;
|
|
18
|
+
if (connection) {
|
|
19
|
+
logger.info("registerValidationChecks");
|
|
20
|
+
services.shared.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
|
|
21
|
+
const message = [`[DocumentBuilder.onUpdate]`];
|
|
22
|
+
if (changed.length > 0) {
|
|
23
|
+
message.push(` changed:`);
|
|
24
|
+
changed.forEach((u) => message.push(` - ${vscodeUri.Utils.basename(u)}`));
|
|
25
|
+
}
|
|
26
|
+
if (deleted.length > 0) {
|
|
27
|
+
message.push(` deleted:`);
|
|
28
|
+
deleted.forEach((u) => message.push(` - ${vscodeUri.Utils.basename(u)}`));
|
|
29
|
+
}
|
|
30
|
+
logger.debug(message.join("\n"));
|
|
31
|
+
for (const uri of deleted) {
|
|
32
|
+
void connection.sendDiagnostics({
|
|
33
|
+
uri: uri.toString(),
|
|
34
|
+
diagnostics: []
|
|
46
35
|
});
|
|
47
|
-
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
48
39
|
}
|
|
49
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
import { isSameHierarchy } from
|
|
2
|
-
import { ast } from
|
|
3
|
-
import { elementRef } from
|
|
4
|
-
import { logError } from
|
|
1
|
+
import { isSameHierarchy } from "@likec4/core";
|
|
2
|
+
import { ast } from "../ast.js";
|
|
3
|
+
import { elementRef } from "../elementRef.js";
|
|
4
|
+
import { logError } from "../logger.js";
|
|
5
5
|
export const relationChecks = (services) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else {
|
|
29
|
-
sourceEl = el.$container.$container;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const source = sourceEl && fqnIndex.getFqn(sourceEl);
|
|
33
|
-
if (sourceEl && !source) {
|
|
34
|
-
accept('error', 'Source not found (not parsed/indexed yet)', {
|
|
35
|
-
node: el,
|
|
36
|
-
property: 'source'
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (source && target && isSameHierarchy(source, target)) {
|
|
40
|
-
return accept('error', 'Invalid parent-child relationship', {
|
|
41
|
-
node: el
|
|
42
|
-
});
|
|
43
|
-
}
|
|
6
|
+
const fqnIndex = services.likec4.FqnIndex;
|
|
7
|
+
return (el, accept) => {
|
|
8
|
+
try {
|
|
9
|
+
const targetEl = elementRef(el.target);
|
|
10
|
+
const target = targetEl && fqnIndex.getFqn(targetEl);
|
|
11
|
+
if (!target) {
|
|
12
|
+
accept("error", "Target not found (not parsed/indexed yet)", {
|
|
13
|
+
node: el,
|
|
14
|
+
property: "target"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
let sourceEl;
|
|
18
|
+
if ("source" in el) {
|
|
19
|
+
sourceEl = elementRef(el.source);
|
|
20
|
+
} else {
|
|
21
|
+
if (!ast.isElementBody(el.$container)) {
|
|
22
|
+
accept("error", "Invalid relation, expected to have source defined or be inside the element", {
|
|
23
|
+
node: el,
|
|
24
|
+
keyword: "->"
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
sourceEl = el.$container.$container;
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
}
|
|
30
|
+
const source = sourceEl && fqnIndex.getFqn(sourceEl);
|
|
31
|
+
if (sourceEl && !source) {
|
|
32
|
+
accept("error", "Source not found (not parsed/indexed yet)", {
|
|
33
|
+
node: el,
|
|
34
|
+
property: "source"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (source && target && isSameHierarchy(source, target)) {
|
|
38
|
+
return accept("error", "Invalid parent-child relationship", {
|
|
39
|
+
node: el
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
logError(e);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
49
46
|
};
|
|
50
|
-
//# sourceMappingURL=relation.js.map
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { ValidationCheck } from 'langium';
|
|
2
1
|
import { ast } from '../ast';
|
|
3
2
|
import type { LikeC4Services } from '../module';
|
|
4
3
|
export declare const elementKindChecks: (services: LikeC4Services) => ValidationCheck<ast.ElementKind>;
|
|
5
4
|
export declare const tagChecks: (services: LikeC4Services) => ValidationCheck<ast.Tag>;
|
|
6
|
-
//# sourceMappingURL=specification.d.ts.map
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
import { ast } from
|
|
1
|
+
import { ast } from "../ast.js";
|
|
2
2
|
export const elementKindChecks = (services) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
property: 'name'
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
};
|
|
3
|
+
const index = services.shared.workspace.IndexManager;
|
|
4
|
+
return (node, accept) => {
|
|
5
|
+
const sameKinds = index.allElements(ast.ElementKind).filter((n) => n.name === node.name).limit(2).count();
|
|
6
|
+
if (sameKinds > 1) {
|
|
7
|
+
accept("error", `Duplicate element kind '${node.name}'`, {
|
|
8
|
+
node,
|
|
9
|
+
property: "name"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
};
|
|
17
13
|
};
|
|
18
14
|
export const tagChecks = (services) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
property: 'name'
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
};
|
|
15
|
+
const index = services.shared.workspace.IndexManager;
|
|
16
|
+
return (node, accept) => {
|
|
17
|
+
const sameKinds = index.allElements(ast.Tag).filter((n) => n.name === node.name).limit(2).count();
|
|
18
|
+
if (sameKinds > 1) {
|
|
19
|
+
accept("error", `Duplicate tag '${node.name}'`, {
|
|
20
|
+
node,
|
|
21
|
+
property: "name"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
33
25
|
};
|
|
34
|
-
//# sourceMappingURL=specification.js.map
|
package/dist/validation/view.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import { ast } from
|
|
1
|
+
import { ast } from "../ast.js";
|
|
2
2
|
export const viewChecks = (services) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
node: el,
|
|
19
|
-
property: 'name'
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
3
|
+
const index = services.shared.workspace.IndexManager;
|
|
4
|
+
return (el, accept) => {
|
|
5
|
+
if (el.extends) {
|
|
6
|
+
}
|
|
7
|
+
if (!el.name) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const anotherViews = index.allElements(ast.View).filter((n) => n.name === el.name).limit(2).count();
|
|
11
|
+
if (anotherViews > 1) {
|
|
12
|
+
accept("error", `Duplicate view '${el.name}'`, {
|
|
13
|
+
node: el,
|
|
14
|
+
property: "name"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
23
18
|
};
|
|
24
|
-
//# sourceMappingURL=view.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/language-server",
|
|
3
3
|
"description": "LikeC4 Language Server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.40.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
@@ -20,21 +20,26 @@
|
|
|
20
20
|
"directory": "packages/language-server"
|
|
21
21
|
},
|
|
22
22
|
"type": "module",
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
26
29
|
"publishConfig": {
|
|
27
30
|
"registry": "https://registry.npmjs.org",
|
|
28
31
|
"access": "public"
|
|
29
32
|
},
|
|
30
33
|
"scripts": {
|
|
31
|
-
"turbo
|
|
32
|
-
"
|
|
33
|
-
"compile": "tsc --noEmit",
|
|
34
|
+
"typecheck:turbo": "run -T turbo run typecheck --filter='language-server'",
|
|
35
|
+
"typecheck": "tsc --emitDeclarationOnly",
|
|
34
36
|
"watch:langium": "langium generate --watch",
|
|
35
37
|
"watch:ts": "tsc --watch",
|
|
36
38
|
"generate": "langium generate",
|
|
37
|
-
"
|
|
39
|
+
"prepack": "run clean && run build",
|
|
40
|
+
"build:watch": "run-p 'watch:*'",
|
|
41
|
+
"build:turbo": "run -T turbo run build --filter='language-server'",
|
|
42
|
+
"build": "unbuild",
|
|
38
43
|
"dev": "run-p 'watch:*'",
|
|
39
44
|
"lint": "run -T eslint src/ --fix",
|
|
40
45
|
"clean": "run -T rimraf dist contrib",
|
|
@@ -42,12 +47,13 @@
|
|
|
42
47
|
"test:watch": "vitest"
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
|
-
"@likec4/core": "0.
|
|
50
|
+
"@likec4/core": "0.40.0",
|
|
46
51
|
"langium": "^2.0.2",
|
|
47
|
-
"nanoid": "^4.0.2",
|
|
48
52
|
"object-hash": "^3.0.0",
|
|
53
|
+
"p-debounce": "^4.0.0",
|
|
54
|
+
"p-throttle": "^5.1.0",
|
|
49
55
|
"rambdax": "^9.1.1",
|
|
50
|
-
"remeda": "^1.
|
|
56
|
+
"remeda": "^1.27.0",
|
|
51
57
|
"strip-indent": "^4.0.0",
|
|
52
58
|
"vscode-languageserver": "~8.1.0",
|
|
53
59
|
"vscode-languageserver-protocol": "~3.17.3",
|
|
@@ -55,11 +61,12 @@
|
|
|
55
61
|
},
|
|
56
62
|
"devDependencies": {
|
|
57
63
|
"@types/node": "^18.15.11",
|
|
58
|
-
"@types/object-hash": "^3.0.
|
|
64
|
+
"@types/object-hash": "^3.0.4",
|
|
59
65
|
"langium-cli": "^2.0.1",
|
|
60
66
|
"npm-run-all": "^4.1.5",
|
|
61
67
|
"typescript": "^5.2.2",
|
|
62
|
-
"
|
|
68
|
+
"unbuild": "^2.0.0",
|
|
69
|
+
"vitest": "^0.34.6"
|
|
63
70
|
},
|
|
64
71
|
"packageManager": "yarn@3.6.3"
|
|
65
72
|
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// Monarch syntax highlighting for the likec4 language.
|
|
2
|
-
export default {
|
|
3
|
-
keywords: [
|
|
4
|
-
'BottomTop','LeftRight','RightLeft','TopBottom','amber','autoLayout','blue','browser','color','cylinder','description','element','exclude','extend','extends','gray','green','icon','include','indigo','it','kind','link','mobile','model','muted','of','person','primary','queue','rectangle','red','secondary','shape','sky','slate','specification','storage','style','tag','technology','this','title','view','views'
|
|
5
|
-
],
|
|
6
|
-
operators: [
|
|
7
|
-
'*','.*'
|
|
8
|
-
],
|
|
9
|
-
symbols: /\*|\.\*/,
|
|
10
|
-
|
|
11
|
-
tokenizer: {
|
|
12
|
-
initial: [
|
|
13
|
-
{ regex: /#/, action: {"token":"HASH"} },
|
|
14
|
-
{ regex: /_/, action: {"token":"UNDERSCORE"} },
|
|
15
|
-
{ regex: /-/, action: {"token":"DASH"} },
|
|
16
|
-
{ regex: /[^\W\d_]/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"LETTER"} }} },
|
|
17
|
-
{ regex: /[0-9]/, action: {"token":"DIGIT"} },
|
|
18
|
-
{ regex: /[\t\r\n\v\f]/, action: {"token":"NEWLINE"} },
|
|
19
|
-
{ regex: /\w+:\/\/\S+/, action: {"token":"URI_WITH_SCHEMA"} },
|
|
20
|
-
{ regex: /\.{0,2}\/[^\/]\S+/, action: {"token":"URI_RELATIVE"} },
|
|
21
|
-
{ regex: /->/, action: {"token":"RARROW"} },
|
|
22
|
-
{ regex: /\b\.\b/, action: {"token":"Dot"} },
|
|
23
|
-
{ regex: /!=/, action: {"token":"NotEqual"} },
|
|
24
|
-
{ regex: /=/, action: {"token":"Eq"} },
|
|
25
|
-
{ regex: /\{/, action: {"token":"OpenBlock"} },
|
|
26
|
-
{ regex: /\}/, action: {"token":"CloseBlock"} },
|
|
27
|
-
{ regex: /:/, action: {"token":"Colon"} },
|
|
28
|
-
{ regex: /;/, action: {"token":"SemiColon"} },
|
|
29
|
-
{ regex: /,/, action: {"token":"Comma"} },
|
|
30
|
-
{ regex: /((#)([^\W\d_])(((([^\W\d_])|([0-9]))|(_))|(-))*)/, action: {"token":"TagID"} },
|
|
31
|
-
{ regex: /((([^\W\d_])|(_))(((([^\W\d_])|([0-9]))|(_))|(-))*)/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"ID"} }} },
|
|
32
|
-
{ regex: /"[^"]*"|'[^']*'/, action: {"token":"string"} },
|
|
33
|
-
{ include: '@whitespace' },
|
|
34
|
-
{ regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} },
|
|
35
|
-
],
|
|
36
|
-
whitespace: [
|
|
37
|
-
{ regex: /[^\S\r\n]/, action: {"token":"white"} },
|
|
38
|
-
{ regex: /(([\t\r\n\v\f])|([^\S\r\n]))+/, action: {"token":"white"} },
|
|
39
|
-
{ regex: /\/\*/, action: {"token":"comment","next":"@comment"} },
|
|
40
|
-
{ regex: /\/\/[^\n\r]*/, action: {"token":"comment"} },
|
|
41
|
-
],
|
|
42
|
-
comment: [
|
|
43
|
-
{ regex: /[^/\*]+/, action: {"token":"comment"} },
|
|
44
|
-
{ regex: /\*\//, action: {"token":"comment","next":"@pop"} },
|
|
45
|
-
{ regex: /[/\*]/, action: {"token":"comment"} },
|
|
46
|
-
],
|
|
47
|
-
}
|
|
48
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "likec4",
|
|
3
|
-
"scopeName": "source.likec4",
|
|
4
|
-
"fileTypes": [
|
|
5
|
-
".c4",
|
|
6
|
-
".likec4",
|
|
7
|
-
".like-c4"
|
|
8
|
-
],
|
|
9
|
-
"patterns": [
|
|
10
|
-
{
|
|
11
|
-
"include": "#comments"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"name": "keyword.control.likec4",
|
|
15
|
-
"match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|autoLayout|blue|browser|color|cylinder|description|element|exclude|extend|extends|gray|green|icon|include|indigo|it|kind|link|mobile|model|muted|of|person|primary|queue|rectangle|red|secondary|shape|sky|slate|specification|storage|style|tag|technology|this|title|view|views)\\b"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name": "string.quoted.double.likec4",
|
|
19
|
-
"begin": "\"",
|
|
20
|
-
"end": "\"",
|
|
21
|
-
"patterns": [
|
|
22
|
-
{
|
|
23
|
-
"include": "#string-character-escape"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"name": "string.quoted.single.likec4",
|
|
29
|
-
"begin": "'",
|
|
30
|
-
"end": "'",
|
|
31
|
-
"patterns": [
|
|
32
|
-
{
|
|
33
|
-
"include": "#string-character-escape"
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"repository": {
|
|
39
|
-
"comments": {
|
|
40
|
-
"patterns": [
|
|
41
|
-
{
|
|
42
|
-
"name": "comment.block.likec4",
|
|
43
|
-
"begin": "/\\*",
|
|
44
|
-
"beginCaptures": {
|
|
45
|
-
"0": {
|
|
46
|
-
"name": "punctuation.definition.comment.likec4"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"end": "\\*/",
|
|
50
|
-
"endCaptures": {
|
|
51
|
-
"0": {
|
|
52
|
-
"name": "punctuation.definition.comment.likec4"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"begin": "//",
|
|
58
|
-
"beginCaptures": {
|
|
59
|
-
"1": {
|
|
60
|
-
"name": "punctuation.whitespace.comment.leading.likec4"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"end": "(?=$)",
|
|
64
|
-
"name": "comment.line.likec4"
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
"string-character-escape": {
|
|
69
|
-
"name": "constant.character.escape.likec4",
|
|
70
|
-
"match": "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\\{[0-9A-Fa-f]+\\}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { URI } from 'vscode-uri';
|
|
2
|
-
import { logger, logError } from './logger';
|
|
3
|
-
import { Rpc } from './protocol';
|
|
4
|
-
import { nonexhaustive } from '@likec4/core';
|
|
5
|
-
import { isLikeC4LangiumDocument } from './ast';
|
|
6
|
-
export function registerProtocolHandlers(services) {
|
|
7
|
-
const connection = services.shared.lsp.Connection;
|
|
8
|
-
if (!connection) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const modelBuilder = services.likec4.ModelBuilder;
|
|
12
|
-
const modelLocator = services.likec4.ModelLocator;
|
|
13
|
-
const LangiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
14
|
-
connection.onRequest(Rpc.fetchModel, async (_cancelToken) => {
|
|
15
|
-
let model;
|
|
16
|
-
try {
|
|
17
|
-
model = modelBuilder.buildModel() ?? null;
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
model = null;
|
|
21
|
-
logError(e);
|
|
22
|
-
}
|
|
23
|
-
return Promise.resolve({ model });
|
|
24
|
-
});
|
|
25
|
-
connection.onRequest(Rpc.fetchRawModel, async (_cancelToken) => {
|
|
26
|
-
let rawmodel;
|
|
27
|
-
try {
|
|
28
|
-
rawmodel = modelBuilder.buildRawModel() ?? null;
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
rawmodel = null;
|
|
32
|
-
logError(e);
|
|
33
|
-
}
|
|
34
|
-
return Promise.resolve({ rawmodel });
|
|
35
|
-
});
|
|
36
|
-
connection.onRequest(Rpc.computeView, ({ viewId }) => {
|
|
37
|
-
return {
|
|
38
|
-
view: modelBuilder.computeView(viewId)
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
connection.onRequest(Rpc.rebuild, async (cancelToken) => {
|
|
42
|
-
const changed = LangiumDocuments.all
|
|
43
|
-
.map(d => {
|
|
44
|
-
// clean up any computed properties
|
|
45
|
-
if (isLikeC4LangiumDocument(d)) {
|
|
46
|
-
delete d.c4Specification;
|
|
47
|
-
delete d.c4Elements;
|
|
48
|
-
delete d.c4Relations;
|
|
49
|
-
delete d.c4Views;
|
|
50
|
-
delete d.c4fqns;
|
|
51
|
-
}
|
|
52
|
-
return d.uri;
|
|
53
|
-
})
|
|
54
|
-
.toArray();
|
|
55
|
-
logger.debug(`[ProtocolHandlers] rebuild all documents: [
|
|
56
|
-
${changed.map(d => d.toString()).join('\n ')}
|
|
57
|
-
]`);
|
|
58
|
-
await services.shared.workspace.DocumentBuilder.update(changed, [], cancelToken);
|
|
59
|
-
return {
|
|
60
|
-
docs: changed.map(d => d.toString())
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
connection.onRequest(Rpc.buildDocuments, async ({ docs }, cancelToken) => {
|
|
64
|
-
if (docs.length === 0) {
|
|
65
|
-
logger.debug(`[ProtocolHandlers] received empty request to rebuild`);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
logger.debug(`[ProtocolHandlers] received request to buildDocuments:
|
|
69
|
-
- ${docs.join('\n - ')}`);
|
|
70
|
-
const changed = [];
|
|
71
|
-
for (const d of docs) {
|
|
72
|
-
try {
|
|
73
|
-
const uri = URI.parse(d);
|
|
74
|
-
if (LangiumDocuments.hasDocument(uri)) {
|
|
75
|
-
changed.push(uri);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
logger.warn(`LangiumDocuments does not have document: ${d}`);
|
|
79
|
-
LangiumDocuments.getOrCreateDocument(uri);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
logError(e);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (changed.length !== docs.length) {
|
|
87
|
-
const all = LangiumDocuments.all.map(d => d.uri.toString()).toArray();
|
|
88
|
-
logger.warn(`
|
|
89
|
-
We have in LangiumDocuments: [
|
|
90
|
-
${all.join('\n ')}
|
|
91
|
-
]
|
|
92
|
-
We rebuild: [
|
|
93
|
-
${changed.join('\n ')}
|
|
94
|
-
]
|
|
95
|
-
`.trim());
|
|
96
|
-
}
|
|
97
|
-
await services.shared.workspace.DocumentBuilder.update(changed, [], cancelToken);
|
|
98
|
-
});
|
|
99
|
-
connection.onRequest(Rpc.locate, params => {
|
|
100
|
-
if ('element' in params) {
|
|
101
|
-
return modelLocator.locateElement(params.element, params.property ?? 'name');
|
|
102
|
-
}
|
|
103
|
-
if ('relation' in params) {
|
|
104
|
-
return modelLocator.locateRelation(params.relation);
|
|
105
|
-
}
|
|
106
|
-
if ('view' in params) {
|
|
107
|
-
return modelLocator.locateView(params.view);
|
|
108
|
-
}
|
|
109
|
-
nonexhaustive(params);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=registerProtocolHandlers.js.map
|