@likec4/language-server 0.6.1 → 0.6.2

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 (101) hide show
  1. package/package.json +5 -5
  2. package/contrib/likec4.monarch.ts +0 -31
  3. package/contrib/likec4.tmLanguage.json +0 -73
  4. package/dist/__test__/parser-smoke/01-Specification.d.ts +0 -3
  5. package/dist/__test__/parser-smoke/01-Specification.js +0 -42
  6. package/dist/__test__/parser-smoke/02-Model.d.ts +0 -9
  7. package/dist/__test__/parser-smoke/02-Model.js +0 -110
  8. package/dist/__test__/parser-smoke/03-ModelRelation.d.ts +0 -6
  9. package/dist/__test__/parser-smoke/03-ModelRelation.js +0 -81
  10. package/dist/__test__/parser-smoke/04-Scope.d.ts +0 -2
  11. package/dist/__test__/parser-smoke/04-Scope.js +0 -38
  12. package/dist/__test__/parser-smoke/05-StrictElementRef.d.ts +0 -3
  13. package/dist/__test__/parser-smoke/05-StrictElementRef.js +0 -46
  14. package/dist/__test__/parser-smoke/06-ElementRef.d.ts +0 -2
  15. package/dist/__test__/parser-smoke/06-ElementRef.js +0 -59
  16. package/dist/__test__/parser-smoke/07-Views.d.ts +0 -10
  17. package/dist/__test__/parser-smoke/07-Views.js +0 -146
  18. package/dist/__test__/parser-smoke/08-Structurizr.d.ts +0 -1
  19. package/dist/__test__/parser-smoke/08-Structurizr.js +0 -22
  20. package/dist/__test__/parser-smoke/index.d.ts +0 -8
  21. package/dist/__test__/parser-smoke/index.js +0 -8
  22. package/dist/__test__/parser-smoke-extendsElement.spec.d.ts +0 -1
  23. package/dist/__test__/parser-smoke-extendsElement.spec.js +0 -36
  24. package/dist/__test__/parser-smoke.spec.d.ts +0 -1
  25. package/dist/__test__/parser-smoke.spec.js +0 -28
  26. package/dist/ast.d.ts +0 -73
  27. package/dist/ast.js +0 -133
  28. package/dist/builtin.d.ts +0 -4
  29. package/dist/builtin.js +0 -8
  30. package/dist/elementRef.d.ts +0 -6
  31. package/dist/elementRef.js +0 -39
  32. package/dist/generated/ast.d.ts +0 -359
  33. package/dist/generated/ast.js +0 -376
  34. package/dist/generated/grammar.d.ts +0 -6
  35. package/dist/generated/grammar.js +0 -2542
  36. package/dist/generated/module.d.ts +0 -9
  37. package/dist/generated/module.js +0 -26
  38. package/dist/index.d.ts +0 -3
  39. package/dist/index.js +0 -14
  40. package/dist/logger.d.ts +0 -8
  41. package/dist/logger.js +0 -20
  42. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -21
  43. package/dist/lsp/DocumentSymbolProvider.js +0 -149
  44. package/dist/lsp/HoverProvider.d.ts +0 -8
  45. package/dist/lsp/HoverProvider.js +0 -54
  46. package/dist/lsp/SemanticTokenProvider.d.ts +0 -6
  47. package/dist/lsp/SemanticTokenProvider.js +0 -221
  48. package/dist/lsp/index.d.ts +0 -3
  49. package/dist/lsp/index.js +0 -3
  50. package/dist/model/fqn-index.d.ts +0 -17
  51. package/dist/model/fqn-index.js +0 -138
  52. package/dist/model/index.d.ts +0 -3
  53. package/dist/model/index.js +0 -3
  54. package/dist/model/model-builder.d.ts +0 -26
  55. package/dist/model/model-builder.js +0 -332
  56. package/dist/model/model-builder.spec.d.ts +0 -1
  57. package/dist/model/model-builder.spec.js +0 -141
  58. package/dist/model/model-locator.d.ts +0 -16
  59. package/dist/model/model-locator.js +0 -108
  60. package/dist/module.d.ts +0 -18
  61. package/dist/module.js +0 -61
  62. package/dist/protocol.d.ts +0 -39
  63. package/dist/protocol.js +0 -19
  64. package/dist/references/index.d.ts +0 -2
  65. package/dist/references/index.js +0 -2
  66. package/dist/references/scope-computation.d.ts +0 -10
  67. package/dist/references/scope-computation.js +0 -76
  68. package/dist/references/scope-provider.d.ts +0 -15
  69. package/dist/references/scope-provider.js +0 -110
  70. package/dist/registerProtocolHandlers.d.ts +0 -2
  71. package/dist/registerProtocolHandlers.js +0 -64
  72. package/dist/shared/CodeLensProvider.d.ts +0 -8
  73. package/dist/shared/CodeLensProvider.js +0 -35
  74. package/dist/shared/WorkspaceManager.d.ts +0 -13
  75. package/dist/shared/WorkspaceManager.js +0 -19
  76. package/dist/shared/index.d.ts +0 -2
  77. package/dist/shared/index.js +0 -2
  78. package/dist/test/index.d.ts +0 -1
  79. package/dist/test/index.js +0 -1
  80. package/dist/test/testServices.d.ts +0 -15
  81. package/dist/test/testServices.js +0 -57
  82. package/dist/utils.d.ts +0 -2
  83. package/dist/utils.js +0 -7
  84. package/dist/validation/element.d.ts +0 -5
  85. package/dist/validation/element.js +0 -20
  86. package/dist/validation/element.spec.d.ts +0 -1
  87. package/dist/validation/element.spec.js +0 -65
  88. package/dist/validation/index.d.ts +0 -2
  89. package/dist/validation/index.js +0 -22
  90. package/dist/validation/relation.d.ts +0 -4
  91. package/dist/validation/relation.js +0 -53
  92. package/dist/validation/relation.spec.d.ts +0 -1
  93. package/dist/validation/relation.spec.js +0 -93
  94. package/dist/validation/specification.d.ts +0 -5
  95. package/dist/validation/specification.js +0 -33
  96. package/dist/validation/specification.spec.d.ts +0 -1
  97. package/dist/validation/specification.spec.js +0 -31
  98. package/dist/validation/view.d.ts +0 -4
  99. package/dist/validation/view.js +0 -20
  100. package/dist/validation/view.spec.d.ts +0 -1
  101. package/dist/validation/view.spec.js +0 -20
@@ -1,146 +0,0 @@
1
- const model = `
2
- specification {
3
- element component
4
- }
5
- model {
6
- component user
7
- component system {
8
- component backend {
9
- component model
10
- component api
11
- }
12
- component auth {
13
- component api
14
- }
15
- component frontend
16
- }
17
- component infra {
18
- component database
19
- }
20
-
21
- backend.model -> infra.database
22
- backend.api -> backend.model
23
- auth.api -> backend.api
24
- frontend -> auth.api
25
- frontend -> backend.api
26
- user -> frontend
27
- }
28
- `;
29
- export const valid_07_View = model +
30
- `
31
- views {
32
- view index {
33
- include *
34
- }
35
- }
36
- `;
37
- export const valid_07_ViewOf = model +
38
- `
39
- views {
40
- view index of system.backend {
41
- include *
42
- }
43
- }
44
- `;
45
- export const valid_07_ViewRules = model +
46
- `
47
- views {
48
- view {
49
- include *,
50
- infra.*,
51
- backend.*
52
- exclude frontend
53
- }
54
- }
55
- `;
56
- // Two api: in backend and auth
57
- export const invalid_07_ViewRules_Inambiqutes = model +
58
- `
59
- views {
60
- view of system {
61
- include api
62
- }
63
- }
64
- `;
65
- export const valid_07_ViewRules_IncludeScopeOf = model +
66
- `
67
- views {
68
- view of system.backend {
69
- include api, auth.api
70
- }
71
- }
72
- `;
73
- export const valid_07_ViewProperties = model +
74
- `
75
- views {
76
- view {
77
- title 'User view'
78
- description "
79
- View description
80
- "
81
- include *
82
- exclude -> user
83
- }
84
- }
85
- `;
86
- export const valid_07_ViewRules_Relations = model +
87
- `
88
- views {
89
- view {
90
- include
91
- -> backend,
92
- -> backend.*,
93
- -> backend ->,
94
- -> backend.* ->,
95
- backend ->,
96
- backend.* ->
97
- exclude
98
- * -> infra,
99
- * -> infra.*,
100
- * -> *
101
- }
102
- }
103
- `;
104
- export const valid_07_ViewStyleRules = model +
105
- `
106
- views {
107
- view {
108
- include *
109
- style * {
110
- color: secondary
111
- }
112
- style backend, infra {
113
- color: muted
114
- }
115
- exclude -> frontend
116
- }
117
- }
118
- `;
119
- export const invalid_07_ViewStyleRules = model +
120
- `
121
- views {
122
- view {
123
- include *
124
- style backend, {
125
- color muted
126
- }
127
- }
128
- }
129
- `;
130
- export const valid_07_ViewLayoutRules = model +
131
- `
132
- views {
133
- view {
134
- include *
135
- style * {
136
- color: secondary
137
- }
138
- autoLayout BottomTop
139
- exclude -> frontend
140
- }
141
- view {
142
- autoLayout LeftRight
143
- include *
144
- }
145
- }
146
- `;
@@ -1 +0,0 @@
1
- export declare const valid_08_Structurizr: string;
@@ -1,22 +0,0 @@
1
- const model = `
2
- specification {
3
- element person
4
- element group
5
- element softwareSystem
6
- element container
7
- element component
8
- }
9
- `;
10
- export const valid_08_Structurizr = model +
11
- `
12
- model {
13
- u = person "User"
14
- s = softwareSystem "Software System" {
15
- webapp = container "Web Application" "" "Spring Boot"
16
- database = container "Database" "" "Relational database schema"
17
- }
18
-
19
- u -> webapp "Uses"
20
- webapp -> database "Reads from and writes to"
21
- }
22
- `;
@@ -1,8 +0,0 @@
1
- export * from './01-Specification';
2
- export * from './02-Model';
3
- export * from './03-ModelRelation';
4
- export * from './04-Scope';
5
- export * from './05-StrictElementRef';
6
- export * from './06-ElementRef';
7
- export * from './07-Views';
8
- export * from './08-Structurizr';
@@ -1,8 +0,0 @@
1
- export * from './01-Specification';
2
- export * from './02-Model';
3
- export * from './03-ModelRelation';
4
- export * from './04-Scope';
5
- export * from './05-StrictElementRef';
6
- export * from './06-ElementRef';
7
- export * from './07-Views';
8
- export * from './08-Structurizr';
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { createTestServices } from '../test';
3
- const document1 = `
4
- specification {
5
- element component
6
- }
7
- model {
8
- component system {
9
- sub = component {
10
- component sub1
11
- }
12
- }
13
- }
14
- `;
15
- const document2 = `
16
- model {
17
- extend system.sub {
18
- component sub2 {
19
- -> sub1
20
- }
21
- }
22
- }
23
- `;
24
- const document3 = `
25
- model {
26
- system.sub1 -> system.sub2
27
- }
28
- `;
29
- test('parser smoke: ExtendsElement Scope', async () => {
30
- const { parse, validateAll } = createTestServices();
31
- await parse(document1);
32
- await parse(document2);
33
- await parse(document3);
34
- const { errors } = await validateAll();
35
- expect(errors).toEqual([]);
36
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import { toPairs } from 'rambdax';
2
- import { describe, vi, it } from 'vitest';
3
- import { createTestServices } from '../test';
4
- import * as testfiles from './parser-smoke';
5
- vi.mock('../logger', () => ({
6
- logger: {
7
- log: vi.fn(),
8
- error: vi.fn(),
9
- warn: vi.fn(),
10
- info: vi.fn(),
11
- debug: vi.fn()
12
- }
13
- }));
14
- describe('parser smoke', () => {
15
- toPairs(testfiles).forEach(([name, document]) => {
16
- it.concurrent(name, async ({ expect }) => {
17
- const { validate } = createTestServices();
18
- const { diagnostics } = await validate(document);
19
- const errors = diagnostics.map(d => d.message);
20
- if (name.startsWith('invalid_')) {
21
- expect(errors).not.toEqual([]);
22
- }
23
- else {
24
- expect(errors).toEqual([]);
25
- }
26
- });
27
- });
28
- });
package/dist/ast.d.ts DELETED
@@ -1,73 +0,0 @@
1
- /// <reference types="react" />
2
- import * as ast from './generated/ast';
3
- import type { LangiumDocument } from 'langium';
4
- import type { LikeC4Document } from './generated/ast';
5
- import type * as c4 from '@likec4/core/types';
6
- export { ast };
7
- export declare function c4hash({ c4Specification, c4Elements, c4Relations, c4Views }: LikeC4LangiumDocument): string;
8
- export interface ParsedAstSpecification {
9
- kinds: Record<c4.ElementKind, {
10
- shape: c4.ElementShape;
11
- color: c4.ThemeColor;
12
- }>;
13
- }
14
- export interface ParsedAstElement {
15
- id: c4.Fqn;
16
- astPath: string;
17
- kind: c4.ElementKind;
18
- title: string;
19
- description?: string;
20
- technology?: string;
21
- tags?: c4.Tag[];
22
- shape?: c4.ElementShape;
23
- color?: c4.ThemeColor;
24
- }
25
- export interface ParsedAstRelation {
26
- id: c4.RelationID;
27
- astPath: string;
28
- source: c4.Fqn;
29
- target: c4.Fqn;
30
- title: string;
31
- }
32
- export interface ParsedAstElementView {
33
- id: c4.ViewID;
34
- astPath: string;
35
- viewOf?: c4.Fqn;
36
- title?: string;
37
- description?: string;
38
- rules: c4.ViewRule[];
39
- }
40
- export declare const ElementViewOps: {
41
- writeId(node: ast.ElementView, id: c4.ViewID): ast.ElementView;
42
- readId(node: ast.ElementView): c4.ViewID | undefined;
43
- };
44
- export declare const ElementOps: {
45
- writeId(node: ast.Element, id: c4.Fqn): ast.Element;
46
- readId(node: ast.Element): c4.Fqn | undefined;
47
- };
48
- export interface LikeC4LangiumDocument extends LangiumDocument<LikeC4Document> {
49
- c4hash?: string;
50
- c4Specification: ParsedAstSpecification;
51
- c4Elements: ParsedAstElement[];
52
- c4Relations: ParsedAstRelation[];
53
- c4Views: ParsedAstElementView[];
54
- }
55
- export declare function cleanParsedModel(doc: LikeC4LangiumDocument): {
56
- elements: ParsedAstElement[];
57
- relations: ParsedAstRelation[];
58
- views: ParsedAstElementView[];
59
- specification: ParsedAstSpecification;
60
- };
61
- export declare function isLikeC4LangiumDocument(doc: LangiumDocument): doc is LikeC4LangiumDocument;
62
- export declare function isParsedLikeC4LangiumDocument(doc: LangiumDocument): doc is LikeC4LangiumDocument;
63
- export declare const isValidDocument: (doc: LangiumDocument) => doc is LikeC4LangiumDocument;
64
- export declare function streamModel(doc: LikeC4LangiumDocument): Generator<ast.Element | ast.Relation, void, unknown>;
65
- export declare function resolveRelationPoints(node: ast.Relation): {
66
- source: ast.Element;
67
- target: ast.Element;
68
- };
69
- export declare function toElementStyle(props?: ast.AStyleProperty[]): {
70
- color?: c4.ThemeColor;
71
- shape?: c4.ElementShape;
72
- };
73
- export declare function toAutoLayout(direction: ast.ViewRuleLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
package/dist/ast.js DELETED
@@ -1,133 +0,0 @@
1
- import * as ast from './generated/ast';
2
- import { DocumentState } from 'langium';
3
- import objectHash from 'object-hash';
4
- import { elementRef } from './elementRef';
5
- import { LikeC4LanguageMetaData } from './generated/module';
6
- export { ast };
7
- export function c4hash({ c4Specification, c4Elements, c4Relations, c4Views }) {
8
- return objectHash({
9
- c4Specification,
10
- c4Elements,
11
- c4Relations,
12
- c4Views
13
- }, {
14
- respectType: false
15
- });
16
- }
17
- const idattr = Symbol.for('idattr');
18
- export const ElementViewOps = {
19
- writeId(node, id) {
20
- Object.assign(node, { [idattr]: id });
21
- return node;
22
- },
23
- readId(node) {
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- return node[idattr];
26
- }
27
- };
28
- export const ElementOps = {
29
- writeId(node, id) {
30
- Object.assign(node, { [idattr]: id });
31
- return node;
32
- },
33
- readId(node) {
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- return node[idattr];
36
- }
37
- };
38
- export function cleanParsedModel(doc) {
39
- doc.c4Specification = {
40
- kinds: {}
41
- };
42
- const elements = (doc.c4Elements = []);
43
- const relations = (doc.c4Relations = []);
44
- const views = (doc.c4Views = []);
45
- return {
46
- elements,
47
- relations,
48
- views,
49
- specification: doc.c4Specification
50
- };
51
- }
52
- export function isLikeC4LangiumDocument(doc) {
53
- return doc.textDocument.languageId === LikeC4LanguageMetaData.languageId;
54
- }
55
- export function isParsedLikeC4LangiumDocument(doc) {
56
- return (isLikeC4LangiumDocument(doc) &&
57
- ['c4Specification', 'c4Elements', 'c4Relations', 'c4Views'].every(key => key in doc));
58
- }
59
- export const isValidDocument = (doc) => {
60
- if (!isLikeC4LangiumDocument(doc))
61
- return false;
62
- const { state, parseResult, diagnostics } = doc;
63
- return (state === DocumentState.Validated &&
64
- parseResult.lexerErrors.length === 0 &&
65
- (!diagnostics || diagnostics.every(d => d.severity !== 1)));
66
- };
67
- export function* streamModel(doc) {
68
- const elements = doc.parseResult.value.model?.elements ?? [];
69
- const traverseStack = [...elements];
70
- let el;
71
- while ((el = traverseStack.shift())) {
72
- if (ast.isExtendElement(el)) {
73
- traverseStack.push(...el.body.elements);
74
- continue;
75
- }
76
- if (ast.isElement(el) && el.body) {
77
- traverseStack.push(...el.body.elements);
78
- }
79
- yield el;
80
- }
81
- }
82
- export function resolveRelationPoints(node) {
83
- const target = elementRef(node.target);
84
- if (!target) {
85
- throw new Error('Skip relation due to invalid reference to target');
86
- }
87
- if (ast.isRelationWithSource(node)) {
88
- const source = elementRef(node.source);
89
- if (!source) {
90
- throw new Error('Skip relation due to invalid reference to source');
91
- }
92
- return {
93
- source,
94
- target
95
- };
96
- }
97
- if (!ast.isElementBody(node.$container)) {
98
- throw new Error('Skip relation due to invalid reference to source');
99
- }
100
- const source = node.$container.$container;
101
- return {
102
- source,
103
- target
104
- };
105
- }
106
- export function toElementStyle(props) {
107
- const result = {};
108
- const color = props?.find(ast.isColorProperty)?.value;
109
- if (color) {
110
- result.color = color;
111
- }
112
- const shape = props?.find(ast.isShapeProperty)?.value;
113
- if (shape) {
114
- result.shape = shape;
115
- }
116
- return result;
117
- }
118
- export function toAutoLayout(direction) {
119
- switch (direction) {
120
- case 'TopBottom': {
121
- return 'TB';
122
- }
123
- case 'BottomTop': {
124
- return 'BT';
125
- }
126
- case 'LeftRight': {
127
- return 'LR';
128
- }
129
- case 'RightLeft': {
130
- return 'RL';
131
- }
132
- }
133
- }
package/dist/builtin.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare const specification: {
2
- uri: string;
3
- document: string;
4
- };
package/dist/builtin.js DELETED
@@ -1,8 +0,0 @@
1
- export const specification = {
2
- uri: 'builtin:///specification.likec4',
3
- document: `
4
- specification {
5
- element element
6
- }
7
- `.trimStart()
8
- };
@@ -1,6 +0,0 @@
1
- import type * as c4 from '@likec4/core/types';
2
- import { ast } from './ast';
3
- export declare function isElementRefHead(node: ast.ElementRef | ast.StrictElementRef): boolean;
4
- export declare function elementRef(node: ast.ElementRef): ast.Element | undefined;
5
- export declare function strictElementRefFqn(node: ast.StrictElementRef): c4.Fqn;
6
- export declare function parentStrictElementRef(node: ast.StrictElementRef): c4.Fqn;
@@ -1,39 +0,0 @@
1
- import { ast } from './ast';
2
- import invariant from 'tiny-invariant';
3
- import { failExpectedNever } from './utils';
4
- export function isElementRefHead(node) {
5
- if (ast.isElementRef(node)) {
6
- return !ast.isElementRef(node.$container);
7
- }
8
- if (ast.isStrictElementRef(node)) {
9
- return !ast.isStrictElementRef(node.$container);
10
- }
11
- failExpectedNever(node);
12
- }
13
- export function elementRef(node) {
14
- invariant(isElementRefHead(node), 'Expected head ElementRef');
15
- while (node.next) {
16
- node = node.next;
17
- }
18
- return node.el.ref;
19
- }
20
- export function strictElementRefFqn(node) {
21
- invariant(isElementRefHead(node), 'Expected head StrictElementRef');
22
- const name = [node.el.$refText];
23
- let child = node.next;
24
- while (child) {
25
- name.push(child.el.$refText);
26
- child = child.next;
27
- }
28
- return name.join('.');
29
- }
30
- export function parentStrictElementRef(node) {
31
- invariant(!isElementRefHead(node), 'Expected next StrictElementRef');
32
- const path = [];
33
- let parent = node.$container;
34
- while (ast.isStrictElementRef(parent)) {
35
- path.unshift(parent.el.$refText);
36
- parent = parent.$container;
37
- }
38
- return path.join('.');
39
- }