import { extensionId } from "./ExtensionInformation.js"; import { ItemType } from "./ItemType.js"; import * as cp from "child_process"; import * as vscode from 'vscode'; export type Folder = { name: string, id: number, children: Folder[] }; export type FolderResult = { folders: Folder[] }; export type ItemResult = { name: string, itemType: ItemType, data: string, stringData: string }; const extension = vscode.extensions.getExtension(extensionId); const extensionPath = extension?.extensionPath + "/binary"; const extensionDll = extensionPath + "/TiaFileFormatServer.dll"; export class TiaProjectServerFetchApi { //@ts-ignore static process: cp.ChildProcessWithoutNullStreams | null; static baseUri: string; static updateBaseuriAndLaunchServer(baseUri: string) { TiaProjectServerFetchApi.process?.kill('SIGINT'); TiaProjectServerFetchApi.baseUri = baseUri ?? "http://127.0.0.1:5400"; if (true) { //disable when using c# directly this.process = cp.spawn("dotnet", [extensionDll, this.baseUri], { cwd: extensionPath, //shell: true, detached: true }); } } static stopServer() { this.process?.kill('SIGINT'); this.process = null; } static async closeProject(file: string): Promise { const response = await fetch(TiaProjectServerFetchApi.baseUri + "/closeProject", { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, method: "POST", body: JSON.stringify({ file: file }) }); } static async getFolders(file: string): Promise { const response = await fetch(TiaProjectServerFetchApi.baseUri + "/getFolders", { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, method: "POST", body: JSON.stringify({ file: file }) }); const answer = await response.json(); return answer; } static async getItem(file: string, id: number): Promise { const response = await fetch(TiaProjectServerFetchApi.baseUri + "/getItem", { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, method: "POST", body: JSON.stringify({ file: file, id: id }) }); const answer = await response.json(); return answer; } }