Skip to content

Commit 2e40465

Browse files
add notification
1 parent a295242 commit 2e40465

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

editor/src/ctx.ts

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class Ctx {
2727
private _extensionContext: vscode.ExtensionContext;
2828
private _commands: Record<string, CommandCallback>;
2929
private _config: Config;
30-
private _listOpenedDB: Set<string> = new Set();
3130

3231
constructor(ctx: vscode.ExtensionContext) {
3332
this._client = null;
@@ -221,41 +220,6 @@ export class Ctx {
221220
},
222221
initializationOptions: this._config.cfg,
223222
diagnosticCollectionName: "4d",
224-
middleware: {
225-
didOpen: async (document, next) => {
226-
const project = this._onFileOpened(document);
227-
228-
//If first time opening a file from that project, start downloading packages
229-
if (project && !this._listOpenedDB.has(project)) {
230-
this._listOpenedDB.add(project);
231-
//Start downloading packages for that project
232-
const packageManager = new PackageManager(project);
233-
packageManager.initialize();
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-
});
253-
}
254-
255-
return next(document);
256-
257-
}
258-
}
259223
};
260224
// Create the language client and start the client.
261225
this._client = new LanguageClient(
@@ -264,7 +228,23 @@ export class Ctx {
264228
serverOptions,
265229
clientOptions
266230
);
231+
this._client.onNotification(ext.notif_needFetchNotification, async (params) => {
232+
const packageManager = new PackageManager(params.uri);
233+
packageManager.initialize();
234+
packageManager.fetch().then(()=> {
235+
this._client.sendNotification(ext.notif_installComponents, params);
236+
});
237+
return true;
238+
});
267239

240+
this._client.onNotification(ext.notif_installComponents_before, async (params) => {
241+
this._client.sendNotification(ext.notif_installComponents, params);
242+
return true;
243+
});
244+
245+
this._client.onNotification(ext.notif_installComponents_progress, async (params) => {
246+
return true;
247+
});
268248
this._client.start();
269249
}
270250

@@ -290,34 +270,6 @@ export class Ctx {
290270
}
291271
}
292272

293-
private _onFileOpened(document: vscode.TextDocument): string | undefined {
294-
// Callback when a file is opened
295-
Logger.debugLog(`File opened: ${document.fileName} (${document.languageId})`);
296-
297-
if (document.languageId === '4d' || document.languageId === '4qs') {
298-
//Find 4D Project path and store it, recursive solution going up the folder tree until .4DProject is found
299-
//The .4DProject is in a folder called Project
300-
301-
let folderPath = vscode.workspace.getWorkspaceFolder(document.uri)?.uri.fsPath;
302-
let currentPath = path.dirname(document.uri.fsPath);
303-
304-
while (currentPath && currentPath !== folderPath) {
305-
306-
const projectName = path.basename(currentPath);
307-
const projectFilePath = path.join(currentPath, "Project");
308-
if (existsSync(path.join(projectFilePath, projectName + ".4DProject"))) {
309-
return projectFilePath;
310-
}
311-
312-
const parentPath = path.dirname(currentPath);
313-
if (parentPath === currentPath) {
314-
break; // Reached the root directory
315-
}
316-
currentPath = parentPath;
317-
}
318-
}
319-
}
320-
321273
public registerCommands() {
322274

323275
this._commands = {

editor/src/lsp_ext.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ export const checkWorkspaceSyntax = new lc.RequestType<lc.TextDocumentIdentifier
99
"experimental/checkSyntax"
1010
);
1111

12+
export const notif_needFetchNotification = new lc.NotificationType<lc.TextDocumentIdentifier>(
13+
"dependency/fetch"
14+
);
1215

13-
export const installComponents = new lc.RequestType<lc.TextDocumentIdentifier, void, void>(
16+
export const notif_installComponents = new lc.NotificationType<lc.TextDocumentIdentifier>(
1417
"dependency/installComponents"
1518
);
1619

17-
18-
export const needFetch = new lc.RequestType<lc.TextDocumentIdentifier, boolean, void>(
19-
"dependency/shouldFetch"
20+
export const notif_installComponents_progress = new lc.NotificationType<lc.TextDocumentIdentifier>(
21+
"dependency/installComponents/progress"
2022
);
23+
24+
export const notif_installComponents_before = new lc.NotificationType<lc.TextDocumentIdentifier>(
25+
"dependency/installComponents/before"
26+
);

0 commit comments

Comments
 (0)