@likec4/language-server 0.37.1 → 0.41.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 +5 -5
- package/contrib/likec4.tmLanguage.json +1 -1
- package/dist/Rpc.d.ts +7 -0
- package/dist/Rpc.js +130 -0
- package/dist/ast.d.ts +20 -0
- package/dist/ast.js +169 -141
- package/dist/elementRef.js +31 -44
- package/dist/generated/ast.d.ts +48 -7
- package/dist/generated/ast.js +344 -315
- package/dist/generated/grammar.js +2 -3177
- package/dist/generated/module.js +13 -18
- package/dist/index.js +2 -3
- package/dist/logger.js +39 -42
- package/dist/lsp/CodeLensProvider.js +28 -32
- package/dist/lsp/DocumentLinkProvider.js +26 -33
- package/dist/lsp/DocumentSymbolProvider.js +165 -167
- package/dist/lsp/HoverProvider.js +35 -48
- package/dist/lsp/SemanticTokenProvider.js +160 -201
- package/dist/lsp/index.js +5 -6
- package/dist/model/fqn-computation.js +39 -40
- package/dist/model/fqn-index.js +117 -141
- package/dist/model/index.js +5 -6
- package/dist/model/model-builder.d.ts +10 -5
- package/dist/model/model-builder.js +247 -176
- package/dist/model/model-locator.d.ts +1 -1
- package/dist/model/model-locator.js +102 -100
- package/dist/model/model-parser.d.ts +2 -6
- package/dist/model/model-parser.js +284 -286
- package/dist/module.d.ts +4 -1
- package/dist/module.js +69 -60
- package/dist/protocol.d.ts +16 -19
- package/dist/protocol.js +14 -22
- package/dist/references/index.js +2 -3
- package/dist/references/scope-computation.js +72 -69
- package/dist/references/scope-provider.js +126 -116
- package/dist/shared/WorkspaceManager.d.ts +2 -3
- package/dist/shared/WorkspaceManager.js +13 -16
- package/dist/shared/index.js +1 -2
- package/dist/test/index.js +1 -2
- package/dist/test/testServices.js +73 -61
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +4 -3
- package/dist/validation/element.d.ts +1 -0
- package/dist/validation/element.js +31 -38
- package/dist/validation/index.js +37 -46
- package/dist/validation/relation.js +46 -46
- package/dist/validation/specification.d.ts +1 -0
- package/dist/validation/specification.js +33 -30
- package/dist/validation/view.js +16 -22
- package/dist/view-utils/assignNavigateTo.d.ts +3 -0
- package/dist/view-utils/assignNavigateTo.js +20 -0
- package/dist/view-utils/index.d.ts +4 -0
- package/dist/view-utils/index.js +3 -0
- package/dist/view-utils/resolve-extended-views.d.ts +7 -0
- package/dist/view-utils/resolve-extended-views.js +41 -0
- package/dist/view-utils/resolve-relative-paths.d.ts +3 -0
- package/dist/view-utils/resolve-relative-paths.js +76 -0
- package/package.json +33 -18
- package/dist/registerProtocolHandlers.d.ts +0 -3
- package/dist/registerProtocolHandlers.js +0 -112
package/dist/module.js
CHANGED
|
@@ -1,69 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
WorkspaceCache
|
|
3
|
+
} from "langium";
|
|
4
|
+
import { EmptyFileSystem, createDefaultModule, createDefaultSharedModule, inject } from "langium";
|
|
5
|
+
import { LikeC4GeneratedModule, LikeC4GeneratedSharedModule } from "./generated/module.js";
|
|
6
|
+
import {
|
|
7
|
+
LikeC4CodeLensProvider,
|
|
8
|
+
LikeC4DocumentLinkProvider,
|
|
9
|
+
LikeC4DocumentSymbolProvider,
|
|
10
|
+
LikeC4HoverProvider,
|
|
11
|
+
LikeC4SemanticTokenProvider
|
|
12
|
+
} from "./lsp/index.js";
|
|
13
|
+
import { FqnIndex, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from "./model/index.js";
|
|
14
|
+
import { LikeC4ScopeComputation, LikeC4ScopeProvider } from "./references/index.js";
|
|
15
|
+
import { Rpc } from "./Rpc.js";
|
|
16
|
+
import { LikeC4WorkspaceManager } from "./shared/index.js";
|
|
17
|
+
import { registerValidationChecks } from "./validation/index.js";
|
|
18
|
+
import { logger } from "./logger.js";
|
|
19
|
+
import { serializeError } from "@likec4/core";
|
|
11
20
|
function bind(Type) {
|
|
12
|
-
|
|
21
|
+
return (services) => new Type(services);
|
|
13
22
|
}
|
|
14
23
|
export const LikeC4Module = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ScopeProvider: bind(LikeC4ScopeProvider)
|
|
35
|
-
}
|
|
24
|
+
WorkspaceCache: (services) => new WorkspaceCache(services.shared),
|
|
25
|
+
Rpc: bind(Rpc),
|
|
26
|
+
likec4: {
|
|
27
|
+
FqnIndex: bind(FqnIndex),
|
|
28
|
+
ModelParser: bind(LikeC4ModelParser),
|
|
29
|
+
ModelBuilder: bind(LikeC4ModelBuilder),
|
|
30
|
+
ModelLocator: bind(LikeC4ModelLocator)
|
|
31
|
+
},
|
|
32
|
+
lsp: {
|
|
33
|
+
DocumentSymbolProvider: bind(LikeC4DocumentSymbolProvider),
|
|
34
|
+
SemanticTokenProvider: bind(LikeC4SemanticTokenProvider),
|
|
35
|
+
HoverProvider: bind(LikeC4HoverProvider),
|
|
36
|
+
CodeLensProvider: bind(LikeC4CodeLensProvider),
|
|
37
|
+
DocumentLinkProvider: bind(LikeC4DocumentLinkProvider)
|
|
38
|
+
},
|
|
39
|
+
references: {
|
|
40
|
+
ScopeComputation: bind(LikeC4ScopeComputation),
|
|
41
|
+
ScopeProvider: bind(LikeC4ScopeProvider)
|
|
42
|
+
}
|
|
36
43
|
};
|
|
37
44
|
const LikeC4SharedModule = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
workspace: {
|
|
46
|
+
WorkspaceManager: (services) => new LikeC4WorkspaceManager(services)
|
|
47
|
+
}
|
|
41
48
|
};
|
|
42
49
|
export function createLanguageServices(context) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
connection.telemetry.logEvent({ eventName: 'error', error: message });
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const moduleContext = {
|
|
59
|
-
...EmptyFileSystem,
|
|
60
|
-
...context
|
|
50
|
+
const connection = context?.connection;
|
|
51
|
+
if (connection) {
|
|
52
|
+
const original = logger.error.bind(logger);
|
|
53
|
+
logger.error = (arg) => {
|
|
54
|
+
if (typeof arg === "string") {
|
|
55
|
+
original(arg);
|
|
56
|
+
connection.telemetry.logEvent({ eventName: "error", error: arg });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { message, error } = serializeError(arg);
|
|
60
|
+
original(error);
|
|
61
|
+
connection.telemetry.logEvent({ eventName: "error", error: message });
|
|
61
62
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
}
|
|
64
|
+
const moduleContext = {
|
|
65
|
+
...EmptyFileSystem,
|
|
66
|
+
...context
|
|
67
|
+
};
|
|
68
|
+
const shared = inject(
|
|
69
|
+
createDefaultSharedModule(moduleContext),
|
|
70
|
+
LikeC4GeneratedSharedModule,
|
|
71
|
+
LikeC4SharedModule
|
|
72
|
+
);
|
|
73
|
+
const likec4 = inject(createDefaultModule({ shared }), LikeC4GeneratedModule, LikeC4Module);
|
|
74
|
+
shared.ServiceRegistry.register(likec4);
|
|
75
|
+
registerValidationChecks(likec4);
|
|
76
|
+
likec4.Rpc.init();
|
|
77
|
+
return { shared, likec4 };
|
|
68
78
|
}
|
|
69
|
-
//# sourceMappingURL=module.js.map
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import type { ComputedView, Fqn, LikeC4Model, LikeC4RawModel, RelationID, ViewID } from '@likec4/core';
|
|
2
2
|
import type { DocumentUri, Location } from 'vscode-languageserver-protocol';
|
|
3
3
|
import { NotificationType, RequestType, RequestType0 } from 'vscode-languageserver-protocol';
|
|
4
|
+
export declare const onDidChangeModel: NotificationType<string>;
|
|
5
|
+
export declare const fetchRawModel: RequestType0<{
|
|
6
|
+
rawmodel: LikeC4RawModel | null;
|
|
7
|
+
}, void>;
|
|
8
|
+
export declare const fetchModel: RequestType0<{
|
|
9
|
+
model: LikeC4Model | null;
|
|
10
|
+
}, void>;
|
|
11
|
+
export declare const computeView: RequestType<{
|
|
12
|
+
viewId: ViewID;
|
|
13
|
+
}, {
|
|
14
|
+
view: ComputedView | null;
|
|
15
|
+
}, void>;
|
|
16
|
+
export declare const rebuild: RequestType0<{
|
|
17
|
+
docs: DocumentUri[];
|
|
18
|
+
}, void>;
|
|
4
19
|
interface BuildDocumentsParams {
|
|
5
20
|
docs: DocumentUri[];
|
|
6
21
|
}
|
|
22
|
+
export declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
|
|
7
23
|
export type LocateParams = {
|
|
8
24
|
element: Fqn;
|
|
9
25
|
property?: string;
|
|
@@ -13,24 +29,5 @@ export type LocateParams = {
|
|
|
13
29
|
view: ViewID;
|
|
14
30
|
};
|
|
15
31
|
export declare const locate: RequestType<LocateParams, Location | null, void>;
|
|
16
|
-
export declare const Rpc: {
|
|
17
|
-
readonly onDidChangeModel: NotificationType<string>;
|
|
18
|
-
readonly fetchModel: RequestType0<{
|
|
19
|
-
model: LikeC4Model | null;
|
|
20
|
-
}, void>;
|
|
21
|
-
readonly fetchRawModel: RequestType0<{
|
|
22
|
-
rawmodel: LikeC4RawModel | null;
|
|
23
|
-
}, void>;
|
|
24
|
-
readonly computeView: RequestType<{
|
|
25
|
-
viewId: ViewID;
|
|
26
|
-
}, {
|
|
27
|
-
view: ComputedView | null;
|
|
28
|
-
}, void>;
|
|
29
|
-
readonly rebuild: RequestType0<{
|
|
30
|
-
docs: DocumentUri[];
|
|
31
|
-
}, void>;
|
|
32
|
-
readonly buildDocuments: RequestType<BuildDocumentsParams, void, void>;
|
|
33
|
-
readonly locate: RequestType<LocateParams, Location | null, void>;
|
|
34
|
-
};
|
|
35
32
|
export {};
|
|
36
33
|
//# sourceMappingURL=protocol.d.ts.map
|
package/dist/protocol.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import { NotificationType, RequestType, RequestType0 } from
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
fetchModel,
|
|
16
|
-
fetchRawModel,
|
|
17
|
-
computeView,
|
|
18
|
-
rebuild,
|
|
19
|
-
buildDocuments,
|
|
20
|
-
locate
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=protocol.js.map
|
|
1
|
+
import { NotificationType, RequestType, RequestType0 } from "vscode-languageserver-protocol";
|
|
2
|
+
export const onDidChangeModel = new NotificationType("likec4/onDidChangeModel");
|
|
3
|
+
export const fetchRawModel = new RequestType0(
|
|
4
|
+
"likec4/fetchRaw"
|
|
5
|
+
);
|
|
6
|
+
export const fetchModel = new RequestType0("likec4/fetchModel");
|
|
7
|
+
export const computeView = new RequestType(
|
|
8
|
+
"likec4/computeView"
|
|
9
|
+
);
|
|
10
|
+
export const rebuild = new RequestType0("likec4/rebuildModel");
|
|
11
|
+
export const buildDocuments = new RequestType(
|
|
12
|
+
"likec4/buildDocuments"
|
|
13
|
+
);
|
|
14
|
+
export const locate = new RequestType("likec4/locate");
|
package/dist/references/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./scope-computation.js";
|
|
2
|
+
export * from "./scope-provider.js";
|
|
@@ -1,80 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
DefaultScopeComputation,
|
|
3
|
+
MultiMap
|
|
4
|
+
} from "langium";
|
|
5
|
+
import { isEmpty } from "remeda";
|
|
6
|
+
import { ast } from "../ast.js";
|
|
4
7
|
export class LikeC4ScopeComputation extends DefaultScopeComputation {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
for (const spec of specification.tags) {
|
|
15
|
-
if (spec.tag && !isEmpty(spec.tag.name)) {
|
|
16
|
-
docExports.push(this.descriptions.createDescription(spec.tag, spec.tag.name, document));
|
|
17
|
-
docExports.push(this.descriptions.createDescription(spec.tag, '#' + spec.tag.name, document));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
8
|
+
computeExports(document, _cancelToken) {
|
|
9
|
+
const { specification, model, views } = document.parseResult.value;
|
|
10
|
+
const docExports = [];
|
|
11
|
+
if (specification) {
|
|
12
|
+
for (const spec of specification.elements) {
|
|
13
|
+
if (spec.kind && !isEmpty(spec.kind.name)) {
|
|
14
|
+
docExports.push(this.descriptions.createDescription(spec.kind, spec.kind.name, document));
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
16
|
+
}
|
|
17
|
+
for (const spec of specification.tags) {
|
|
18
|
+
if (spec.tag && !isEmpty(spec.tag.name)) {
|
|
19
|
+
docExports.push(this.descriptions.createDescription(spec.tag, spec.tag.name, document));
|
|
20
|
+
docExports.push(this.descriptions.createDescription(spec.tag, "#" + spec.tag.name, document));
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}
|
|
22
|
+
}
|
|
23
|
+
for (const spec of specification.relationships) {
|
|
24
|
+
if (spec.kind && !isEmpty(spec.kind.name)) {
|
|
25
|
+
docExports.push(this.descriptions.createDescription(spec.kind, spec.kind.name, document));
|
|
35
26
|
}
|
|
36
|
-
|
|
27
|
+
}
|
|
37
28
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const nested = this.processContainer(root.model, scopes, document);
|
|
43
|
-
scopes.addAll(root, nested.values());
|
|
29
|
+
if (model && model.elements.length > 0) {
|
|
30
|
+
for (const elAst of model.elements) {
|
|
31
|
+
if (ast.isElement(elAst) && !isEmpty(elAst.name)) {
|
|
32
|
+
docExports.push(this.descriptions.createDescription(elAst, elAst.name, document));
|
|
44
33
|
}
|
|
45
|
-
|
|
34
|
+
}
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (ast.isRelation(el)) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
let subcontainer;
|
|
55
|
-
if (ast.isElement(el) && !isEmpty(el.name)) {
|
|
56
|
-
localScope.add(el.name, this.descriptions.createDescription(el, el.name, document));
|
|
57
|
-
subcontainer = el.body;
|
|
58
|
-
}
|
|
59
|
-
else if (ast.isExtendElement(el)) {
|
|
60
|
-
subcontainer = el.body;
|
|
61
|
-
}
|
|
62
|
-
if (subcontainer && subcontainer.elements.length > 0) {
|
|
63
|
-
const nested = this.processContainer(subcontainer, scopes, document);
|
|
64
|
-
for (const [nestedName, desc] of nested) {
|
|
65
|
-
nestedScopes.add(nestedName, desc);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
36
|
+
if (views && views.views.length > 0) {
|
|
37
|
+
for (const viewAst of views.views) {
|
|
38
|
+
if (viewAst.name && !isEmpty(viewAst.name)) {
|
|
39
|
+
docExports.push(this.descriptions.createDescription(viewAst, viewAst.name, document));
|
|
68
40
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve(docExports);
|
|
44
|
+
}
|
|
45
|
+
async computeLocalScopes(document, _cancelToken) {
|
|
46
|
+
const root = document.parseResult.value;
|
|
47
|
+
const scopes = new MultiMap();
|
|
48
|
+
if (root.model) {
|
|
49
|
+
const nested = this.processContainer(root.model, scopes, document);
|
|
50
|
+
scopes.addAll(root, nested.values());
|
|
51
|
+
}
|
|
52
|
+
return Promise.resolve(scopes);
|
|
53
|
+
}
|
|
54
|
+
processContainer(container, scopes, document) {
|
|
55
|
+
const localScope = new MultiMap();
|
|
56
|
+
const nestedScopes = new MultiMap();
|
|
57
|
+
for (const el of container.elements) {
|
|
58
|
+
if (ast.isRelation(el)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let subcontainer;
|
|
62
|
+
if (ast.isElement(el) && !isEmpty(el.name)) {
|
|
63
|
+
localScope.add(el.name, this.descriptions.createDescription(el, el.name, document));
|
|
64
|
+
subcontainer = el.body;
|
|
65
|
+
} else if (ast.isExtendElement(el)) {
|
|
66
|
+
subcontainer = el.body;
|
|
67
|
+
}
|
|
68
|
+
if (subcontainer && subcontainer.elements.length > 0) {
|
|
69
|
+
const nested = this.processContainer(subcontainer, scopes, document);
|
|
70
|
+
for (const [nestedName, desc] of nested) {
|
|
71
|
+
nestedScopes.add(nestedName, desc);
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const [name, descriptions] of nestedScopes.entriesGroupedByKey()) {
|
|
76
|
+
if (!localScope.has(name) && descriptions.length === 1) {
|
|
77
|
+
localScope.add(name, descriptions[0]);
|
|
78
|
+
}
|
|
78
79
|
}
|
|
80
|
+
scopes.addAll(container, localScope.values());
|
|
81
|
+
return localScope;
|
|
82
|
+
}
|
|
79
83
|
}
|
|
80
|
-
//# sourceMappingURL=scope-computation.js.map
|
|
@@ -1,129 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
95
|
+
}
|
|
96
|
+
return this.computeScope(container, referenceType);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
logError(e);
|
|
99
|
+
return this.getGlobalScope(referenceType);
|
|
121
100
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|