@likec4/language-server 0.42.2 → 0.43.1

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/dist/Rpc.js CHANGED
@@ -85,6 +85,7 @@ export class Rpc {
85
85
  `[ServerRpc] received request to buildDocuments:
86
86
  ${docs.map((d) => " - " + d).join("\n")}`
87
87
  );
88
+ const deleted = LangiumDocuments.all.filter((d) => !docs.includes(d.uri.toString())).map((d) => d.uri).toArray();
88
89
  const changed = [];
89
90
  for (const d of docs) {
90
91
  try {
@@ -112,7 +113,7 @@ We rebuild: [
112
113
  `.trim()
113
114
  );
114
115
  }
115
- await DocumentBuilder.update(changed, [], cancelToken);
116
+ await DocumentBuilder.update(changed, deleted, cancelToken);
116
117
  });
117
118
  connection.onRequest(locate, (params) => {
118
119
  if ("element" in params) {
@@ -12,12 +12,20 @@ export class FqnIndex {
12
12
  langiumDocuments;
13
13
  constructor(services) {
14
14
  this.langiumDocuments = services.shared.workspace.LangiumDocuments;
15
- services.shared.workspace.DocumentBuilder.onBuildPhase(
16
- DocumentState.Changed,
17
- (docs, _cancelToken) => {
18
- logger.debug(`[FqnIndex] onChanged (${docs.length} docs):
19
- ` + printDocs(docs));
20
- for (const doc of docs) {
15
+ services.shared.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
16
+ const message = [`[FqnIndex] onUpdate`];
17
+ if (changed.length > 0) {
18
+ message.push(` changed:`);
19
+ changed.forEach((u) => message.push(` - ${u}`));
20
+ }
21
+ if (deleted.length > 0) {
22
+ message.push(` deleted:`);
23
+ deleted.forEach((u) => message.push(` - ${u}`));
24
+ }
25
+ logger.debug(message.join("\n"));
26
+ for (const uri of changed) {
27
+ if (this.langiumDocuments.hasDocument(uri)) {
28
+ const doc = this.langiumDocuments.getOrCreateDocument(uri);
21
29
  if (isLikeC4LangiumDocument(doc)) {
22
30
  delete doc.c4fqns;
23
31
  delete doc.c4Elements;
@@ -27,7 +35,7 @@ export class FqnIndex {
27
35
  }
28
36
  }
29
37
  }
30
- );
38
+ });
31
39
  services.shared.workspace.DocumentBuilder.onBuildPhase(
32
40
  DocumentState.IndexedContent,
33
41
  (docs, _cancelToken) => {
@@ -6,10 +6,8 @@ type ModelParsedListener = (docs: URI[]) => void;
6
6
  export declare class LikeC4ModelBuilder {
7
7
  private services;
8
8
  private langiumDocuments;
9
- private workspaceManager;
10
9
  private listeners;
11
10
  constructor(services: LikeC4Services);
12
- get workspaceUri(): string | null;
13
11
  buildRawModel(): c4.LikeC4RawModel | null;
14
12
  buildModel(): c4.LikeC4Model | null;
15
13
  computeView(viewId: ViewID): c4.ComputedView | null;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  compareByFqnHierarchically,
3
- invariant,
4
3
  isStrictElementView,
5
4
  parentFqn
6
5
  } from "@likec4/core";
6
+ import { LikeC4ModelGraph, computeView } from "@likec4/graph";
7
7
  import {
8
8
  DocumentState,
9
9
  interruptAndCheck
@@ -12,10 +12,8 @@ import * as R from "remeda";
12
12
  import { Disposable } from "vscode-languageserver";
13
13
  import { isValidLikeC4LangiumDocument } from "../ast.js";
14
14
  import { logError, logWarnError, logger } from "../logger.js";
15
- import { LikeC4WorkspaceManager } from "../shared/index.js";
16
- import { printDocs, queueMicrotask } from "../utils.js";
15
+ import { printDocs } from "../utils.js";
17
16
  import { assignNavigateTo, resolveRelativePaths, resolveRulesExtendedViews } from "../view-utils/index.js";
18
- import { LikeC4ModelGraph, computeView } from "@likec4/graph";
19
17
  function isRelativeLink(link) {
20
18
  return link.startsWith(".") || link.startsWith("/");
21
19
  }
@@ -162,24 +160,20 @@ export class LikeC4ModelBuilder {
162
160
  constructor(services) {
163
161
  this.services = services;
164
162
  this.langiumDocuments = services.shared.workspace.LangiumDocuments;
165
- invariant(services.shared.workspace.WorkspaceManager instanceof LikeC4WorkspaceManager);
166
- this.workspaceManager = services.shared.workspace.WorkspaceManager;
167
163
  const parser = services.likec4.ModelParser;
168
164
  services.shared.workspace.DocumentBuilder.onBuildPhase(
169
165
  DocumentState.Validated,
170
166
  async (docs, cancelToken) => {
171
- await queueMicrotask(() => parser.parse(docs));
167
+ const parsed = parser.parse(docs).map((d) => d.uri);
172
168
  await interruptAndCheck(cancelToken);
173
- this.notifyListeners(docs.map((d) => d.uri));
169
+ if (parsed.length > 0) {
170
+ this.notifyListeners(parsed);
171
+ }
174
172
  }
175
173
  );
176
174
  }
177
175
  langiumDocuments;
178
- workspaceManager;
179
176
  listeners = [];
180
- get workspaceUri() {
181
- return this.workspaceManager.workspace()?.uri ?? null;
182
- }
183
177
  buildRawModel() {
184
178
  const cache = this.services.WorkspaceCache;
185
179
  return cache.get(RAW_MODEL_CACHE, () => {
@@ -8,7 +8,7 @@ export declare class LikeC4ModelParser {
8
8
  private services;
9
9
  private fqnIndex;
10
10
  constructor(services: LikeC4Services);
11
- parse(doc: LangiumDocument | LangiumDocument[]): void;
11
+ parse(doc: LangiumDocument | LangiumDocument[]): LikeC4LangiumDocument[];
12
12
  protected parseLikeC4Document(doc: LikeC4LangiumDocument): void;
13
13
  private parseElement;
14
14
  private parseRelation;
@@ -27,16 +27,19 @@ export class LikeC4ModelParser {
27
27
  const docs = Array.isArray(doc) ? doc : [doc];
28
28
  logger.debug(`[ModelParser] onValidated (${docs.length} docs)
29
29
  ${printDocs(docs)}`);
30
+ const result = [];
30
31
  for (const doc2 of docs) {
31
32
  if (!isLikeC4LangiumDocument(doc2)) {
32
33
  continue;
33
34
  }
34
35
  try {
35
36
  this.parseLikeC4Document(doc2);
37
+ result.push(doc2);
36
38
  } catch (cause) {
37
39
  logError(new InvalidModelError(`Error parsing document ${doc2.uri.toString()}`, { cause }));
38
40
  }
39
41
  }
42
+ return result;
40
43
  }
41
44
  parseLikeC4Document(doc) {
42
45
  const { elements, relations, views, specification } = cleanParsedModel(doc);
package/dist/module.js CHANGED
@@ -13,7 +13,6 @@ import {
13
13
  import { FqnIndex, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from "./model/index.js";
14
14
  import { LikeC4ScopeComputation, LikeC4ScopeProvider } from "./references/index.js";
15
15
  import { Rpc } from "./Rpc.js";
16
- import { LikeC4WorkspaceManager } from "./shared/index.js";
17
16
  import { registerValidationChecks } from "./validation/index.js";
18
17
  import { logger } from "./logger.js";
19
18
  import { serializeError } from "@likec4/core";
@@ -42,9 +41,9 @@ export const LikeC4Module = {
42
41
  }
43
42
  };
44
43
  const LikeC4SharedModule = {
45
- workspace: {
46
- WorkspaceManager: (services) => new LikeC4WorkspaceManager(services)
47
- }
44
+ // workspace: {
45
+ // WorkspaceManager: services => new LikeC4WorkspaceManager(services)
46
+ // }
48
47
  };
49
48
  export function createLanguageServices(context) {
50
49
  const connection = context?.connection;
@@ -1,9 +1,9 @@
1
- import * as vscodeUri from "vscode-uri";
2
1
  import { logger } from "../logger.js";
3
2
  import { elementChecks } from "./element.js";
4
3
  import { relationChecks } from "./relation.js";
5
- import { elementKindChecks, tagChecks, relationshipChecks } from "./specification.js";
4
+ import { elementKindChecks, relationshipChecks, tagChecks } from "./specification.js";
6
5
  import { viewChecks } from "./view.js";
6
+ import { incomingExpressionChecks, outgoingExpressionChecks } from "./view-predicates/index.js";
7
7
  export function registerValidationChecks(services) {
8
8
  logger.info("registerValidationChecks");
9
9
  const registry = services.validation.ValidationRegistry;
@@ -13,22 +13,13 @@ export function registerValidationChecks(services) {
13
13
  ElementKind: elementKindChecks(services),
14
14
  Relation: relationChecks(services),
15
15
  Tag: tagChecks(services),
16
- RelationshipKind: relationshipChecks(services)
16
+ RelationshipKind: relationshipChecks(services),
17
+ IncomingExpression: incomingExpressionChecks(services),
18
+ OutgoingExpression: outgoingExpressionChecks(services)
17
19
  });
18
20
  const connection = services.shared.lsp.Connection;
19
21
  if (connection) {
20
- logger.info("registerValidationChecks");
21
22
  services.shared.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
22
- const message = [`[DocumentBuilder.onUpdate]`];
23
- if (changed.length > 0) {
24
- message.push(` changed:`);
25
- changed.forEach((u) => message.push(` - ${vscodeUri.Utils.basename(u)}`));
26
- }
27
- if (deleted.length > 0) {
28
- message.push(` deleted:`);
29
- deleted.forEach((u) => message.push(` - ${vscodeUri.Utils.basename(u)}`));
30
- }
31
- logger.debug(message.join("\n"));
32
23
  for (const uri of deleted) {
33
24
  void connection.sendDiagnostics({
34
25
  uri: uri.toString(),
@@ -0,0 +1,5 @@
1
+ import type { ValidationCheck } from 'langium';
2
+ import { ast } from '../../ast';
3
+ import type { LikeC4Services } from '../../module';
4
+ export declare const incomingExpressionChecks: (_services: LikeC4Services) => ValidationCheck<ast.IncomingExpression>;
5
+ //# sourceMappingURL=incoming.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { ast } from "../../ast.js";
2
+ import { isNil } from "remeda";
3
+ export const incomingExpressionChecks = (_services) => {
4
+ return (el, accept) => {
5
+ if (ast.isWildcardExpression(el.target) && ast.isViewRuleExpression(el.$container)) {
6
+ const view = el.$container.$container.$container;
7
+ if (isNil(view.viewOf)) {
8
+ accept("warning", "Predicate is ignored as it concerns all relationships", {
9
+ node: el
10
+ });
11
+ }
12
+ }
13
+ };
14
+ };
@@ -0,0 +1,3 @@
1
+ export * from './incoming';
2
+ export * from './outgoing';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "./incoming.js";
2
+ export * from "./outgoing.js";
@@ -0,0 +1,5 @@
1
+ import type { ValidationCheck } from 'langium';
2
+ import { ast } from '../../ast';
3
+ import type { LikeC4Services } from '../../module';
4
+ export declare const outgoingExpressionChecks: (_services: LikeC4Services) => ValidationCheck<ast.OutgoingExpression>;
5
+ //# sourceMappingURL=outgoing.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { ast } from "../../ast.js";
2
+ import { isNil } from "remeda";
3
+ export const outgoingExpressionChecks = (_services) => {
4
+ return (el, accept) => {
5
+ if (ast.isWildcardExpression(el.source) && ast.isViewRuleExpression(el.$container)) {
6
+ const view = el.$container.$container.$container;
7
+ if (isNil(view.viewOf)) {
8
+ accept("warning", "Predicate is ignored as it concerns all relationships", {
9
+ node: el
10
+ });
11
+ }
12
+ }
13
+ };
14
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likec4/language-server",
3
3
  "description": "LikeC4 Language Server",
4
- "version": "0.42.2",
4
+ "version": "0.43.1",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -50,14 +50,14 @@
50
50
  "test": "vitest run"
51
51
  },
52
52
  "dependencies": {
53
- "@likec4/core": "0.42.2",
54
- "@likec4/graph": "0.42.2",
53
+ "@likec4/core": "0.43.1",
54
+ "@likec4/graph": "0.43.1",
55
55
  "langium": "^2.0.2",
56
56
  "object-hash": "^3.0.0",
57
57
  "p-debounce": "^4.0.0",
58
58
  "p-throttle": "^5.1.0",
59
59
  "rambdax": "^9.1.1",
60
- "remeda": "^1.27.1",
60
+ "remeda": "^1.28.0",
61
61
  "strip-indent": "^4.0.0",
62
62
  "vscode-languageserver": "~8.1.0",
63
63
  "vscode-languageserver-protocol": "~3.17.3",