Skip to content

Commit 06dac68

Browse files
WIP: add package manager
1 parent 8e16bb2 commit 06dac68

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

editor/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@
206206
"test": "node ./out/test/runTest.js"
207207
},
208208
"dependencies": {
209-
"vscode-languageclient": "^9.0.1"
209+
"vscode-languageclient": "^9.0.1",
210+
"@4dsas/package-manager": "file:../../packageManager"
210211
},
211212
"devDependencies": {
212213
"@types/mocha": "^10.0.10",

editor/src/ctx.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import * as Commands from "./commands";
33
import { Config } from "./config";
44
import { LabeledVersion } from './labeledVersion';
5-
import { ResultUpdate, ToolPreparator } from "./toolPreparator";
5+
import { ResultUpdate, ToolPreparator } from "./tool4D/toolPreparator";
66
import {
77
LanguageClient,
88
LanguageClientOptions,
@@ -15,6 +15,7 @@ import * as net from 'net';
1515
import { Logger } from "./logger";
1616
import { existsSync, readdirSync, rmdirSync, rm } from "fs";
1717
import * as path from "path";
18+
import {PackageManager} from "@4dsas/package-manager";
1819

1920
export type CommandCallback = {
2021
call: (ctx: Ctx) => Commands.Cmd;
@@ -25,6 +26,7 @@ export class Ctx {
2526
private _extensionContext: vscode.ExtensionContext;
2627
private _commands: Record<string, CommandCallback>;
2728
private _config: Config;
29+
private _listOpenedDB: Set<string> = new Set();
2830

2931
constructor(ctx: vscode.ExtensionContext) {
3032
this._client = null;
@@ -218,6 +220,21 @@ export class Ctx {
218220
},
219221
initializationOptions: this._config.cfg,
220222
diagnosticCollectionName: "4d",
223+
middleware: {
224+
didOpen: async (document, next) => {
225+
const project = this._onFileOpened(document);
226+
227+
//If first time opening a file from that project, start downloading packages
228+
if( project && !this._listOpenedDB.has(project)) {
229+
this._listOpenedDB.add(project);
230+
//Start downloading packages for that project
231+
const packageManager = new PackageManager(project);
232+
packageManager.initialize();
233+
await packageManager.fetch();
234+
}
235+
return next(document);
236+
}
237+
}
221238
};
222239
// Create the language client and start the client.
223240
this._client = new LanguageClient(
@@ -252,6 +269,34 @@ export class Ctx {
252269
}
253270
}
254271

272+
private _onFileOpened(document: vscode.TextDocument) : string | undefined{
273+
// Callback when a file is opened
274+
Logger.debugLog(`File opened: ${document.fileName} (${document.languageId})`);
275+
276+
if (document.languageId === '4d' || document.languageId === '4qs') {
277+
//Find 4D Project path and store it, recursive solution going up the folder tree until .4DProject is found
278+
//The .4DProject is in a folder called Project
279+
280+
let folderPath = vscode.workspace.getWorkspaceFolder(document.uri)?.uri.fsPath;
281+
let currentPath = path.dirname(document.uri.fsPath);
282+
283+
while (currentPath && currentPath !== folderPath) {
284+
285+
const projectName = path.basename(currentPath);
286+
const projectFilePath = path.join(currentPath, "Project");
287+
if(existsSync(path.join(projectFilePath, projectName + ".4DProject"))) {
288+
return projectFilePath;
289+
}
290+
291+
const parentPath = path.dirname(currentPath);
292+
if (parentPath === currentPath) {
293+
break; // Reached the root directory
294+
}
295+
currentPath = parentPath;
296+
}
297+
}
298+
}
299+
255300
public registerCommands() {
256301

257302
this._commands = {

editor/src/test/toolDownload.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getDocPath } from './helper';
2-
import { ToolPreparator } from '../toolPreparator';
3-
import { APIManager, requestLabelVersion } from '../apiManager';
2+
import { ToolPreparator } from '../tool4D/toolPreparator';
3+
import { APIManager, requestLabelVersion } from '../tool4D/apiManager';
44
import { LabeledVersion } from '../labeledVersion';
55
import * as assert from 'assert';
66
import * as vscode from 'vscode';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { LabeledVersion } from "./labeledVersion";
1+
import { LabeledVersion } from "../labeledVersion";
22
import * as fs from 'fs';
33
import * as os from 'os';
4-
import { Logger } from './logger';
4+
import { Logger } from '../logger';
55
import { existsSync, mkdirSync } from "fs";
66
import * as path from 'path';
77
import * as https from 'https';
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { existsSync, mkdirSync, readdirSync } from "fs";
33
import * as child_process from 'child_process';
44
import * as path from 'path';
55
import * as vscode from 'vscode';
6-
import { LabeledVersion } from './labeledVersion';
7-
import { InfoPlistManager } from './infoplist';
6+
import { LabeledVersion } from '../labeledVersion';
7+
import { InfoPlistManager } from '../infoplist';
88
import { window, ProgressLocation } from 'vscode';
9-
import { Logger } from './logger';
9+
import { Logger } from '../logger';
1010
import { APIManager } from './apiManager';
1111

1212
export interface ResultUpdate {

0 commit comments

Comments
 (0)