@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.
Files changed (75) hide show
  1. package/dist/Rpc.d.ts +6 -0
  2. package/dist/Rpc.js +130 -0
  3. package/dist/ast.d.ts +0 -97
  4. package/dist/ast.js +127 -143
  5. package/dist/elementRef.d.ts +1 -2
  6. package/dist/elementRef.js +31 -44
  7. package/dist/generated/ast.d.ts +4 -5
  8. package/dist/generated/ast.js +310 -315
  9. package/dist/generated/grammar.d.ts +0 -2
  10. package/dist/generated/grammar.js +2 -3177
  11. package/dist/generated/module.d.ts +1 -6
  12. package/dist/generated/module.js +13 -18
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.js +2 -3
  15. package/dist/logger.d.ts +0 -1
  16. package/dist/logger.js +39 -42
  17. package/dist/lsp/CodeLensProvider.d.ts +0 -1
  18. package/dist/lsp/CodeLensProvider.js +28 -32
  19. package/dist/lsp/DocumentLinkProvider.d.ts +0 -1
  20. package/dist/lsp/DocumentLinkProvider.js +26 -33
  21. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -1
  22. package/dist/lsp/DocumentSymbolProvider.js +165 -167
  23. package/dist/lsp/HoverProvider.d.ts +0 -1
  24. package/dist/lsp/HoverProvider.js +35 -48
  25. package/dist/lsp/SemanticTokenProvider.d.ts +0 -1
  26. package/dist/lsp/SemanticTokenProvider.js +153 -201
  27. package/dist/lsp/index.d.ts +0 -1
  28. package/dist/lsp/index.js +5 -6
  29. package/dist/model/fqn-computation.d.ts +0 -1
  30. package/dist/model/fqn-computation.js +39 -40
  31. package/dist/model/fqn-index.d.ts +0 -1
  32. package/dist/model/fqn-index.js +112 -142
  33. package/dist/model/index.d.ts +0 -1
  34. package/dist/model/index.js +5 -6
  35. package/dist/model/model-builder.d.ts +10 -6
  36. package/dist/model/model-builder.js +242 -177
  37. package/dist/model/model-locator.d.ts +1 -2
  38. package/dist/model/model-locator.js +102 -100
  39. package/dist/model/model-parser.d.ts +2 -7
  40. package/dist/model/model-parser.js +296 -287
  41. package/dist/module.d.ts +4 -2
  42. package/dist/module.js +69 -60
  43. package/dist/protocol.d.ts +16 -20
  44. package/dist/protocol.js +14 -22
  45. package/dist/references/index.d.ts +0 -1
  46. package/dist/references/index.js +2 -3
  47. package/dist/references/scope-computation.d.ts +2 -3
  48. package/dist/references/scope-computation.js +68 -70
  49. package/dist/references/scope-provider.d.ts +1 -2
  50. package/dist/references/scope-provider.js +126 -116
  51. package/dist/shared/WorkspaceManager.d.ts +2 -4
  52. package/dist/shared/WorkspaceManager.js +13 -16
  53. package/dist/shared/index.d.ts +0 -1
  54. package/dist/shared/index.js +1 -2
  55. package/dist/test/index.d.ts +0 -1
  56. package/dist/test/index.js +1 -2
  57. package/dist/test/testServices.d.ts +6 -7
  58. package/dist/test/testServices.js +64 -61
  59. package/dist/utils.d.ts +1 -1
  60. package/dist/utils.js +4 -3
  61. package/dist/validation/element.d.ts +0 -2
  62. package/dist/validation/element.js +28 -39
  63. package/dist/validation/index.d.ts +0 -1
  64. package/dist/validation/index.js +36 -46
  65. package/dist/validation/relation.d.ts +0 -2
  66. package/dist/validation/relation.js +43 -47
  67. package/dist/validation/specification.d.ts +0 -2
  68. package/dist/validation/specification.js +21 -30
  69. package/dist/validation/view.d.ts +0 -2
  70. package/dist/validation/view.js +16 -22
  71. package/package.json +20 -13
  72. package/contrib/likec4.monarch.ts +0 -48
  73. package/contrib/likec4.tmLanguage.json +0 -73
  74. package/dist/registerProtocolHandlers.d.ts +0 -3
  75. package/dist/registerProtocolHandlers.js +0 -112
@@ -1,129 +1,139 @@
1
- import { DONE_RESULT, DefaultScopeProvider, EMPTY_STREAM, StreamImpl, StreamScope, getDocument, stream, findNodeForProperty, toDocumentSegment } from 'langium';
2
- import { ast } from '../ast';
3
- import { elementRef, isElementRefHead, parentFqnElementRef } from '../elementRef';
4
- import { logError } from '../logger';
1
+ import {
2
+ DONE_RESULT,
3
+ DefaultScopeProvider,
4
+ EMPTY_STREAM,
5
+ StreamImpl,
6
+ StreamScope,
7
+ getDocument,
8
+ stream,
9
+ findNodeForProperty,
10
+ toDocumentSegment
11
+ } from "langium";
12
+ import { ast } from "../ast.js";
13
+ import { elementRef, isElementRefHead, parentFqnElementRef } from "../elementRef.js";
14
+ import { logError } from "../logger.js";
5
15
  function toAstNodeDescription(entry) {
6
- const $cstNode = findNodeForProperty(entry.el.$cstNode, 'name');
7
- return {
8
- documentUri: entry.doc.uri,
9
- name: entry.name,
10
- ...(entry.el.$cstNode && {
11
- selectionSegment: toDocumentSegment(entry.el.$cstNode)
12
- }),
13
- ...($cstNode && {
14
- nameSegment: toDocumentSegment($cstNode)
15
- }),
16
- path: entry.path,
17
- type: ast.Element
18
- };
16
+ const $cstNode = findNodeForProperty(entry.el.$cstNode, "name");
17
+ return {
18
+ documentUri: entry.doc.uri,
19
+ name: entry.name,
20
+ ...entry.el.$cstNode && {
21
+ selectionSegment: toDocumentSegment(entry.el.$cstNode)
22
+ },
23
+ ...$cstNode && {
24
+ nameSegment: toDocumentSegment($cstNode)
25
+ },
26
+ path: entry.path,
27
+ type: ast.Element
28
+ };
19
29
  }
20
30
  export class LikeC4ScopeProvider extends DefaultScopeProvider {
21
- fqnIndex;
22
- constructor(services) {
23
- super(services);
24
- this.fqnIndex = services.likec4.FqnIndex;
25
- }
26
- directChildrenOf(parent) {
27
- return this.fqnIndex.directChildrenOf(parent).map(toAstNodeDescription);
28
- }
29
- // we need lazy resolving here
30
- uniqueDescedants(of) {
31
- return new StreamImpl(() => {
32
- const element = of();
33
- const fqn = element && this.fqnIndex.getFqn(element);
34
- if (fqn) {
35
- return this.fqnIndex.uniqueDescedants(fqn).map(toAstNodeDescription).iterator();
36
- }
37
- return null;
38
- }, iterator => {
39
- if (iterator) {
40
- return iterator.next();
41
- }
42
- return DONE_RESULT;
43
- });
44
- }
45
- scopeElementRef(ref) {
46
- const parentNode = ref.$container;
47
- if (!ast.isElementRef(parentNode)) {
48
- throw new Error('Expected be inside ElementRef');
31
+ fqnIndex;
32
+ constructor(services) {
33
+ super(services);
34
+ this.fqnIndex = services.likec4.FqnIndex;
35
+ }
36
+ directChildrenOf(parent) {
37
+ return this.fqnIndex.directChildrenOf(parent).map(toAstNodeDescription);
38
+ }
39
+ // we need lazy resolving here
40
+ uniqueDescedants(of) {
41
+ return new StreamImpl(
42
+ () => {
43
+ const element = of();
44
+ const fqn = element && this.fqnIndex.getFqn(element);
45
+ if (fqn) {
46
+ return this.fqnIndex.uniqueDescedants(fqn).map(toAstNodeDescription).iterator();
49
47
  }
50
- return this.uniqueDescedants(() => parentNode.el.ref);
48
+ return null;
49
+ },
50
+ (iterator) => {
51
+ if (iterator) {
52
+ return iterator.next();
53
+ }
54
+ return DONE_RESULT;
55
+ }
56
+ );
57
+ }
58
+ scopeElementRef(ref) {
59
+ const parentNode = ref.$container;
60
+ if (!ast.isElementRef(parentNode)) {
61
+ throw new Error("Expected be inside ElementRef");
51
62
  }
52
- scopeExtendElement(extend) {
53
- return this.uniqueDescedants(() => elementRef(extend.element));
63
+ return this.uniqueDescedants(() => parentNode.el.ref);
64
+ }
65
+ scopeExtendElement(extend) {
66
+ return this.uniqueDescedants(() => elementRef(extend.element));
67
+ }
68
+ scopeElementView({ viewOf, extends: ext }) {
69
+ if (ext) {
70
+ return stream([ext]).flatMap((v) => {
71
+ const view = v.view.ref;
72
+ return view ? this.scopeElementView(view) : EMPTY_STREAM;
73
+ });
54
74
  }
55
- scopeElementView({ viewOf, extends: ext }) {
56
- if (ext) {
57
- return stream([ext]).flatMap(v => {
58
- const view = v.view.ref;
59
- return view ? this.scopeElementView(view) : EMPTY_STREAM;
60
- });
61
- }
62
- if (viewOf) {
63
- return this.uniqueDescedants(() => elementRef(viewOf));
64
- }
65
- return EMPTY_STREAM;
75
+ if (viewOf) {
76
+ return this.uniqueDescedants(() => elementRef(viewOf));
66
77
  }
67
- getScope(context) {
68
- const referenceType = this.reflection.getReferenceType(context);
69
- try {
70
- const container = context.container;
71
- // const path = this.services.workspace.AstNodeLocator.getAstNodePath(node)
72
- if (referenceType === ast.Element) {
73
- if (ast.isStrictElementRef(container)) {
74
- if (isElementRefHead(container)) {
75
- return this.getGlobalScope(referenceType);
76
- }
77
- const parent = parentFqnElementRef(container);
78
- return new StreamScope(this.directChildrenOf(parent));
79
- }
80
- if (ast.isElementRef(container) && !isElementRefHead(container)) {
81
- return new StreamScope(this.scopeElementRef(container));
82
- }
83
- }
84
- return this.computeScope(container, referenceType);
85
- }
86
- catch (e) {
87
- logError(e);
78
+ return EMPTY_STREAM;
79
+ }
80
+ getScope(context) {
81
+ const referenceType = this.reflection.getReferenceType(context);
82
+ try {
83
+ const container = context.container;
84
+ if (referenceType === ast.Element) {
85
+ if (ast.isStrictElementRef(container)) {
86
+ if (isElementRefHead(container)) {
88
87
  return this.getGlobalScope(referenceType);
88
+ }
89
+ const parent = parentFqnElementRef(container);
90
+ return new StreamScope(this.directChildrenOf(parent));
89
91
  }
90
- }
91
- computeScope(node, referenceType) {
92
- const scopes = [];
93
- const doc = getDocument(node);
94
- const precomputed = doc.precomputedScopes;
95
- const byReferenceType = (desc) => this.reflection.isSubtype(desc.type, referenceType);
96
- if (precomputed) {
97
- const elements = precomputed.get(node).filter(byReferenceType);
98
- if (elements.length > 0) {
99
- scopes.push(stream(elements));
100
- }
101
- let container = node.$container;
102
- while (container) {
103
- const elements = precomputed.get(container).filter(byReferenceType);
104
- if (elements.length > 0) {
105
- scopes.push(stream(elements));
106
- }
107
- if (referenceType === ast.Element) {
108
- if (ast.isExtendElementBody(container)) {
109
- scopes.push(this.scopeExtendElement(container.$container));
110
- }
111
- if (ast.isElementViewBody(container)) {
112
- scopes.push(this.scopeElementView(container.$container));
113
- }
114
- }
115
- container = container.$container;
116
- }
92
+ if (ast.isElementRef(container) && !isElementRefHead(container)) {
93
+ return new StreamScope(this.scopeElementRef(container));
117
94
  }
118
- return scopes.reduceRight((outerScope, elements) => {
119
- return this.createScope(elements, outerScope);
120
- }, this.getGlobalScope(referenceType));
95
+ }
96
+ return this.computeScope(container, referenceType);
97
+ } catch (e) {
98
+ logError(e);
99
+ return this.getGlobalScope(referenceType);
121
100
  }
122
- /**
123
- * Create a global scope filtered for the given reference type.
124
- */
125
- getGlobalScope(referenceType) {
126
- return new StreamScope(this.indexManager.allElements(referenceType));
101
+ }
102
+ computeScope(node, referenceType) {
103
+ const scopes = [];
104
+ const doc = getDocument(node);
105
+ const precomputed = doc.precomputedScopes;
106
+ const byReferenceType = (desc) => this.reflection.isSubtype(desc.type, referenceType);
107
+ if (precomputed) {
108
+ const elements = precomputed.get(node).filter(byReferenceType);
109
+ if (elements.length > 0) {
110
+ scopes.push(stream(elements));
111
+ }
112
+ let container = node.$container;
113
+ while (container) {
114
+ const elements2 = precomputed.get(container).filter(byReferenceType);
115
+ if (elements2.length > 0) {
116
+ scopes.push(stream(elements2));
117
+ }
118
+ if (referenceType === ast.Element) {
119
+ if (ast.isExtendElementBody(container)) {
120
+ scopes.push(this.scopeExtendElement(container.$container));
121
+ }
122
+ if (ast.isElementViewBody(container)) {
123
+ scopes.push(this.scopeElementView(container.$container));
124
+ }
125
+ }
126
+ container = container.$container;
127
+ }
127
128
  }
129
+ return scopes.reduceRight((outerScope, elements) => {
130
+ return this.createScope(elements, outerScope);
131
+ }, this.getGlobalScope(referenceType));
132
+ }
133
+ /**
134
+ * Create a global scope filtered for the given reference type.
135
+ */
136
+ getGlobalScope(referenceType) {
137
+ return new StreamScope(this.indexManager.allElements(referenceType));
138
+ }
128
139
  }
129
- //# sourceMappingURL=scope-provider.js.map
@@ -1,14 +1,12 @@
1
- import type { LangiumDocument, LangiumDocumentFactory, LangiumSharedServices } from 'langium';
1
+ import type { LangiumDocument } from 'langium';
2
2
  import { DefaultWorkspaceManager } from 'langium';
3
3
  import type { WorkspaceFolder } from 'vscode-languageserver';
4
4
  export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
5
- protected readonly documentFactory: LangiumDocumentFactory;
6
- constructor(services: LangiumSharedServices);
7
5
  /**
8
6
  * Load all additional documents that shall be visible in the context of the given workspace
9
7
  * folders and add them to the collector. This can be used to include built-in libraries of
10
8
  * your language, which can be either loaded from provided files or constructed in memory.
11
9
  */
12
10
  protected loadAdditionalDocuments(_folders: WorkspaceFolder[], _collector: (document: LangiumDocument) => void): Promise<void>;
11
+ workspace(): any;
13
12
  }
14
- //# sourceMappingURL=WorkspaceManager.d.ts.map
@@ -1,18 +1,15 @@
1
- import { DefaultWorkspaceManager } from 'langium';
1
+ import { nonNullable } from "@likec4/core";
2
+ import { DefaultWorkspaceManager } from "langium";
2
3
  export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
3
- documentFactory;
4
- constructor(services) {
5
- super(services);
6
- this.documentFactory = services.workspace.LangiumDocumentFactory;
7
- }
8
- /**
9
- * Load all additional documents that shall be visible in the context of the given workspace
10
- * folders and add them to the collector. This can be used to include built-in libraries of
11
- * your language, which can be either loaded from provided files or constructed in memory.
12
- */
13
- loadAdditionalDocuments(_folders, _collector) {
14
- // collector(this.documentFactory.fromString(builtin.specification.document, URI.parse(builtin.specification.uri)))
15
- return Promise.resolve();
16
- }
4
+ /**
5
+ * Load all additional documents that shall be visible in the context of the given workspace
6
+ * folders and add them to the collector. This can be used to include built-in libraries of
7
+ * your language, which can be either loaded from provided files or constructed in memory.
8
+ */
9
+ loadAdditionalDocuments(_folders, _collector) {
10
+ return Promise.resolve();
11
+ }
12
+ workspace() {
13
+ return this.folders && this.folders.length > 0 ? nonNullable(this.folders[0]) : null;
14
+ }
17
15
  }
18
- //# sourceMappingURL=WorkspaceManager.js.map
@@ -1,2 +1 @@
1
1
  export * from './WorkspaceManager';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
- export * from './WorkspaceManager';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./WorkspaceManager.js";
@@ -1,2 +1 @@
1
1
  export * from './testServices';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
- export * from './testServices';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./testServices.js";
@@ -1,16 +1,15 @@
1
1
  import type { LikeC4LangiumDocument } from '../ast';
2
2
  export declare function createTestServices(workspace?: string): {
3
- services: import("../module").LikeC4Services;
3
+ services: any;
4
4
  parse: (input: string, uri?: string) => Promise<LikeC4LangiumDocument>;
5
5
  validate: (input: string | LikeC4LangiumDocument, uri?: string) => Promise<{
6
6
  document: LikeC4LangiumDocument;
7
- diagnostics: import("vscode-languageserver-types").Diagnostic[];
8
- errors: string[];
7
+ diagnostics: any;
8
+ errors: any;
9
9
  }>;
10
10
  validateAll: () => Promise<{
11
- diagnostics: import("vscode-languageserver-types").Diagnostic[];
12
- errors: string[];
11
+ diagnostics: any;
12
+ errors: any;
13
13
  }>;
14
- buildModel: () => Promise<import("@likec4/core").LikeC4Model>;
14
+ buildModel: () => Promise<any>;
15
15
  };
16
- //# sourceMappingURL=testServices.d.ts.map
@@ -1,65 +1,68 @@
1
- import { createLanguageServices } from '../module';
2
- import { EmptyFileSystem } from 'langium';
3
- import { URI, Utils } from 'vscode-uri';
4
- import stripIndent from 'strip-indent';
5
- export function createTestServices(workspace = 'file:///test/workspace') {
6
- const services = createLanguageServices(EmptyFileSystem).likec4;
7
- const metaData = services.LanguageMetaData;
8
- const langiumDocuments = services.shared.workspace.LangiumDocuments;
9
- const documentBuilder = services.shared.workspace.DocumentBuilder;
10
- const modelBuilder = services.likec4.ModelBuilder;
11
- const workspaceUri = URI.parse(workspace);
12
- const initPromise = services.shared.workspace.WorkspaceManager.initializeWorkspace([
13
- {
14
- name: 'test',
15
- uri: workspaceUri.toString()
16
- }
17
- ]);
18
- let documentIndex = 1;
19
- const parse = async (input, uri) => {
20
- await initPromise;
21
- const docUri = Utils.joinPath(workspaceUri, '/src/', uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`);
22
- const document = services.shared.workspace.LangiumDocumentFactory.fromString(stripIndent(input), docUri);
23
- langiumDocuments.addDocument(document);
24
- await documentBuilder.build([document], { validation: false });
25
- return document;
26
- };
27
- const validate = async (input, uri) => {
28
- await initPromise;
29
- const document = typeof input === 'string' ? await parse(input, uri) : input;
30
- await documentBuilder.build([document], { validation: true });
31
- const diagnostics = document.diagnostics ?? [];
32
- const errors = diagnostics.map(d => d.message);
33
- return {
34
- document,
35
- diagnostics,
36
- errors
37
- };
38
- };
39
- const validateAll = async () => {
40
- await initPromise;
41
- const docs = langiumDocuments.all.toArray();
42
- await documentBuilder.build(docs, { validation: true });
43
- const diagnostics = docs.flatMap(doc => doc.diagnostics ?? []);
44
- const errors = diagnostics.map(d => d.message);
45
- return {
46
- diagnostics,
47
- errors
48
- };
49
- };
50
- const buildModel = async () => {
51
- await validateAll();
52
- const model = modelBuilder.buildModel();
53
- if (!model)
54
- throw new Error('No model found');
55
- return model;
1
+ import { createLanguageServices } from "../module.js";
2
+ import { EmptyFileSystem } from "langium";
3
+ import { URI, Utils } from "vscode-uri";
4
+ import stripIndent from "strip-indent";
5
+ export function createTestServices(workspace = "file:///test/workspace") {
6
+ const services = createLanguageServices(EmptyFileSystem).likec4;
7
+ const metaData = services.LanguageMetaData;
8
+ const langiumDocuments = services.shared.workspace.LangiumDocuments;
9
+ const documentBuilder = services.shared.workspace.DocumentBuilder;
10
+ const modelBuilder = services.likec4.ModelBuilder;
11
+ const workspaceUri = URI.parse(workspace);
12
+ const workspaceFolder = {
13
+ name: "test",
14
+ uri: workspaceUri.toString()
15
+ };
16
+ const initPromise = services.shared.workspace.WorkspaceManager.initializeWorkspace([workspaceFolder]);
17
+ void initPromise.finally(() => {
18
+ Object.assign(services.shared.workspace.WorkspaceManager, {
19
+ folders: [workspaceFolder]
20
+ });
21
+ });
22
+ let documentIndex = 1;
23
+ const parse = async (input, uri) => {
24
+ await initPromise;
25
+ const docUri = Utils.resolvePath(workspaceUri, "./src/", uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`);
26
+ const document = services.shared.workspace.LangiumDocumentFactory.fromString(stripIndent(input), docUri);
27
+ langiumDocuments.addDocument(document);
28
+ await documentBuilder.build([document], { validation: false });
29
+ return document;
30
+ };
31
+ const validate = async (input, uri) => {
32
+ await initPromise;
33
+ const document = typeof input === "string" ? await parse(input, uri) : input;
34
+ await documentBuilder.build([document], { validation: true });
35
+ const diagnostics = document.diagnostics ?? [];
36
+ const errors = diagnostics.map((d) => d.message);
37
+ return {
38
+ document,
39
+ diagnostics,
40
+ errors
56
41
  };
42
+ };
43
+ const validateAll = async () => {
44
+ await initPromise;
45
+ const docs = langiumDocuments.all.toArray();
46
+ await documentBuilder.build(docs, { validation: true });
47
+ const diagnostics = docs.flatMap((doc) => doc.diagnostics ?? []);
48
+ const errors = diagnostics.map((d) => d.message);
57
49
  return {
58
- services,
59
- parse,
60
- validate,
61
- validateAll,
62
- buildModel
50
+ diagnostics,
51
+ errors
63
52
  };
53
+ };
54
+ const buildModel = async () => {
55
+ await validateAll();
56
+ const model = modelBuilder.buildModel();
57
+ if (!model)
58
+ throw new Error("No model found");
59
+ return model;
60
+ };
61
+ return {
62
+ services,
63
+ parse,
64
+ validate,
65
+ validateAll,
66
+ buildModel
67
+ };
64
68
  }
65
- //# sourceMappingURL=testServices.js.map
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { LangiumDocument } from 'langium';
2
2
  export declare const printDocs: (docs: LangiumDocument[]) => string;
3
- //# sourceMappingURL=utils.d.ts.map
3
+ export declare function queueMicrotask(cb: () => void): Promise<void>;
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
- import { Utils } from 'vscode-uri';
2
- export const printDocs = (docs) => docs.map(d => ' - ' + Utils.basename(d.uri)).join('\n');
3
- //# sourceMappingURL=utils.js.map
1
+ export const printDocs = (docs) => docs.map((d) => " - " + d.uri.path).join("\n");
2
+ export function queueMicrotask(cb) {
3
+ return Promise.resolve().then(cb);
4
+ }
@@ -1,5 +1,3 @@
1
- import { type ValidationCheck } from 'langium';
2
1
  import type { ast } from '../ast';
3
2
  import type { LikeC4Services } from '../module';
4
3
  export declare const elementChecks: (services: LikeC4Services) => ValidationCheck<ast.Element>;
5
- //# sourceMappingURL=element.d.ts.map
@@ -1,41 +1,30 @@
1
- import { getDocument } from 'langium';
1
+ import { getDocument } from "langium";
2
2
  export const elementChecks = (services) => {
3
- const fqnIndex = services.likec4.FqnIndex;
4
- return (el, accept) => {
5
- const fqn = fqnIndex.getFqn(el);
6
- if (!fqn) {
7
- accept('error', 'Not indexed element', {
8
- node: el,
9
- property: 'name'
10
- });
11
- return;
12
- }
13
- const withSameFqn = fqnIndex
14
- .byFqn(fqn)
15
- .filter(v => v.el !== el)
16
- .head();
17
- if (withSameFqn) {
18
- accept('error', `Duplicate element name ${el.name !== fqn ? el.name + ' (' + fqn + ')' : el.name}`, {
19
- node: el,
20
- property: 'name',
21
- relatedInformation: [
22
- {
23
- location: {
24
- range: withSameFqn.el.$cstNode.range,
25
- uri: getDocument(withSameFqn.el).uri.toString()
26
- },
27
- message: `Already defined here`
28
- }
29
- ]
30
- });
31
- }
32
- // for (let i = 3; i < el.props.length; i++) {
33
- // accept('error', `Too many properties, max 3 allowed`, {
34
- // node: el,
35
- // property: 'props',
36
- // index: i
37
- // })
38
- // }
39
- };
3
+ const fqnIndex = services.likec4.FqnIndex;
4
+ return (el, accept) => {
5
+ const fqn = fqnIndex.getFqn(el);
6
+ if (!fqn) {
7
+ accept("error", "Not indexed element", {
8
+ node: el,
9
+ property: "name"
10
+ });
11
+ return;
12
+ }
13
+ const withSameFqn = fqnIndex.byFqn(fqn).filter((v) => v.el !== el).head();
14
+ if (withSameFqn) {
15
+ accept("error", `Duplicate element name ${el.name !== fqn ? el.name + " (" + fqn + ")" : el.name}`, {
16
+ node: el,
17
+ property: "name",
18
+ relatedInformation: [
19
+ {
20
+ location: {
21
+ range: withSameFqn.el.$cstNode.range,
22
+ uri: getDocument(withSameFqn.el).uri.toString()
23
+ },
24
+ message: `Already defined here`
25
+ }
26
+ ]
27
+ });
28
+ }
29
+ };
40
30
  };
41
- //# sourceMappingURL=element.js.map
@@ -1,3 +1,2 @@
1
1
  import type { LikeC4Services } from '../module';
2
2
  export declare function registerValidationChecks(services: LikeC4Services): void;
3
- //# sourceMappingURL=index.d.ts.map