@likec4/language-server 1.38.0 → 1.38.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.
@@ -12,7 +12,7 @@ export declare class MergedSpecification {
12
12
  readonly tags: Readonly<Record<c4.Tag, c4.TagSpecification>>;
13
13
  readonly globals: c4.ModelGlobals;
14
14
  readonly imports: MultiMap<c4.ProjectId, c4.Fqn, Set<c4.Fqn>>;
15
- constructor(docs: ParsedLikeC4LangiumDocument[]);
15
+ constructor(docs: ReadonlyArray<ParsedLikeC4LangiumDocument>);
16
16
  /**
17
17
  * Converts a parsed model into a C4 model element.
18
18
  */
@@ -18,4 +18,4 @@ export declare function buildModelData(project: {
18
18
  id: c4.ProjectId;
19
19
  folderUri: URI;
20
20
  config: Readonly<ProjectConfig>;
21
- }, docs: ParsedLikeC4LangiumDocument[]): BuildModelData;
21
+ }, docs: ReadonlyArray<ParsedLikeC4LangiumDocument>): BuildModelData;
@@ -1,10 +1,13 @@
1
1
  import type { NonEmptyArray, ProjectId } from '@likec4/core';
2
- import { type Stream, DefaultLangiumDocuments } from 'langium';
2
+ import type { LangiumDocument, Stream } from 'langium';
3
+ import { DefaultLangiumDocuments } from 'langium';
3
4
  import { type LikeC4LangiumDocument } from '../ast';
4
5
  import type { LikeC4SharedServices } from '../module';
5
6
  export declare class LangiumDocuments extends DefaultLangiumDocuments {
6
7
  protected services: LikeC4SharedServices;
8
+ protected compare: any;
7
9
  constructor(services: LikeC4SharedServices);
10
+ addDocument(document: LangiumDocument): void;
8
11
  /**
9
12
  * Returns all user documents, excluding built-in documents.
10
13
  */
@@ -1,12 +1,27 @@
1
+ import { compareNaturalHierarchically } from "@likec4/core/utils";
1
2
  import { DefaultLangiumDocuments } from "langium";
2
3
  import { groupBy, prop } from "remeda";
3
4
  import { isLikeC4LangiumDocument } from "../ast.js";
4
5
  import { isLikeC4Builtin } from "../likec4lib.js";
6
+ const compare = compareNaturalHierarchically("/", true);
7
+ const ensureOrder = (a, b) => compare(a.uri.path, b.uri.path);
5
8
  export class LangiumDocuments extends DefaultLangiumDocuments {
6
9
  constructor(services) {
7
10
  super(services);
8
11
  this.services = services;
9
12
  }
13
+ compare = compareNaturalHierarchically("/", true);
14
+ addDocument(document) {
15
+ const uriString = document.uri.toString();
16
+ if (this.documentMap.has(uriString)) {
17
+ throw new Error(`A document with the URI '${uriString}' is already present.`);
18
+ }
19
+ const docs = [...this.documentMap.values(), document].sort(ensureOrder);
20
+ this.documentMap.clear();
21
+ for (const doc of docs) {
22
+ this.documentMap.set(doc.uri.toString(), doc);
23
+ }
24
+ }
10
25
  /**
11
26
  * Returns all user documents, excluding built-in documents.
12
27
  */
@@ -5,7 +5,7 @@ import type { Tagged } from 'type-fest';
5
5
  import { ProjectConfig } from '../config';
6
6
  import type { LikeC4SharedServices } from '../module';
7
7
  /**
8
- * A tagged string that represents a project folder.
8
+ * A tagged string that represents a project folder URI
9
9
  * Always has trailing slash.
10
10
  */
11
11
  export type ProjectFolder = Tagged<string, 'ProjectFolder'>;
@@ -10,23 +10,26 @@ import PQueue from "p-queue";
10
10
  import picomatch from "picomatch";
11
11
  import { hasAtLeast, isNullish, isTruthy, map, pickBy, pipe, prop, sortBy } from "remeda";
12
12
  import {
13
- hasProtocol,
14
13
  joinRelativeURL,
15
- normalizeURL,
16
14
  parseFilename,
17
15
  withoutProtocol,
18
- withProtocol,
19
16
  withTrailingSlash
20
17
  } from "ufo";
21
18
  import { parseConfigJson, validateConfig } from "../config/index.js";
22
19
  import { logger as mainLogger } from "../logger.js";
23
20
  const logger = mainLogger.getChild("ProjectsManager");
24
- export function ProjectFolder(folder) {
25
- if (URI.isUri(folder)) {
26
- folder = folder.toString();
21
+ function normalizeUri(uri) {
22
+ if (URI.isUri(uri)) {
23
+ return uri.toString();
24
+ } else if (typeof uri === "string") {
25
+ return uri.startsWith("file://") ? uri : URI.file(uri).toString();
26
+ } else {
27
+ return uri.uri.toString();
27
28
  }
28
- folder = hasProtocol(folder) ? folder : withProtocol(folder, "file://");
29
- return withTrailingSlash(normalizeURL(folder));
29
+ }
30
+ export function ProjectFolder(folder) {
31
+ folder = normalizeUri(folder);
32
+ return withTrailingSlash(folder);
30
33
  }
31
34
  export class ProjectsManager {
32
35
  constructor(services) {
@@ -131,7 +134,7 @@ export class ProjectsManager {
131
134
  }
132
135
  checkIfExcluded(document) {
133
136
  if (typeof document === "string" || URI.isUri(document)) {
134
- let docUriAsString = typeof document === "string" ? document : document.toString();
137
+ let docUriAsString = normalizeUri(document);
135
138
  const project = this.findProjectForDocument(docUriAsString);
136
139
  return project.exclude ? project.exclude(withoutProtocol(docUriAsString)) : false;
137
140
  }
@@ -244,14 +247,7 @@ ${loggable(error)}`
244
247
  return project;
245
248
  }
246
249
  belongsTo(document) {
247
- let documentUri;
248
- if (typeof document === "string") {
249
- documentUri = hasProtocol(document) ? document : withProtocol(document, "file://");
250
- } else if (URI.isUri(document)) {
251
- documentUri = document.toString();
252
- } else {
253
- documentUri = document.uri.toString();
254
- }
250
+ const documentUri = normalizeUri(document);
255
251
  return this.findProjectForDocument(documentUri).id;
256
252
  }
257
253
  async reloadProjects(token) {
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.38.0",
4
+ "version": "1.38.1",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -123,7 +123,7 @@
123
123
  "remeda": "^2.23.1",
124
124
  "strip-indent": "^4.0.0",
125
125
  "tsx": "4.20.3",
126
- "turbo": "2.5.5",
126
+ "turbo": "2.5.6",
127
127
  "type-fest": "^4.41.0",
128
128
  "typescript": "5.9.2",
129
129
  "ufo": "1.6.1",
@@ -137,17 +137,17 @@
137
137
  "vscode-uri": "3.1.0",
138
138
  "which": "^5.0.0",
139
139
  "zod": "3.25.67",
140
- "@likec4/log": "1.38.0",
141
- "@likec4/icons": "1.38.0",
142
- "@likec4/core": "1.38.0",
143
- "@likec4/tsconfig": "1.38.0",
144
- "@likec4/layouts": "1.38.0"
140
+ "@likec4/core": "1.38.1",
141
+ "@likec4/layouts": "1.38.1",
142
+ "@likec4/tsconfig": "1.38.1",
143
+ "@likec4/icons": "1.38.1",
144
+ "@likec4/log": "1.38.1"
145
145
  },
146
146
  "scripts": {
147
147
  "typecheck": "tsc -b --verbose",
148
148
  "build": "unbuild",
149
149
  "pack": "pnpm pack",
150
- "pregenerate": "rm -f src/generated/*",
150
+ "pregenerate": "rm -f src/generated/* || true",
151
151
  "watch:langium": "langium generate --watch",
152
152
  "watch:ts": "tsc --watch",
153
153
  "generate": "langium generate && tsx scripts/generate-icons.ts",