@likec4/language-server 1.0.0-rc.1 → 1.0.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
@@ -23,18 +23,21 @@ export class Rpc {
23
23
  const modelEditor = this.services.likec4.ModelChanges;
24
24
  const connection = this.services.shared.lsp.Connection;
25
25
  if (!connection) {
26
- logger.info(`[ServerRpc] no connection, not initializing`);
26
+ logger.warn(`[ServerRpc] no connection, not initializing`);
27
27
  return;
28
28
  }
29
29
  logger.info(`[ServerRpc] init`);
30
30
  const LangiumDocuments = this.services.shared.workspace.LangiumDocuments;
31
31
  const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
32
32
  const notifyModelParsed = debounce(
33
- () => void connection.sendNotification(onDidChangeModel, "").catch(logError),
33
+ () => void connection.sendNotification(onDidChangeModel, "").catch((e) => {
34
+ logger.error(`[ServerRpc] error sending onDidChangeModel: ${e}`);
35
+ return Promise.resolve();
36
+ }),
34
37
  {
35
38
  timing: "both",
36
- waitMs: 100,
37
- maxWaitMs: 500
39
+ waitMs: 350,
40
+ maxWaitMs: 1e3
38
41
  }
39
42
  );
40
43
  this.disposables.push(
package/dist/ast.d.ts CHANGED
@@ -9,10 +9,10 @@ export { ast };
9
9
  declare const idattr: unique symbol;
10
10
  declare module './generated/ast' {
11
11
  interface Element {
12
- [idattr]?: c4.Fqn;
12
+ [idattr]?: c4.Fqn | undefined;
13
13
  }
14
14
  interface ElementView {
15
- [idattr]?: c4.ViewID;
15
+ [idattr]?: c4.ViewID | undefined;
16
16
  }
17
17
  }
18
18
  export interface ParsedAstSpecification {
@@ -101,13 +101,12 @@ export declare function isLikeC4LangiumDocument(doc: LangiumDocument): doc is Li
101
101
  export declare function isParsedLikeC4LangiumDocument(doc: LangiumDocument): doc is ParsedLikeC4LangiumDocument;
102
102
  type Guard<N extends AstNode> = (n: AstNode) => n is N;
103
103
  type Guarded<G> = G extends Guard<infer N> ? N : never;
104
- declare const isValidatableAstNode: (n: AstNode) => n is ast.Relation | ast.SpecificationRelationshipKind | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.SpecificationElementKind | ast.ElementView | ast.ModelViews | ast.SpecificationTag;
104
+ declare const isValidatableAstNode: (n: AstNode) => n is ast.DescedantsExpr | ast.ElementKindExpr | ast.ElementRef | ast.ElementTagExpr | ast.ExpandElementExpr | ast.WildcardExpr | ast.ElementStringProperty | ast.LinkProperty | ast.StyleProperties | ast.ExplicitRelation | ast.ImplicitRelation | ast.RelationStringProperty | ast.RelationStyleProperty | ast.ViewStringProperty | ast.ViewRuleAutoLayout | ast.ExcludePredicate | ast.IncludePredicate | ast.ViewRuleStyle | ast.CustomElementExpr | ast.InOutExpr | ast.IncomingExpr | ast.OutgoingExpr | ast.RelationExpr | ast.SpecificationRelationshipKind | ast.RelationBody | ast.ElementBody | ast.ExtendElementBody | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.SpecificationElementKind | ast.ElementViewBody | ast.ElementView | ast.ModelViews | ast.SpecificationTag;
105
105
  type ValidatableAstNode = Guarded<typeof isValidatableAstNode>;
106
106
  export declare function checksFromDiagnostics(doc: LikeC4LangiumDocument): {
107
107
  isValid: (n: ValidatableAstNode) => boolean;
108
- invalidNodes: WeakSet<ast.ExplicitRelation | ast.ImplicitRelation | ast.SpecificationRelationshipKind | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.SpecificationElementKind | ast.ElementView | ast.ModelViews | ast.SpecificationTag>;
108
+ invalidNodes: WeakSet<ast.DescedantsExpr | ast.ElementKindExpr | ast.ElementRef | ast.ElementTagExpr | ast.ExpandElementExpr | ast.WildcardExpr | ast.ElementStringProperty | ast.LinkProperty | ast.StyleProperties | ast.ExplicitRelation | ast.ImplicitRelation | ast.RelationStringProperty | ast.RelationStyleProperty | ast.ViewStringProperty | ast.ViewRuleAutoLayout | ast.ExcludePredicate | ast.IncludePredicate | ast.ViewRuleStyle | ast.CustomElementExpr | ast.InOutExpr | ast.IncomingExpr | ast.OutgoingExpr | ast.RelationExpr | ast.SpecificationRelationshipKind | ast.RelationBody | ast.ElementBody | ast.ExtendElementBody | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.SpecificationElementKind | ast.ElementViewBody | ast.ElementView | ast.ModelViews | ast.SpecificationTag>;
109
109
  };
110
- export declare const isValidLikeC4LangiumDocument: (doc: LangiumDocument) => doc is ParsedLikeC4LangiumDocument;
111
110
  export declare function streamModel(doc: LikeC4LangiumDocument): Generator<ast.Relation | ast.Element, void, unknown>;
112
111
  export declare function resolveRelationPoints(node: ast.Relation): {
113
112
  source: ast.Element;
package/dist/ast.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  RelationRefError
9
9
  } from "@likec4/core";
10
10
  import { AstUtils, DocumentState } from "langium";
11
- import { isNil } from "remeda";
11
+ import { isNullish } from "remeda";
12
12
  import { DiagnosticSeverity } from "vscode-languageserver-protocol";
13
13
  import { elementRef } from "./elementRef.js";
14
14
  import * as ast from "./generated/ast.js";
@@ -26,8 +26,8 @@ export const ElementViewOps = {
26
26
  };
27
27
  export const ElementOps = {
28
28
  writeId(node, id) {
29
- if (isNil(id)) {
30
- delete node[idattr];
29
+ if (isNullish(id)) {
30
+ node[idattr] = void 0;
31
31
  } else {
32
32
  node[idattr] = id;
33
33
  }
@@ -62,24 +62,33 @@ function validatableAstNodeGuards(predicates) {
62
62
  return (n) => predicates.some((p) => p(n));
63
63
  }
64
64
  const isValidatableAstNode = validatableAstNodeGuards([
65
- ast.isModel,
65
+ ast.isViewRuleStyle,
66
+ ast.isViewRulePredicateExpr,
67
+ ast.isViewRulePredicate,
68
+ ast.isViewRule,
69
+ ast.isViewProperty,
70
+ ast.isElementViewBody,
71
+ ast.isElementView,
72
+ ast.isRelationProperty,
73
+ ast.isRelationBody,
66
74
  ast.isRelation,
75
+ ast.isElementProperty,
76
+ ast.isElementBody,
67
77
  ast.isElement,
78
+ ast.isExtendElementBody,
68
79
  ast.isExtendElement,
69
- ast.isSpecificationRule,
70
80
  ast.isSpecificationElementKind,
71
81
  ast.isSpecificationRelationshipKind,
72
82
  ast.isSpecificationTag,
73
- ast.isElementView,
83
+ ast.isSpecificationRule,
84
+ ast.isModel,
74
85
  ast.isModelViews
75
86
  ]);
76
87
  export function checksFromDiagnostics(doc) {
88
+ const errors = doc.diagnostics?.filter((d) => d.severity === DiagnosticSeverity.Error) ?? [];
77
89
  const invalidNodes = new WeakSet(
78
- doc.diagnostics?.flatMap((d) => {
79
- if (d.severity === DiagnosticSeverity.Error) {
80
- return AstUtils.getContainerOfType(d.node, isValidatableAstNode) ?? [];
81
- }
82
- return [];
90
+ errors.flatMap((d) => {
91
+ return AstUtils.getContainerOfType(d.node, isValidatableAstNode) ?? [];
83
92
  }) ?? []
84
93
  );
85
94
  const isValid = (n) => !invalidNodes.has(n);
@@ -88,16 +97,9 @@ export function checksFromDiagnostics(doc) {
88
97
  invalidNodes
89
98
  };
90
99
  }
91
- export const isValidLikeC4LangiumDocument = (doc) => {
92
- if (!isParsedLikeC4LangiumDocument(doc))
93
- return false;
94
- const { parseResult, diagnostics } = doc;
95
- return parseResult.lexerErrors.length === 0 && parseResult.parserErrors.length === 0 && (!diagnostics || diagnostics.length === 0 || diagnostics.every((d) => d.severity !== DiagnosticSeverity.Error));
96
- };
97
100
  export function* streamModel(doc) {
98
101
  const { isValid } = checksFromDiagnostics(doc);
99
- const elements = doc.parseResult.value.models.flatMap((m) => isValid(m) ? m.elements : []);
100
- const traverseStack = [...elements];
102
+ const traverseStack = doc.parseResult.value.models.flatMap((m) => isValid(m) ? m.elements : []);
101
103
  const relations = [];
102
104
  let el;
103
105
  while (el = traverseStack.shift()) {
@@ -5,8 +5,11 @@ export function getFqnElementRef(node) {
5
5
  const name = [node.el.$refText];
6
6
  let parent = node.parent;
7
7
  while (parent) {
8
- name.unshift(parent.el.$refText);
8
+ name.push(parent.el.$refText);
9
9
  parent = parent.parent;
10
10
  }
11
- return name.join(".");
11
+ if (name.length === 1) {
12
+ return name[0];
13
+ }
14
+ return name.reverse().join(".");
12
15
  }
@@ -5,11 +5,19 @@ import { changeViewStyle } from "./changeViewStyle.js";
5
5
  function unionRangeOfAllEdits(edits) {
6
6
  let start = Number.MAX_SAFE_INTEGER;
7
7
  let end = Number.MIN_SAFE_INTEGER;
8
- for (const edit of edits) {
9
- start = Math.min(start, edit.range.start.line);
10
- end = Math.max(end, edit.range.end.line);
8
+ let startCharacter = 0;
9
+ let endCharacter = 0;
10
+ for (const { range } of edits) {
11
+ start = Math.min(start, range.start.line);
12
+ if (start === range.start.line) {
13
+ startCharacter = range.start.character;
14
+ }
15
+ end = Math.max(end, range.end.line);
16
+ if (end === range.end.line) {
17
+ endCharacter = range.end.character;
18
+ }
11
19
  }
12
- return Range.create(start, 0, end, 0);
20
+ return Range.create(start, startCharacter, end, endCharacter);
13
21
  }
14
22
  export class LikeC4ModelChanges {
15
23
  constructor(services) {
@@ -39,7 +47,7 @@ export class LikeC4ModelChanges {
39
47
  }
40
48
  });
41
49
  if (!applyResult.applied) {
42
- lspConnection.window.showErrorMessage(`Failed to apply changes${applyResult.failureReason}`);
50
+ lspConnection.window.showErrorMessage(`Failed to apply changes ${applyResult.failureReason}`);
43
51
  return;
44
52
  }
45
53
  result = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likec4/language-server",
3
3
  "description": "LikeC4 Language Server",
4
- "version": "1.0.0-rc.1",
4
+ "version": "1.0.1",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -74,8 +74,8 @@
74
74
  "test": "vitest run"
75
75
  },
76
76
  "dependencies": {
77
- "@likec4/core": "1.0.0-rc.1",
78
- "@likec4/graph": "1.0.0-rc.1",
77
+ "@likec4/core": "1.0.1",
78
+ "@likec4/graph": "1.0.1",
79
79
  "@total-typescript/ts-reset": "^0.5.1",
80
80
  "fast-equals": "^5.0.1",
81
81
  "langium": "^3.0.0",
@@ -85,7 +85,7 @@
85
85
  "remeda": "^1.61.0",
86
86
  "string-hash": "^1.1.3",
87
87
  "strip-indent": "^4.0.0",
88
- "type-fest": "^4.18.1",
88
+ "type-fest": "^4.18.2",
89
89
  "ufo": "^1.5.3",
90
90
  "vscode-languageserver": "9.0.1",
91
91
  "vscode-languageserver-protocol": "3.17.5",
@@ -96,11 +96,11 @@
96
96
  "@types/object-hash": "^3.0.6",
97
97
  "@types/string-hash": "^1",
98
98
  "execa": "^8.0.1",
99
- "langium-cli": "^3.0.3",
99
+ "langium-cli": "3.0.3",
100
100
  "npm-run-all2": "^6.1.2",
101
101
  "typescript": "^5.4.5",
102
102
  "unbuild": "^2.0.0",
103
103
  "vitest": "~1.5.2"
104
104
  },
105
- "packageManager": "yarn@4.1.1"
105
+ "packageManager": "yarn@4.2.2"
106
106
  }