@likec4/language-server 0.6.3 → 0.18.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/contrib/likec4.monarch.ts +1 -1
- package/contrib/likec4.tmLanguage.json +1 -1
- package/dist/ast.d.ts +4 -2
- package/dist/ast.js +13 -3
- package/dist/builtin.d.ts +1 -0
- package/dist/builtin.js +1 -0
- package/dist/elementRef.d.ts +2 -1
- package/dist/elementRef.js +1 -0
- package/dist/generated/ast.d.ts +12 -6
- package/dist/generated/ast.js +14 -2
- package/dist/generated/grammar.d.ts +3 -2
- package/dist/generated/grammar.js +79 -37
- package/dist/generated/module.d.ts +3 -2
- package/dist/generated/module.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +1 -0
- package/dist/lsp/DocumentSymbolProvider.d.ts +2 -1
- package/dist/lsp/DocumentSymbolProvider.js +29 -11
- package/dist/lsp/HoverProvider.d.ts +2 -1
- package/dist/lsp/HoverProvider.js +1 -0
- package/dist/lsp/SemanticTokenProvider.d.ts +1 -0
- package/dist/lsp/SemanticTokenProvider.js +9 -44
- package/dist/lsp/index.d.ts +1 -0
- package/dist/lsp/index.js +1 -0
- package/dist/model/fqn-computation.d.ts +4 -0
- package/dist/model/fqn-computation.js +41 -0
- package/dist/model/fqn-index.d.ts +36 -11
- package/dist/model/fqn-index.js +50 -89
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +2 -0
- package/dist/model/model-builder.d.ts +1 -0
- package/dist/model/model-builder.js +44 -30
- package/dist/model/model-locator.d.ts +1 -0
- package/dist/model/model-locator.js +24 -16
- package/dist/module.d.ts +1 -0
- package/dist/module.js +1 -4
- package/dist/protocol.d.ts +36 -0
- package/dist/protocol.js +22 -0
- package/dist/references/index.d.ts +1 -0
- package/dist/references/index.js +1 -0
- package/dist/references/scope-computation.d.ts +5 -1
- package/dist/references/scope-computation.js +11 -3
- package/dist/references/scope-provider.d.ts +4 -0
- package/dist/references/scope-provider.js +40 -30
- package/dist/registerProtocolHandlers.d.ts +1 -0
- package/dist/registerProtocolHandlers.js +48 -17
- package/dist/shared/CodeLensProvider.d.ts +2 -1
- package/dist/shared/CodeLensProvider.js +1 -0
- package/dist/shared/WorkspaceManager.d.ts +3 -2
- package/dist/shared/WorkspaceManager.js +3 -4
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.js +2 -0
- package/dist/test/testServices.d.ts +16 -0
- package/dist/test/testServices.js +58 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -0
- package/dist/validation/element.d.ts +1 -0
- package/dist/validation/element.js +9 -2
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/dist/validation/relation.d.ts +1 -0
- package/dist/validation/relation.js +1 -0
- package/dist/validation/specification.d.ts +1 -0
- package/dist/validation/specification.js +1 -0
- package/dist/validation/view.d.ts +1 -0
- package/dist/validation/view.js +1 -0
- package/package.json +24 -42
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Fqn, LikeC4Model, RelationID, ViewID } from '@likec4/core';
|
|
2
|
+
import type { DocumentUri, Location } from 'vscode-languageserver-protocol';
|
|
3
|
+
import { NotificationType0, RequestType0, RequestType } from 'vscode-languageserver-protocol';
|
|
4
|
+
interface BuildDocumentsParams {
|
|
5
|
+
docs: DocumentUri[];
|
|
6
|
+
}
|
|
7
|
+
export interface LocateElementParams {
|
|
8
|
+
element: Fqn;
|
|
9
|
+
property?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const locateElement: RequestType<LocateElementParams, Location | null, void>;
|
|
12
|
+
export declare const locateRelation: RequestType<{
|
|
13
|
+
id: RelationID;
|
|
14
|
+
}, Location | null, void>;
|
|
15
|
+
export declare const locateView: RequestType<{
|
|
16
|
+
id: ViewID;
|
|
17
|
+
}, Location | null, void>;
|
|
18
|
+
export declare const Rpc: {
|
|
19
|
+
readonly onDidChangeModel: NotificationType0;
|
|
20
|
+
readonly fetchModel: RequestType0<{
|
|
21
|
+
model: LikeC4Model | null;
|
|
22
|
+
}, void>;
|
|
23
|
+
readonly rebuild: RequestType0<{
|
|
24
|
+
docs: DocumentUri[];
|
|
25
|
+
}, void>;
|
|
26
|
+
readonly buildDocuments: RequestType<BuildDocumentsParams, void, void>;
|
|
27
|
+
readonly locateElement: RequestType<LocateElementParams, Location | null, void>;
|
|
28
|
+
readonly locateRelation: RequestType<{
|
|
29
|
+
id: RelationID;
|
|
30
|
+
}, Location | null, void>;
|
|
31
|
+
readonly locateView: RequestType<{
|
|
32
|
+
id: ViewID;
|
|
33
|
+
}, Location | null, void>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=protocol.d.ts.map
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NotificationType0, RequestType0, RequestType } from 'vscode-languageserver-protocol';
|
|
2
|
+
//#region From server
|
|
3
|
+
const onDidChangeModel = new NotificationType0('likec4/onDidChangeModel');
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region To server
|
|
6
|
+
const fetchModel = new RequestType0('likec4/fetchModel');
|
|
7
|
+
const rebuild = new RequestType0('likec4/rebuildModel');
|
|
8
|
+
const buildDocuments = new RequestType('likec4/buildDocuments');
|
|
9
|
+
export const locateElement = new RequestType('likec4/locateElement');
|
|
10
|
+
export const locateRelation = new RequestType('likec4/locateRelation');
|
|
11
|
+
export const locateView = new RequestType('likec4/locateView');
|
|
12
|
+
//#endregion
|
|
13
|
+
export const Rpc = {
|
|
14
|
+
onDidChangeModel,
|
|
15
|
+
fetchModel,
|
|
16
|
+
rebuild,
|
|
17
|
+
buildDocuments,
|
|
18
|
+
locateElement,
|
|
19
|
+
locateRelation,
|
|
20
|
+
locateView
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=protocol.js.map
|
package/dist/references/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { DefaultScopeComputation, MultiMap, type AstNodeDescription, type PrecomputedScopes } from 'langium';
|
|
2
|
-
import type { CancellationToken } from 'vscode-languageserver
|
|
2
|
+
import type { CancellationToken } from 'vscode-languageserver';
|
|
3
3
|
import { ast, type LikeC4LangiumDocument } from '../ast';
|
|
4
|
+
import type { LikeC4Services } from '../module';
|
|
4
5
|
type ElementsContainer = ast.Model | ast.ElementBody | ast.ExtendElementBody;
|
|
5
6
|
export declare class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
7
|
+
private services;
|
|
8
|
+
constructor(services: LikeC4Services);
|
|
6
9
|
computeExports(document: LikeC4LangiumDocument, _cancelToken: CancellationToken): Promise<AstNodeDescription[]>;
|
|
7
10
|
computeLocalScopes(document: LikeC4LangiumDocument, _cancelToken: CancellationToken): Promise<PrecomputedScopes>;
|
|
8
11
|
protected processContainer(container: ElementsContainer, scopes: PrecomputedScopes, document: LikeC4LangiumDocument): MultiMap<string, AstNodeDescription>;
|
|
9
12
|
}
|
|
10
13
|
export {};
|
|
14
|
+
//# sourceMappingURL=scope-computation.d.ts.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DefaultScopeComputation, MultiMap } from 'langium';
|
|
2
2
|
import { ast } from '../ast';
|
|
3
3
|
export class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
services;
|
|
5
|
+
constructor(services) {
|
|
6
|
+
super(services);
|
|
7
|
+
this.services = services;
|
|
8
|
+
}
|
|
7
9
|
computeExports(document, _cancelToken) {
|
|
8
10
|
const { specification, model, views } = document.parseResult.value;
|
|
9
11
|
const docExports = [];
|
|
@@ -16,6 +18,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
|
16
18
|
docExports.push(this.descriptions.createDescription(tag, '#' + tag.name, document));
|
|
17
19
|
}
|
|
18
20
|
}
|
|
21
|
+
document.c4fqns = undefined;
|
|
19
22
|
if (model) {
|
|
20
23
|
for (const elAst of model.elements) {
|
|
21
24
|
if (ast.isElement(elAst)) {
|
|
@@ -23,6 +26,10 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
// const c4fqns = document.c4fqns
|
|
30
|
+
// logger.debug(`doc ${document.uri.path}:
|
|
31
|
+
// fqns: ${c4fqns ? Array.from(c4fqns.keys()).join(', ') : '--'}
|
|
32
|
+
// `)
|
|
26
33
|
if (views) {
|
|
27
34
|
for (const viewAst of views.views) {
|
|
28
35
|
if ('name' in viewAst) {
|
|
@@ -74,3 +81,4 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
|
74
81
|
return localScope;
|
|
75
82
|
}
|
|
76
83
|
}
|
|
84
|
+
//# sourceMappingURL=scope-computation.js.map
|
|
@@ -4,7 +4,10 @@ import type { LikeC4Services } from '../module';
|
|
|
4
4
|
export declare class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
5
5
|
private fqnIndex;
|
|
6
6
|
constructor(services: LikeC4Services);
|
|
7
|
+
private directChildrenOf;
|
|
8
|
+
private uniqueDescedants;
|
|
7
9
|
private scopeElementRef;
|
|
10
|
+
private scopeExtendElement;
|
|
8
11
|
private scopeElementView;
|
|
9
12
|
getScope(context: ReferenceInfo): Scope;
|
|
10
13
|
protected computeScope(node: AstNode, referenceType: string): Scope;
|
|
@@ -13,3 +16,4 @@ export declare class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
13
16
|
*/
|
|
14
17
|
protected getGlobalScope(referenceType: string): Scope;
|
|
15
18
|
}
|
|
19
|
+
//# sourceMappingURL=scope-provider.d.ts.map
|
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import { DONE_RESULT, DefaultScopeProvider,
|
|
1
|
+
import { DONE_RESULT, DefaultScopeProvider, EMPTY_STREAM, StreamImpl, StreamScope, getDocument, stream } from 'langium';
|
|
2
2
|
import { ast } from '../ast';
|
|
3
|
-
import { elementRef, isElementRefHead, parentStrictElementRef
|
|
3
|
+
import { elementRef, isElementRefHead, parentStrictElementRef } from '../elementRef';
|
|
4
|
+
import { logger } from '../logger';
|
|
5
|
+
function toAstNodeDescription(entry) {
|
|
6
|
+
return {
|
|
7
|
+
documentUri: entry.doc.uri,
|
|
8
|
+
name: entry.name,
|
|
9
|
+
path: entry.path,
|
|
10
|
+
type: ast.Element
|
|
11
|
+
};
|
|
12
|
+
}
|
|
4
13
|
export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
5
14
|
fqnIndex;
|
|
6
15
|
constructor(services) {
|
|
7
16
|
super(services);
|
|
8
17
|
this.fqnIndex = services.likec4.FqnIndex;
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
directChildrenOf(parent) {
|
|
20
|
+
return this.fqnIndex
|
|
21
|
+
.directChildrenOf(parent)
|
|
22
|
+
.map(toAstNodeDescription);
|
|
23
|
+
}
|
|
24
|
+
uniqueDescedants(of) {
|
|
15
25
|
return new StreamImpl(() => {
|
|
16
|
-
const
|
|
17
|
-
const fqn =
|
|
26
|
+
const element = of();
|
|
27
|
+
const fqn = element && this.fqnIndex.get(element);
|
|
18
28
|
if (fqn) {
|
|
19
|
-
return this.fqnIndex.uniqueDescedants(fqn)
|
|
29
|
+
return this.fqnIndex.uniqueDescedants(fqn)
|
|
30
|
+
.map(toAstNodeDescription)
|
|
31
|
+
.iterator();
|
|
20
32
|
}
|
|
21
33
|
return null;
|
|
22
34
|
}, iterator => {
|
|
@@ -26,27 +38,25 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
26
38
|
return DONE_RESULT;
|
|
27
39
|
});
|
|
28
40
|
}
|
|
41
|
+
scopeElementRef(ref) {
|
|
42
|
+
const parentNode = ref.$container;
|
|
43
|
+
if (!ast.isElementRef(parentNode)) {
|
|
44
|
+
throw new Error('Expected be inside ElementRef');
|
|
45
|
+
}
|
|
46
|
+
return this.uniqueDescedants(() => parentNode.el.ref);
|
|
47
|
+
}
|
|
48
|
+
scopeExtendElement(extend) {
|
|
49
|
+
return this.uniqueDescedants(() => elementRef(extend.element));
|
|
50
|
+
}
|
|
29
51
|
scopeElementView({ viewOf }) {
|
|
30
52
|
if (!viewOf) {
|
|
31
53
|
return EMPTY_STREAM;
|
|
32
54
|
}
|
|
33
|
-
return
|
|
34
|
-
const target = elementRef(viewOf);
|
|
35
|
-
const fqn = target && this.fqnIndex.get(target);
|
|
36
|
-
if (fqn) {
|
|
37
|
-
return this.fqnIndex.uniqueDescedants(fqn).iterator();
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}, iterator => {
|
|
41
|
-
if (iterator) {
|
|
42
|
-
return iterator.next();
|
|
43
|
-
}
|
|
44
|
-
return DONE_RESULT;
|
|
45
|
-
});
|
|
55
|
+
return this.uniqueDescedants(() => elementRef(viewOf));
|
|
46
56
|
}
|
|
47
57
|
getScope(context) {
|
|
58
|
+
const referenceType = this.reflection.getReferenceType(context);
|
|
48
59
|
try {
|
|
49
|
-
const referenceType = this.reflection.getReferenceType(context);
|
|
50
60
|
const node = context.container;
|
|
51
61
|
// const path = this.services.workspace.AstNodeLocator.getAstNodePath(node)
|
|
52
62
|
if (referenceType === ast.Element) {
|
|
@@ -55,7 +65,7 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
55
65
|
return this.getGlobalScope(referenceType);
|
|
56
66
|
}
|
|
57
67
|
const parent = parentStrictElementRef(node);
|
|
58
|
-
return new StreamScope(this.
|
|
68
|
+
return new StreamScope(this.directChildrenOf(parent));
|
|
59
69
|
}
|
|
60
70
|
if (ast.isElementRef(node) && !isElementRefHead(node)) {
|
|
61
71
|
return new StreamScope(this.scopeElementRef(node));
|
|
@@ -64,9 +74,9 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
64
74
|
return this.computeScope(node, referenceType);
|
|
65
75
|
}
|
|
66
76
|
catch (e) {
|
|
67
|
-
console.error(e)
|
|
68
|
-
|
|
69
|
-
return
|
|
77
|
+
// console.error(e)
|
|
78
|
+
logger.error(e);
|
|
79
|
+
return this.getGlobalScope(referenceType);
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
computeScope(node, referenceType) {
|
|
@@ -87,8 +97,7 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
87
97
|
}
|
|
88
98
|
if (referenceType === ast.Element) {
|
|
89
99
|
if (ast.isExtendElementBody(container)) {
|
|
90
|
-
|
|
91
|
-
scopes.push(this.fqnIndex.uniqueDescedants(extendsOf));
|
|
100
|
+
scopes.push(this.scopeExtendElement(container.$container));
|
|
92
101
|
}
|
|
93
102
|
if (ast.isViewRule(container)) {
|
|
94
103
|
scopes.push(this.scopeElementView(container.$container));
|
|
@@ -108,3 +117,4 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
|
108
117
|
return new StreamScope(this.indexManager.allElements(referenceType));
|
|
109
118
|
}
|
|
110
119
|
}
|
|
120
|
+
//# sourceMappingURL=scope-provider.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { URI } from 'vscode-uri';
|
|
1
2
|
import { logger } from './logger';
|
|
2
|
-
import {
|
|
3
|
+
import { Rpc } from './protocol';
|
|
3
4
|
export function registerProtocolHandlers(services) {
|
|
4
5
|
const connection = services.shared.lsp.Connection;
|
|
5
6
|
if (!connection) {
|
|
@@ -8,7 +9,7 @@ export function registerProtocolHandlers(services) {
|
|
|
8
9
|
const modelBuilder = services.likec4.ModelBuilder;
|
|
9
10
|
const modelLocator = services.likec4.ModelLocator;
|
|
10
11
|
const LangiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
11
|
-
connection.onRequest(
|
|
12
|
+
connection.onRequest(Rpc.fetchModel, async (_cancelToken) => {
|
|
12
13
|
let model;
|
|
13
14
|
try {
|
|
14
15
|
model = modelBuilder.buildModel() ?? null;
|
|
@@ -17,27 +18,56 @@ export function registerProtocolHandlers(services) {
|
|
|
17
18
|
model = null;
|
|
18
19
|
logger.error(e);
|
|
19
20
|
}
|
|
20
|
-
return Promise.resolve({
|
|
21
|
-
model: model ?? null
|
|
22
|
-
});
|
|
21
|
+
return Promise.resolve({ model });
|
|
23
22
|
});
|
|
24
|
-
connection.onRequest(
|
|
23
|
+
connection.onRequest(Rpc.rebuild, async (cancelToken) => {
|
|
24
|
+
const changed = LangiumDocuments.all.map(d => d.uri).toArray();
|
|
25
|
+
logger.debug(`Rebuild all documents: [
|
|
26
|
+
${changed.map(d => d.toString()).join('\n ')}
|
|
27
|
+
]`);
|
|
28
|
+
await services.shared.workspace.DocumentBuilder.update(changed, [], cancelToken);
|
|
29
|
+
return {
|
|
30
|
+
docs: changed.map(d => d.toString())
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
connection.onRequest(Rpc.buildDocuments, async ({ docs }, cancelToken) => {
|
|
34
|
+
if (docs.length === 0) {
|
|
35
|
+
logger.debug(`Received empty request to rebuild`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
logger.debug(`Received request to rebuild: [
|
|
39
|
+
${docs.join('\n ')}
|
|
40
|
+
]`);
|
|
25
41
|
const changed = [];
|
|
26
42
|
for (const d of docs) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
try {
|
|
44
|
+
const uri = URI.parse(d);
|
|
45
|
+
if (LangiumDocuments.hasDocument(uri)) {
|
|
46
|
+
changed.push(uri);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
logger.warn(`LangiumDocuments does not have document: ${d}`);
|
|
50
|
+
LangiumDocuments.getOrCreateDocument(uri);
|
|
51
|
+
}
|
|
30
52
|
}
|
|
31
|
-
|
|
32
|
-
logger.error(
|
|
53
|
+
catch (e) {
|
|
54
|
+
logger.error(e);
|
|
33
55
|
}
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
if (changed.length !== docs.length) {
|
|
58
|
+
const all = LangiumDocuments.all.map(d => d.uri.toString()).toArray();
|
|
59
|
+
logger.warn(`
|
|
60
|
+
We have in LangiumDocuments: [
|
|
61
|
+
${all.join('\n ')}
|
|
62
|
+
]
|
|
63
|
+
We rebuild: [
|
|
64
|
+
${changed.join('\n ')}
|
|
65
|
+
]
|
|
66
|
+
`.trim());
|
|
67
|
+
}
|
|
38
68
|
await services.shared.workspace.DocumentBuilder.update(changed, [], cancelToken);
|
|
39
69
|
});
|
|
40
|
-
connection.onRequest(locateElement, async ({ element, property }, _cancelToken) => {
|
|
70
|
+
connection.onRequest(Rpc.locateElement, async ({ element, property }, _cancelToken) => {
|
|
41
71
|
try {
|
|
42
72
|
return Promise.resolve(modelLocator.locateElement(element, property ?? 'name'));
|
|
43
73
|
}
|
|
@@ -45,7 +75,7 @@ export function registerProtocolHandlers(services) {
|
|
|
45
75
|
return Promise.reject(e);
|
|
46
76
|
}
|
|
47
77
|
});
|
|
48
|
-
connection.onRequest(locateRelation, ({ id }, _cancelToken) => {
|
|
78
|
+
connection.onRequest(Rpc.locateRelation, ({ id }, _cancelToken) => {
|
|
49
79
|
try {
|
|
50
80
|
return Promise.resolve(modelLocator.locateRelation(id));
|
|
51
81
|
}
|
|
@@ -53,7 +83,7 @@ export function registerProtocolHandlers(services) {
|
|
|
53
83
|
return Promise.reject(e);
|
|
54
84
|
}
|
|
55
85
|
});
|
|
56
|
-
connection.onRequest(locateView, ({ id }, _cancelToken) => {
|
|
86
|
+
connection.onRequest(Rpc.locateView, ({ id }, _cancelToken) => {
|
|
57
87
|
try {
|
|
58
88
|
return Promise.resolve(modelLocator.locateView(id));
|
|
59
89
|
}
|
|
@@ -62,3 +92,4 @@ export function registerProtocolHandlers(services) {
|
|
|
62
92
|
}
|
|
63
93
|
});
|
|
64
94
|
}
|
|
95
|
+
//# sourceMappingURL=registerProtocolHandlers.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { LangiumDocument, LangiumSharedServices, MaybePromise } from 'langium';
|
|
2
2
|
import type { CodeLensProvider } from 'langium/lib/lsp/code-lens-provider';
|
|
3
|
-
import type { CancellationToken, CodeLens, CodeLensParams } from 'vscode-languageserver
|
|
3
|
+
import type { CancellationToken, CodeLens, CodeLensParams } from 'vscode-languageserver';
|
|
4
4
|
export declare class LikeC4CodeLensProvider implements CodeLensProvider {
|
|
5
5
|
private services;
|
|
6
6
|
constructor(services: LangiumSharedServices);
|
|
7
7
|
provideCodeLens(doc: LangiumDocument, _params: CodeLensParams, _cancelToken?: CancellationToken): MaybePromise<CodeLens[] | undefined>;
|
|
8
8
|
}
|
|
9
|
+
//# sourceMappingURL=CodeLensProvider.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LangiumDocument, LangiumDocumentFactory, LangiumSharedServices } from 'langium';
|
|
2
2
|
import { DefaultWorkspaceManager } from 'langium';
|
|
3
|
-
import type { WorkspaceFolder } from 'vscode-languageserver
|
|
3
|
+
import type { WorkspaceFolder } from 'vscode-languageserver';
|
|
4
4
|
export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
5
5
|
protected readonly documentFactory: LangiumDocumentFactory;
|
|
6
6
|
constructor(services: LangiumSharedServices);
|
|
@@ -9,5 +9,6 @@ export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
|
9
9
|
* folders and add them to the collector. This can be used to include built-in libraries of
|
|
10
10
|
* your language, which can be either loaded from provided files or constructed in memory.
|
|
11
11
|
*/
|
|
12
|
-
protected loadAdditionalDocuments(
|
|
12
|
+
protected loadAdditionalDocuments(_folders: WorkspaceFolder[], _collector: (document: LangiumDocument) => void): Promise<void>;
|
|
13
13
|
}
|
|
14
|
+
//# sourceMappingURL=WorkspaceManager.d.ts.map
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { DefaultWorkspaceManager } from 'langium';
|
|
2
|
-
import { URI } from 'vscode-uri';
|
|
3
|
-
import * as builtin from '../builtin';
|
|
4
2
|
export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
5
3
|
documentFactory;
|
|
6
4
|
constructor(services) {
|
|
@@ -12,8 +10,9 @@ export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
|
12
10
|
* folders and add them to the collector. This can be used to include built-in libraries of
|
|
13
11
|
* your language, which can be either loaded from provided files or constructed in memory.
|
|
14
12
|
*/
|
|
15
|
-
loadAdditionalDocuments(
|
|
16
|
-
collector(this.documentFactory.fromString(builtin.specification.document, URI.parse(builtin.specification.uri)))
|
|
13
|
+
loadAdditionalDocuments(_folders, _collector) {
|
|
14
|
+
// collector(this.documentFactory.fromString(builtin.specification.document, URI.parse(builtin.specification.uri)))
|
|
17
15
|
return Promise.resolve();
|
|
18
16
|
}
|
|
19
17
|
}
|
|
18
|
+
//# sourceMappingURL=WorkspaceManager.js.map
|
package/dist/shared/index.d.ts
CHANGED
package/dist/shared/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LikeC4LangiumDocument } from '../ast';
|
|
2
|
+
export declare function createTestServices(): {
|
|
3
|
+
services: import("../module").LikeC4Services;
|
|
4
|
+
parse: (input: string, uri?: string) => Promise<LikeC4LangiumDocument>;
|
|
5
|
+
validate: (input: string | LikeC4LangiumDocument) => Promise<{
|
|
6
|
+
document: LikeC4LangiumDocument;
|
|
7
|
+
diagnostics: import("vscode-languageserver-types").Diagnostic[];
|
|
8
|
+
errors: string[];
|
|
9
|
+
}>;
|
|
10
|
+
validateAll: () => Promise<{
|
|
11
|
+
diagnostics: import("vscode-languageserver-types").Diagnostic[];
|
|
12
|
+
errors: string[];
|
|
13
|
+
}>;
|
|
14
|
+
buildModel: () => Promise<import("@likec4/core").LikeC4Model>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=testServices.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createLanguageServices } from '../module';
|
|
2
|
+
import { EmptyFileSystem } from 'langium';
|
|
3
|
+
import { URI } from 'vscode-uri';
|
|
4
|
+
export function createTestServices() {
|
|
5
|
+
const services = createLanguageServices(EmptyFileSystem).likec4;
|
|
6
|
+
const metaData = services.LanguageMetaData;
|
|
7
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
8
|
+
const documentBuilder = services.shared.workspace.DocumentBuilder;
|
|
9
|
+
const modelBuilder = services.likec4.ModelBuilder;
|
|
10
|
+
const initPromise = services.shared.workspace.WorkspaceManager.initializeWorkspace([]);
|
|
11
|
+
let documentIndex = 1;
|
|
12
|
+
const parse = async (input, uri) => {
|
|
13
|
+
await initPromise;
|
|
14
|
+
uri = uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`;
|
|
15
|
+
const document = services.shared.workspace.LangiumDocumentFactory.fromString(input, URI.file(uri));
|
|
16
|
+
langiumDocuments.addDocument(document);
|
|
17
|
+
await documentBuilder.build([document], { validationChecks: 'none' });
|
|
18
|
+
return document;
|
|
19
|
+
};
|
|
20
|
+
const validate = async (input) => {
|
|
21
|
+
await initPromise;
|
|
22
|
+
const document = typeof input === 'string' ? await parse(input) : input;
|
|
23
|
+
await documentBuilder.build([document], { validationChecks: 'all' });
|
|
24
|
+
const diagnostics = document.diagnostics ?? [];
|
|
25
|
+
const errors = diagnostics.map(d => d.message);
|
|
26
|
+
return {
|
|
27
|
+
document,
|
|
28
|
+
diagnostics,
|
|
29
|
+
errors
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const validateAll = async () => {
|
|
33
|
+
await initPromise;
|
|
34
|
+
const docs = langiumDocuments.all.toArray();
|
|
35
|
+
await documentBuilder.build(docs, { validationChecks: 'all' });
|
|
36
|
+
const diagnostics = docs.flatMap(doc => doc.diagnostics ?? []);
|
|
37
|
+
const errors = diagnostics.map(d => d.message);
|
|
38
|
+
return {
|
|
39
|
+
diagnostics,
|
|
40
|
+
errors
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const buildModel = async () => {
|
|
44
|
+
await validateAll();
|
|
45
|
+
const model = modelBuilder.buildModel();
|
|
46
|
+
if (!model)
|
|
47
|
+
throw new Error('No model found');
|
|
48
|
+
return model;
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
services,
|
|
52
|
+
parse,
|
|
53
|
+
validate,
|
|
54
|
+
validateAll,
|
|
55
|
+
buildModel
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=testServices.js.map
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -9,8 +9,14 @@ export const elementChecks = (services) => {
|
|
|
9
9
|
});
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const withSameFqn = fqnIndex.byFqn(fqn);
|
|
13
|
-
if (withSameFqn
|
|
12
|
+
const withSameFqn = fqnIndex.byFqn(fqn).limit(2).count();
|
|
13
|
+
if (withSameFqn > 1) {
|
|
14
|
+
// console.error(withSameFqn.map(e => ({
|
|
15
|
+
// fqn,
|
|
16
|
+
// name: el.name,
|
|
17
|
+
// path: e.path,
|
|
18
|
+
// doc: e.doc.uri.toString()
|
|
19
|
+
// })))
|
|
14
20
|
accept('error', `Duplicate element name ${el.name !== fqn ? el.name + ' (' + fqn + ')' : el.name}`, {
|
|
15
21
|
node: el,
|
|
16
22
|
property: 'name'
|
|
@@ -18,3 +24,4 @@ export const elementChecks = (services) => {
|
|
|
18
24
|
}
|
|
19
25
|
};
|
|
20
26
|
};
|
|
27
|
+
//# sourceMappingURL=element.js.map
|
package/dist/validation/index.js
CHANGED
|
@@ -2,3 +2,4 @@ import type { ValidationCheck } from 'langium';
|
|
|
2
2
|
import type { ast } from '../ast';
|
|
3
3
|
import type { LikeC4Services } from '../module';
|
|
4
4
|
export declare const relationChecks: (services: LikeC4Services) => ValidationCheck<ast.Relation>;
|
|
5
|
+
//# sourceMappingURL=relation.d.ts.map
|
|
@@ -3,3 +3,4 @@ import { ast } from '../ast';
|
|
|
3
3
|
import type { LikeC4Services } from '../module';
|
|
4
4
|
export declare const elementKindChecks: (services: LikeC4Services) => ValidationCheck<ast.ElementKind>;
|
|
5
5
|
export declare const tagChecks: (services: LikeC4Services) => ValidationCheck<ast.Tag>;
|
|
6
|
+
//# sourceMappingURL=specification.d.ts.map
|
package/dist/validation/view.js
CHANGED