@likec4/language-server 1.21.1 → 1.22.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 (113) hide show
  1. package/README.md +4 -1
  2. package/bin/likec4-language-server.mjs +5 -2
  3. package/dist/LikeC4FileSystem.js +2 -2
  4. package/dist/browser.d.ts +3 -3
  5. package/dist/browser.js +17 -2
  6. package/dist/bundled.d.ts +8 -0
  7. package/dist/bundled.js +25 -0
  8. package/dist/bundled.mjs +2555 -4022
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +23 -2
  11. package/dist/logger.d.ts +9 -3
  12. package/dist/logger.js +35 -55
  13. package/dist/model/fqn-computation.js +2 -2
  14. package/dist/model/model-builder.js +13 -14
  15. package/dist/model-change/ModelChanges.js +2 -2
  16. package/dist/module.js +1 -4
  17. package/dist/references/scope-provider.js +3 -3
  18. package/dist/view-utils/manual-layout.js +2 -2
  19. package/dist/views/configurable-layouter.js +4 -4
  20. package/dist/views/likec4-views.d.ts +2 -1
  21. package/dist/views/likec4-views.js +2 -2
  22. package/package.json +14 -12
  23. package/dist/test/setup.d.ts +0 -1
  24. package/dist/test/setup.js +0 -7
  25. package/src/LikeC4FileSystem.ts +0 -38
  26. package/src/Rpc.ts +0 -134
  27. package/src/ast.ts +0 -556
  28. package/src/browser.ts +0 -35
  29. package/src/documentation/documentation-provider.ts +0 -52
  30. package/src/documentation/index.ts +0 -1
  31. package/src/formatting/LikeC4Formatter.ts +0 -639
  32. package/src/formatting/utils.ts +0 -26
  33. package/src/generated/ast.ts +0 -3735
  34. package/src/generated/grammar.ts +0 -10
  35. package/src/generated/module.ts +0 -33
  36. package/src/generated-lib/icons.ts +0 -1538
  37. package/src/index.ts +0 -30
  38. package/src/like-c4.langium +0 -901
  39. package/src/likec4lib.ts +0 -6
  40. package/src/logger.ts +0 -80
  41. package/src/lsp/CodeLensProvider.ts +0 -50
  42. package/src/lsp/CompletionProvider.ts +0 -147
  43. package/src/lsp/DocumentHighlightProvider.ts +0 -12
  44. package/src/lsp/DocumentLinkProvider.ts +0 -65
  45. package/src/lsp/DocumentSymbolProvider.ts +0 -313
  46. package/src/lsp/HoverProvider.ts +0 -92
  47. package/src/lsp/RenameProvider.ts +0 -8
  48. package/src/lsp/SemanticTokenProvider.ts +0 -383
  49. package/src/lsp/index.ts +0 -8
  50. package/src/model/deployments-index.ts +0 -209
  51. package/src/model/fqn-computation.ts +0 -83
  52. package/src/model/fqn-index.ts +0 -138
  53. package/src/model/index.ts +0 -6
  54. package/src/model/model-builder.ts +0 -724
  55. package/src/model/model-locator.ts +0 -146
  56. package/src/model/model-parser-where.ts +0 -84
  57. package/src/model/model-parser.ts +0 -86
  58. package/src/model/parser/Base.ts +0 -113
  59. package/src/model/parser/DeploymentModelParser.ts +0 -192
  60. package/src/model/parser/DeploymentViewParser.ts +0 -122
  61. package/src/model/parser/FqnRefParser.ts +0 -143
  62. package/src/model/parser/GlobalsParser.ts +0 -96
  63. package/src/model/parser/ModelParser.ts +0 -170
  64. package/src/model/parser/PredicatesParser.ts +0 -315
  65. package/src/model/parser/SpecificationParser.ts +0 -133
  66. package/src/model/parser/ViewsParser.ts +0 -428
  67. package/src/model-change/ModelChanges.ts +0 -101
  68. package/src/model-change/changeElementStyle.ts +0 -172
  69. package/src/model-change/changeViewLayout.ts +0 -47
  70. package/src/model-change/saveManualLayout.ts +0 -41
  71. package/src/module.ts +0 -255
  72. package/src/protocol.ts +0 -93
  73. package/src/references/index.ts +0 -3
  74. package/src/references/name-provider.ts +0 -37
  75. package/src/references/scope-computation.ts +0 -364
  76. package/src/references/scope-provider.ts +0 -201
  77. package/src/shared/NodeKindProvider.ts +0 -121
  78. package/src/shared/WorkspaceManager.ts +0 -48
  79. package/src/shared/WorkspaceSymbolProvider.ts +0 -3
  80. package/src/shared/index.ts +0 -3
  81. package/src/test/index.ts +0 -1
  82. package/src/test/setup.ts +0 -8
  83. package/src/test/testServices.ts +0 -152
  84. package/src/utils/disposable.ts +0 -30
  85. package/src/utils/elementRef.ts +0 -26
  86. package/src/utils/fqnRef.ts +0 -56
  87. package/src/utils/index.ts +0 -2
  88. package/src/utils/printDocs.ts +0 -3
  89. package/src/utils/stringHash.ts +0 -6
  90. package/src/validation/_shared.ts +0 -29
  91. package/src/validation/deployment-checks.ts +0 -131
  92. package/src/validation/dynamic-view-rule.ts +0 -23
  93. package/src/validation/dynamic-view-step.ts +0 -36
  94. package/src/validation/element.ts +0 -56
  95. package/src/validation/index.ts +0 -171
  96. package/src/validation/property-checks.ts +0 -52
  97. package/src/validation/relation.ts +0 -63
  98. package/src/validation/specification.ts +0 -205
  99. package/src/validation/view-predicates/element-with.ts +0 -36
  100. package/src/validation/view-predicates/expanded-element.ts +0 -16
  101. package/src/validation/view-predicates/expression-v2.ts +0 -101
  102. package/src/validation/view-predicates/incoming.ts +0 -20
  103. package/src/validation/view-predicates/index.ts +0 -6
  104. package/src/validation/view-predicates/outgoing.ts +0 -20
  105. package/src/validation/view-predicates/relation-with.ts +0 -17
  106. package/src/validation/view.ts +0 -37
  107. package/src/view-utils/assignNavigateTo.ts +0 -31
  108. package/src/view-utils/index.ts +0 -2
  109. package/src/view-utils/manual-layout.ts +0 -116
  110. package/src/view-utils/resolve-relative-paths.ts +0 -90
  111. package/src/views/configurable-layouter.ts +0 -65
  112. package/src/views/index.ts +0 -1
  113. package/src/views/likec4-views.ts +0 -139
@@ -1,83 +0,0 @@
1
- import type * as c4 from '@likec4/core'
2
- import { AsFqn, LinkedList, nonexhaustive } from '@likec4/core'
3
- import { type AstNodeDescription, type AstNodeLocator, AstUtils, CstUtils, GrammarUtils, MultiMap } from 'langium'
4
- import { isDefined, isEmpty } from 'remeda'
5
- import { type LikeC4LangiumDocument, ast, ElementOps } from '../ast'
6
- import { logError } from '../logger'
7
- import type { LikeC4Services } from '../module'
8
- import { getFqnElementRef } from '../utils/elementRef'
9
-
10
- const { findNodeForProperty } = GrammarUtils
11
- const { toDocumentSegment } = CstUtils
12
- const { getDocument } = AstUtils
13
-
14
- type TraversePair = [el: ast.Element | ast.ExtendElement | ast.Relation, parent: c4.Fqn | null]
15
-
16
- function toAstNodeDescription(
17
- locator: AstNodeLocator,
18
- entry: ast.Element,
19
- doc: LikeC4LangiumDocument,
20
- ): AstNodeDescription {
21
- const $cstNode = findNodeForProperty(entry.$cstNode, 'name')
22
- return {
23
- documentUri: doc.uri,
24
- name: entry.name,
25
- ...(entry.$cstNode && {
26
- selectionSegment: toDocumentSegment(entry.$cstNode),
27
- }),
28
- ...($cstNode && {
29
- nameSegment: toDocumentSegment($cstNode),
30
- }),
31
- path: locator.getAstNodePath(entry),
32
- type: ast.Element,
33
- }
34
- }
35
-
36
- export function computeDocumentFqn(document: LikeC4LangiumDocument, services: LikeC4Services) {
37
- const c4fqnIndex = (document.c4fqnIndex = new MultiMap())
38
- const elements = document.parseResult.value.models.flatMap(m => m.elements)
39
- if (elements.length === 0) {
40
- return
41
- }
42
- const locator = services.workspace.AstNodeLocator
43
- const traverseStack = LinkedList.from(elements.map(el => [el, null] as TraversePair))
44
- let pair
45
- while ((pair = traverseStack.shift())) {
46
- try {
47
- const [el, parent] = pair
48
- if (ast.isRelation(el)) {
49
- continue
50
- }
51
- if (ast.isExtendElement(el)) {
52
- if (isDefined(el.body) && !isEmpty(el.body.elements)) {
53
- const fqn = getFqnElementRef(el.element)
54
- for (const child of el.body.elements) {
55
- if (!ast.isRelation(child)) {
56
- traverseStack.push([child, fqn])
57
- }
58
- }
59
- }
60
- continue
61
- }
62
- if (ast.isElement(el)) {
63
- const fqn = AsFqn(el.name, parent)
64
- c4fqnIndex.add(fqn, {
65
- ...toAstNodeDescription(locator, el, document),
66
- fqn,
67
- })
68
- ElementOps.writeId(el, fqn)
69
- if (isDefined(el.body) && !isEmpty(el.body.elements)) {
70
- for (const child of el.body.elements) {
71
- if (!ast.isRelation(child)) {
72
- traverseStack.push([child, fqn])
73
- }
74
- }
75
- }
76
- continue
77
- }
78
- nonexhaustive(el)
79
- } catch (e) {
80
- logError(e)
81
- }
82
- }
83
- }
@@ -1,138 +0,0 @@
1
- import type { Fqn } from '@likec4/core'
2
- import { nameFromFqn, parentFqn } from '@likec4/core'
3
- import type { AstNodeDescription, LangiumDocuments, Stream } from 'langium'
4
- import { DocumentState, DONE_RESULT, MultiMap, stream, StreamImpl } from 'langium'
5
- import type { ast, DocFqnIndexAstNodeDescription, FqnIndexedDocument } from '../ast'
6
- import { ElementOps, isFqnIndexedDocument, isLikeC4LangiumDocument } from '../ast'
7
- import { logger, logWarnError } from '../logger'
8
- import type { LikeC4Services } from '../module'
9
- import { ADisposable } from '../utils'
10
- import { computeDocumentFqn } from './fqn-computation'
11
-
12
- export interface FqnIndexEntry {
13
- fqn: Fqn
14
- name: string
15
- el: ast.Element
16
- doc: FqnIndexedDocument
17
- path: string
18
- }
19
-
20
- export class FqnIndex extends ADisposable {
21
- protected langiumDocuments: LangiumDocuments
22
-
23
- constructor(private services: LikeC4Services) {
24
- super()
25
- this.langiumDocuments = services.shared.workspace.LangiumDocuments
26
-
27
- this.onDispose(
28
- services.shared.workspace.DocumentBuilder.onBuildPhase(
29
- DocumentState.IndexedContent,
30
- async (docs, _cancelToken) => {
31
- for (const doc of docs) {
32
- if (isLikeC4LangiumDocument(doc)) {
33
- delete doc.c4fqnIndex
34
- delete doc.c4Elements
35
- delete doc.c4Specification
36
- delete doc.c4Relations
37
- delete doc.c4Deployments
38
- delete doc.c4DeploymentRelations
39
- delete doc.c4Globals
40
- delete doc.c4Views
41
- try {
42
- computeDocumentFqn(doc, services)
43
- } catch (e) {
44
- logWarnError(e)
45
- }
46
- }
47
- }
48
- return await Promise.resolve()
49
- },
50
- ),
51
- )
52
- logger.debug(`[FqnIndex] Created`)
53
- }
54
-
55
- get documents() {
56
- return this.langiumDocuments.all.filter(isFqnIndexedDocument)
57
- }
58
-
59
- private entries(filterByFqn: (fqn: Fqn) => boolean): Stream<DocFqnIndexAstNodeDescription> {
60
- return this.documents.flatMap(doc => {
61
- return doc.c4fqnIndex.keys().filter(filterByFqn).flatMap(fqn => doc.c4fqnIndex.get(fqn))
62
- })
63
- }
64
-
65
- public getFqn(el: ast.Element): Fqn | null {
66
- return ElementOps.readId(el) ?? null
67
- }
68
-
69
- public byFqn(fqn: Fqn): Stream<AstNodeDescription> {
70
- return this.documents.flatMap(doc => {
71
- return doc.c4fqnIndex.get(fqn)
72
- })
73
- }
74
-
75
- public directChildrenOf(parent: Fqn): Stream<AstNodeDescription> {
76
- return stream([parent]).flatMap(_parent => {
77
- const children = this.entries(fqn => parentFqn(fqn) === _parent)
78
- .map((entry) => [entry.name, entry] as [string, AstNodeDescription])
79
- .toArray()
80
- if (children.length === 0) {
81
- return []
82
- }
83
- return new MultiMap(children)
84
- .entriesGroupedByKey()
85
- .flatMap(([_name, descrs]) => (descrs.length === 1 ? descrs : []))
86
- .iterator()
87
- })
88
- }
89
-
90
- /**
91
- * Returns descedant elements with unique names in the scope
92
- */
93
- public uniqueDescedants(parent: Fqn): Stream<AstNodeDescription> {
94
- return new StreamImpl(
95
- () => {
96
- const prefix = `${parent}.`
97
-
98
- const childrenNames = new Set<string>()
99
- const descedants = [] as AstNodeDescription[]
100
-
101
- const nested = new MultiMap<string, AstNodeDescription>()
102
-
103
- this.entries(f => f.startsWith(prefix)).forEach(e => {
104
- const name = nameFromFqn(e.fqn)
105
- const entry = { ...e, name }
106
- // To keep direct children always
107
- if (parentFqn(e.fqn) === parent) {
108
- childrenNames.add(name)
109
- nested.add(name, entry)
110
- } else {
111
- descedants.push(entry)
112
- }
113
- })
114
-
115
- if (nested.size + descedants.length === 0) {
116
- return null
117
- }
118
-
119
- for (const descedant of descedants) {
120
- if (!childrenNames.has(descedant.name)) {
121
- nested.add(descedant.name, descedant)
122
- }
123
- }
124
-
125
- return nested
126
- .entriesGroupedByKey()
127
- .flatMap(([_name, descrs]) => (descrs.length === 1 ? descrs : []))
128
- .iterator()
129
- },
130
- iterator => {
131
- if (iterator) {
132
- return iterator.next()
133
- }
134
- return DONE_RESULT as IteratorResult<AstNodeDescription>
135
- },
136
- )
137
- }
138
- }
@@ -1,6 +0,0 @@
1
- export * from './deployments-index'
2
- export * from './fqn-computation'
3
- export * from './fqn-index'
4
- export * from './model-builder'
5
- export * from './model-locator'
6
- export * from './model-parser'