Skip to content

Commit a295242

Browse files
add new requests
1 parent 06dac68 commit a295242

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

editor/src/ctx.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
LanguageClientOptions,
99
StreamInfo,
1010
} from 'vscode-languageclient/node';
11+
import * as ext from "./lsp_ext";
1112

1213
import { workspace } from 'vscode';
1314
import * as child_process from 'child_process';
1415
import * as net from 'net';
1516
import { Logger } from "./logger";
1617
import { existsSync, readdirSync, rmdirSync, rm } from "fs";
1718
import * as path from "path";
18-
import {PackageManager} from "@4dsas/package-manager";
19+
import { FetchResult, PackageManager } from "@4dsas/package-manager";
1920

2021
export type CommandCallback = {
2122
call: (ctx: Ctx) => Commands.Cmd;
@@ -221,18 +222,38 @@ export class Ctx {
221222
initializationOptions: this._config.cfg,
222223
diagnosticCollectionName: "4d",
223224
middleware: {
224-
didOpen: async (document, next) => {
225+
didOpen: async (document, next) => {
225226
const project = this._onFileOpened(document);
226227

227228
//If first time opening a file from that project, start downloading packages
228-
if( project && !this._listOpenedDB.has(project)) {
229+
if (project && !this._listOpenedDB.has(project)) {
229230
this._listOpenedDB.add(project);
230231
//Start downloading packages for that project
231232
const packageManager = new PackageManager(project);
232233
packageManager.initialize();
233-
await packageManager.fetch();
234+
const params = this._client.code2ProtocolConverter.asTextDocumentIdentifier(
235+
vscode.window.activeTextEditor.document
236+
);
237+
238+
return new Promise<void>(async (resolve, reject) => {
239+
next(document);
240+
if (await this._client.sendRequest(ext.needFetch, params)) {
241+
packageManager.fetch().then(async (result) => {
242+
await this._client.sendRequest(ext.installComponents, params);
243+
}).catch(() => {
244+
// Handle errors if needed
245+
});
246+
}
247+
else {
248+
//TODO: should have a progress indicator
249+
await this._client.sendRequest(ext.installComponents, params);
250+
}
251+
resolve();
252+
});
234253
}
254+
235255
return next(document);
256+
236257
}
237258
}
238259
};
@@ -269,7 +290,7 @@ export class Ctx {
269290
}
270291
}
271292

272-
private _onFileOpened(document: vscode.TextDocument) : string | undefined{
293+
private _onFileOpened(document: vscode.TextDocument): string | undefined {
273294
// Callback when a file is opened
274295
Logger.debugLog(`File opened: ${document.fileName} (${document.languageId})`);
275296

@@ -284,7 +305,7 @@ export class Ctx {
284305

285306
const projectName = path.basename(currentPath);
286307
const projectFilePath = path.join(currentPath, "Project");
287-
if(existsSync(path.join(projectFilePath, projectName + ".4DProject"))) {
308+
if (existsSync(path.join(projectFilePath, projectName + ".4DProject"))) {
288309
return projectFilePath;
289310
}
290311

editor/src/lsp_ext.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ export const filesStatus = new lc.RequestType0<object, void>(
88
export const checkWorkspaceSyntax = new lc.RequestType<lc.TextDocumentIdentifier, WorkspaceDiagnosticReport, void>(
99
"experimental/checkSyntax"
1010
);
11+
12+
13+
export const installComponents = new lc.RequestType<lc.TextDocumentIdentifier, void, void>(
14+
"dependency/installComponents"
15+
);
16+
17+
18+
export const needFetch = new lc.RequestType<lc.TextDocumentIdentifier, boolean, void>(
19+
"dependency/shouldFetch"
20+
);

0 commit comments

Comments
 (0)