@likec4/language-server 1.44.0 → 1.45.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.
- package/dist/LikeC4LanguageServices.d.ts +1 -15
- package/dist/LikeC4LanguageServices.js +2 -32
- package/dist/Rpc.js +32 -20
- package/dist/ast.js +6 -2
- package/dist/browser.js +2 -2
- package/dist/bundled.js +2 -0
- package/dist/bundled.mjs +3184 -3162
- package/dist/filesystem/ChokidarWatcher.d.ts +2 -0
- package/dist/filesystem/ChokidarWatcher.js +27 -16
- package/dist/filesystem/LikeC4FileSystem.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -3
- package/dist/mcp/server/StdioLikeC4MCPServer.js +10 -6
- package/dist/mcp/server/StreamableLikeC4MCPServer.js +97 -97
- package/dist/mcp/server/WithMCPServer.js +5 -5
- package/dist/mcp/tools/search-element.js +5 -5
- package/dist/mcp/utils.js +1 -1
- package/dist/model/deployments-index.js +2 -2
- package/dist/model/fqn-index.d.ts +1 -2
- package/dist/model/fqn-index.js +13 -16
- package/dist/model/model-builder.js +0 -2
- package/dist/model/model-parser.js +34 -27
- package/dist/model/parser/SpecificationParser.js +4 -0
- package/dist/model/parser/ViewsParser.js +3 -1
- package/dist/model-change/ModelChanges.d.ts +2 -2
- package/dist/model-change/ModelChanges.js +36 -9
- package/dist/protocol.d.ts +33 -10
- package/dist/protocol.js +13 -4
- package/dist/view-utils/manual-layout.js +2 -4
- package/dist/views/LikeC4ManualLayouts.d.ts +16 -2
- package/dist/views/LikeC4ManualLayouts.js +99 -22
- package/dist/views/LikeC4Views.d.ts +26 -5
- package/dist/views/LikeC4Views.js +49 -33
- package/dist/workspace/AstNodeDescriptionProvider.js +6 -3
- package/dist/workspace/IndexManager.js +1 -1
- package/dist/workspace/LangiumDocuments.d.ts +3 -2
- package/dist/workspace/LangiumDocuments.js +29 -15
- package/dist/workspace/ProjectsManager.d.ts +19 -15
- package/dist/workspace/ProjectsManager.js +137 -41
- package/dist/workspace/WorkspaceManager.js +5 -0
- package/package.json +16 -15
|
@@ -37,6 +37,7 @@ export interface LikeC4LanguageServices {
|
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Returns diagrams (i.e. views with layout computed) for the specified project
|
|
40
|
+
* if diagram has manual layout, it will be used
|
|
40
41
|
* If no project is specified, returns diagrams for default project
|
|
41
42
|
*/
|
|
42
43
|
diagrams(project?: ProjectId | undefined, cancelToken?: CancellationToken): Promise<DiagramView[]>;
|
|
@@ -48,14 +49,6 @@ export interface LikeC4LanguageServices {
|
|
|
48
49
|
range: Range;
|
|
49
50
|
sourceFsPath: string;
|
|
50
51
|
}>;
|
|
51
|
-
/**
|
|
52
|
-
* Notifies the language server about changes in the workspace
|
|
53
|
-
* @deprecated use watcher instead
|
|
54
|
-
*/
|
|
55
|
-
notifyUpdate(update: {
|
|
56
|
-
changed?: string;
|
|
57
|
-
removed?: string;
|
|
58
|
-
}): Promise<boolean>;
|
|
59
52
|
/**
|
|
60
53
|
* Returns the location of the specified element, relation, view or deployment element
|
|
61
54
|
*/
|
|
@@ -108,13 +101,6 @@ export declare class DefaultLikeC4LanguageServices implements LikeC4LanguageServ
|
|
|
108
101
|
range: Range;
|
|
109
102
|
sourceFsPath: string;
|
|
110
103
|
}>;
|
|
111
|
-
/**
|
|
112
|
-
* TODO Replace with watcher
|
|
113
|
-
*/
|
|
114
|
-
notifyUpdate({ changed, removed }: {
|
|
115
|
-
changed?: string;
|
|
116
|
-
removed?: string;
|
|
117
|
-
}): Promise<boolean>;
|
|
118
104
|
locate(params: Locate.Params): Locate.Res;
|
|
119
105
|
dispose(): Promise<void>;
|
|
120
106
|
}
|
|
@@ -4,8 +4,7 @@ import { loggable } from '@likec4/log';
|
|
|
4
4
|
import { URI } from 'langium';
|
|
5
5
|
import { entries, hasAtLeast, indexBy, map, pipe, prop } from 'remeda';
|
|
6
6
|
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
7
|
-
import {
|
|
8
|
-
import { logger as mainLogger, logWarnError } from './logger';
|
|
7
|
+
import { logger as mainLogger } from './logger';
|
|
9
8
|
import { ProjectsManager } from './workspace';
|
|
10
9
|
const logger = mainLogger.getChild('LanguageServices');
|
|
11
10
|
/**
|
|
@@ -99,7 +98,7 @@ export class DefaultLikeC4LanguageServices {
|
|
|
99
98
|
const projectId = this.projectsManager.ensureProjectId(project);
|
|
100
99
|
const model = await this.builder.computeModel(projectId, cancelToken);
|
|
101
100
|
if (!model) {
|
|
102
|
-
throw new Error('Failed to
|
|
101
|
+
throw new Error('Failed to compute model, empty project?');
|
|
103
102
|
}
|
|
104
103
|
const layouted = await this.views.layoutAllViews(projectId, cancelToken);
|
|
105
104
|
return LikeC4Model.create({
|
|
@@ -121,35 +120,6 @@ export class DefaultLikeC4LanguageServices {
|
|
|
121
120
|
}));
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
|
-
/**
|
|
125
|
-
* TODO Replace with watcher
|
|
126
|
-
*/
|
|
127
|
-
async notifyUpdate({ changed, removed }) {
|
|
128
|
-
if (!changed && !removed) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
const _changed = changed ? URI.file(changed) : undefined;
|
|
132
|
-
const _removed = removed ? URI.file(removed) : undefined;
|
|
133
|
-
const pm = this.services.shared.workspace.ProjectsManager;
|
|
134
|
-
if ((_changed && pm.isConfigFile(_changed)) || (_removed && pm.isConfigFile(_removed))) {
|
|
135
|
-
await pm.reloadProjects();
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
const mutex = this.services.shared.workspace.WorkspaceLock;
|
|
139
|
-
try {
|
|
140
|
-
let completed = false;
|
|
141
|
-
await mutex.write(async (token) => {
|
|
142
|
-
await this.services.shared.workspace.DocumentBuilder.update(_changed ? [_changed] : [], _removed ? [_removed] : [], token);
|
|
143
|
-
// we come here if only the update was successful, did not throw and not cancelled
|
|
144
|
-
completed = !token.isCancellationRequested;
|
|
145
|
-
});
|
|
146
|
-
return completed;
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
logger.error(loggable(e));
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
123
|
locate(params) {
|
|
154
124
|
switch (true) {
|
|
155
125
|
case 'element' in params:
|
package/dist/Rpc.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { filter, flatMap, funnel, indexBy, keys, map, mapValues, pipe, sort } from 'remeda';
|
|
2
2
|
import { logger as rootLogger } from './logger';
|
|
3
|
-
import { serializableLikeC4ProjectConfig } from '@likec4/config';
|
|
4
3
|
import { invariant, nonexhaustive, } from '@likec4/core';
|
|
5
4
|
import { LikeC4Model } from '@likec4/core/model';
|
|
6
5
|
import { Disposable, interruptAndCheck, URI, UriUtils } from 'langium';
|
|
7
6
|
import { DiagnosticSeverity } from 'vscode-languageserver-protocol';
|
|
8
|
-
import { BuildDocuments, ChangeView, DidChangeModelNotification, DidRequestOpenViewNotification, FetchComputedModel, FetchLayoutedModel, FetchProjects, FetchTelemetryMetrics, FetchViewsFromAllProjects, GetDocumentTags, LayoutView, Locate, RegisterProject, ReloadProjects, ValidateLayout, } from './protocol';
|
|
7
|
+
import { BuildDocuments, ChangeView, DidChangeModelNotification, DidChangeSnapshotNotification, DidRequestOpenViewNotification, FetchComputedModel, FetchLayoutedModel, FetchProjects, FetchTelemetryMetrics, FetchViewsFromAllProjects, GetDocumentTags, LayoutView, Locate, RegisterProject, ReloadProjects, ValidateLayout, } from './protocol';
|
|
9
8
|
import { ADisposable } from './utils';
|
|
10
9
|
const logger = rootLogger.getChild('rpc');
|
|
11
10
|
export class Rpc extends ADisposable {
|
|
@@ -17,28 +16,28 @@ export class Rpc extends ADisposable {
|
|
|
17
16
|
init() {
|
|
18
17
|
const connection = this.services.shared.lsp.Connection;
|
|
19
18
|
if (!connection) {
|
|
20
|
-
logger.info(`
|
|
19
|
+
logger.info(`no connection, skip init ServerRpc`);
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
23
|
-
logger.info(`
|
|
22
|
+
logger.info(`init ServerRpc`);
|
|
24
23
|
const likec4Services = this.services.likec4;
|
|
25
24
|
const projects = this.services.shared.workspace.ProjectsManager;
|
|
26
25
|
const LangiumDocuments = this.services.shared.workspace.LangiumDocuments;
|
|
27
26
|
const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
|
|
28
|
-
const notifyModelParsed = funnel(() => {
|
|
29
|
-
logger.debug `
|
|
27
|
+
const notifyModelParsed = funnel((batch) => {
|
|
28
|
+
logger.debug `send onDidChangeModel ${batch > 1 ? '(' + batch + ' batched)' : ''}`;
|
|
30
29
|
connection.sendNotification(DidChangeModelNotification.type, '').catch(error => {
|
|
31
30
|
logger.warn(`[ServerRpc] error sending onDidChangeModel:`, { error });
|
|
32
31
|
return;
|
|
33
32
|
});
|
|
34
33
|
}, {
|
|
34
|
+
reducer: (accumulator, req) => (accumulator ?? 0) + req,
|
|
35
35
|
triggerAt: 'end',
|
|
36
|
-
minQuietPeriodMs:
|
|
37
|
-
maxBurstDurationMs:
|
|
38
|
-
minGapMs: 300,
|
|
36
|
+
minQuietPeriodMs: 200,
|
|
37
|
+
maxBurstDurationMs: 400,
|
|
39
38
|
});
|
|
40
39
|
let isFirstBuild = true;
|
|
41
|
-
this.onDispose(likec4Services.ModelBuilder.onModelParsed(() => notifyModelParsed.call()), connection.onRequest(FetchComputedModel.req, async ({ projectId, cleanCaches }, cancelToken) => {
|
|
40
|
+
this.onDispose(likec4Services.ModelBuilder.onModelParsed(() => notifyModelParsed.call(1)), connection.onRequest(FetchComputedModel.req, async ({ projectId, cleanCaches }, cancelToken) => {
|
|
42
41
|
logger.debug `received request ${'fetchComputedModel'} for project ${projectId}`;
|
|
43
42
|
if (cleanCaches) {
|
|
44
43
|
const docs = projectId
|
|
@@ -52,6 +51,10 @@ export class Rpc extends ADisposable {
|
|
|
52
51
|
return { model: likec4model.$model };
|
|
53
52
|
}
|
|
54
53
|
return { model: null };
|
|
54
|
+
}), connection.onNotification(DidChangeSnapshotNotification.type, async ({ snapshotUri }) => {
|
|
55
|
+
logger.debug `received notification ${'onDidChangeSnapshot'} for snapshot ${snapshotUri}`;
|
|
56
|
+
const uri = URI.parse(snapshotUri);
|
|
57
|
+
await projects.rebuidProject(projects.belongsTo(uri.path));
|
|
55
58
|
}), connection.onRequest(FetchLayoutedModel.req, async ({ projectId }, cancelToken) => {
|
|
56
59
|
logger.debug `received request ${'fetchLayoutedModel'} for project ${projectId}`;
|
|
57
60
|
const model = await likec4Services.LanguageServices.layoutedModel(projectId);
|
|
@@ -66,24 +69,33 @@ export class Rpc extends ADisposable {
|
|
|
66
69
|
views: indexBy(diagrams, d => d.id),
|
|
67
70
|
},
|
|
68
71
|
};
|
|
69
|
-
}), connection.onRequest(LayoutView.req, async ({ viewId, projectId }, cancelToken) => {
|
|
70
|
-
logger
|
|
71
|
-
|
|
72
|
+
}), connection.onRequest(LayoutView.req, async ({ viewId, projectId, layoutType, }, cancelToken) => {
|
|
73
|
+
logger
|
|
74
|
+
.debug `received request ${'layoutView'} for ${viewId} from project ${projectId} (layout type: ${layoutType ?? 'not set'})`;
|
|
75
|
+
const result = await likec4Services.Views.layoutView({
|
|
76
|
+
viewId,
|
|
77
|
+
projectId: projectId,
|
|
78
|
+
layoutType,
|
|
79
|
+
cancelToken,
|
|
80
|
+
});
|
|
72
81
|
return { result };
|
|
73
|
-
}), connection.onRequest(ValidateLayout.
|
|
82
|
+
}), connection.onRequest(ValidateLayout.req, async ({ projectId }, cancelToken) => {
|
|
74
83
|
logger.debug `received request ${'validateLayout'} for project ${projectId}`;
|
|
75
84
|
const layouts = await likec4Services.Views.layoutAllViews(projectId, cancelToken);
|
|
76
85
|
const result = reportLayoutDrift(layouts.map(l => l.diagram));
|
|
77
86
|
return { result };
|
|
78
|
-
}), connection.onRequest(FetchProjects.req, async (
|
|
87
|
+
}), connection.onRequest(FetchProjects.req, async () => {
|
|
79
88
|
logger.debug `received request ${'FetchProjects'}`;
|
|
80
89
|
const docsByProject = LangiumDocuments.groupedByProject();
|
|
81
90
|
return {
|
|
82
91
|
projects: mapValues(docsByProject, (docs, projectId) => {
|
|
83
|
-
const { folderUri, config, } = projects.getProject(projectId);
|
|
92
|
+
const { folderUri, config: { name, title, }, } = projects.getProject(projectId);
|
|
84
93
|
return {
|
|
85
94
|
folder: folderUri.toString(),
|
|
86
|
-
config:
|
|
95
|
+
config: {
|
|
96
|
+
name,
|
|
97
|
+
title,
|
|
98
|
+
},
|
|
87
99
|
docs: map(docs, d => d.uri.toString()),
|
|
88
100
|
};
|
|
89
101
|
}),
|
|
@@ -120,7 +132,7 @@ export class Rpc extends ADisposable {
|
|
|
120
132
|
return {
|
|
121
133
|
views: pipe(results, filter(r => r.status === 'fulfilled'), flatMap(r => r.value)),
|
|
122
134
|
};
|
|
123
|
-
}), connection.onRequest(BuildDocuments.
|
|
135
|
+
}), connection.onRequest(BuildDocuments.req, async ({ docs }, cancelToken) => {
|
|
124
136
|
const changed = docs.map(d => URI.parse(d));
|
|
125
137
|
const notChanged = (uri) => changed.every(c => !UriUtils.equals(c, uri));
|
|
126
138
|
const deleted = LangiumDocuments.allExcludingBuiltin
|
|
@@ -149,7 +161,7 @@ export class Rpc extends ADisposable {
|
|
|
149
161
|
isFirstBuild = false;
|
|
150
162
|
await interruptAndCheck(cancelToken);
|
|
151
163
|
await DocumentBuilder.update(changed, deleted, cancelToken);
|
|
152
|
-
}), connection.onRequest(Locate.
|
|
164
|
+
}), connection.onRequest(Locate.req, params => {
|
|
153
165
|
logger.debug `received request ${'locate'}, ${params}`;
|
|
154
166
|
switch (true) {
|
|
155
167
|
case 'element' in params:
|
|
@@ -169,7 +181,7 @@ export class Rpc extends ADisposable {
|
|
|
169
181
|
default:
|
|
170
182
|
nonexhaustive(params);
|
|
171
183
|
}
|
|
172
|
-
}), connection.onRequest(ChangeView.
|
|
184
|
+
}), connection.onRequest(ChangeView.req, async (request, _cancelToken) => {
|
|
173
185
|
logger.debug `received request ${'changeView'} of ${request.viewId} from project ${request.projectId}`;
|
|
174
186
|
return await likec4Services.ModelChanges.applyChange(request);
|
|
175
187
|
}), connection.onRequest(FetchTelemetryMetrics.req, async (cancelToken) => {
|
package/dist/ast.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MultiMap, nonexhaustive } from '@likec4/core/utils';
|
|
1
|
+
import { invariant, MultiMap, nonexhaustive } from '@likec4/core/utils';
|
|
2
2
|
import { AstUtils, DocumentState } from 'langium';
|
|
3
3
|
import { clamp, isNullish, isTruthy } from 'remeda';
|
|
4
4
|
import * as ast from './generated/ast';
|
|
@@ -29,7 +29,11 @@ export const ElementOps = {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
export function isLikeC4LangiumDocument(doc) {
|
|
32
|
-
|
|
32
|
+
if (doc.textDocument.languageId === LikeC4LanguageMetaData.languageId) {
|
|
33
|
+
invariant(isTruthy(doc.likec4ProjectId), `LikeC4Document must have projectId defined: ${doc.uri.fsPath}`);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
33
37
|
}
|
|
34
38
|
export function isParsedLikeC4LangiumDocument(doc) {
|
|
35
39
|
return (isLikeC4LangiumDocument(doc)
|
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { configureLogger,
|
|
1
|
+
import { configureLogger, getConsoleSink, getTextFormatter } from '@likec4/log';
|
|
2
2
|
import { startLanguageServer as startLanguim } from 'langium/lsp';
|
|
3
3
|
import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser';
|
|
4
4
|
import { createLanguageServices } from './module';
|
|
@@ -12,7 +12,7 @@ export function startLanguageServer(port) {
|
|
|
12
12
|
configureLogger({
|
|
13
13
|
sinks: {
|
|
14
14
|
console: getConsoleSink({
|
|
15
|
-
formatter:
|
|
15
|
+
formatter: getTextFormatter({
|
|
16
16
|
format: ({ level, category, message }) => {
|
|
17
17
|
return `${level} ${category} ${message}`;
|
|
18
18
|
},
|
package/dist/bundled.js
CHANGED
|
@@ -6,6 +6,7 @@ import { getLspConnectionSink, logger } from './logger';
|
|
|
6
6
|
import { WithMCPServer } from './mcp/server/WithMCPServer';
|
|
7
7
|
import { createLanguageServices } from './module';
|
|
8
8
|
import { ConfigurableLayouter } from './views/ConfigurableLayouter';
|
|
9
|
+
import { WithLikeC4ManualLayouts } from './views/LikeC4ManualLayouts';
|
|
9
10
|
/**
|
|
10
11
|
* This is used as `bin` entry point to start the language server.
|
|
11
12
|
*/
|
|
@@ -35,6 +36,7 @@ export function startLanguageServer() {
|
|
|
35
36
|
connection,
|
|
36
37
|
...LikeC4FileSystem(false),
|
|
37
38
|
...WithMCPServer('sse'),
|
|
39
|
+
...WithLikeC4ManualLayouts,
|
|
38
40
|
}, ConfigurableLayouter);
|
|
39
41
|
// Start the language server with the shared services
|
|
40
42
|
startLanguim(services.shared);
|