diff --git a/src/api/index.ts b/src/api/index.ts index 87e434f0..cd575a78 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -188,6 +188,11 @@ export class AtelierAPI { return this.cookies; } const data = response.body; + /// deconde encoded content + if (data.result && data.result.enc && data.result.content) { + data.result.enc = false; + data.result.content = Buffer.from(data.result.content.join(""), "base64"); + } if (data.console) { outputConsole(data.console); } diff --git a/src/extension.ts b/src/extension.ts index 7c1a2bc4..037c67ab 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -179,10 +179,9 @@ export async function activate(context: vscode.ExtensionContext): Promise }); workspace.onDidSaveTextDocument(file => { - if (!languages.includes(file.languageId)) { - return; + if (schemas.includes(file.uri.scheme) || languages.includes(file.languageId)) { + vscode.commands.executeCommand("vscode-objectscript.compile"); } - vscode.commands.executeCommand("vscode-objectscript.compile"); }); vscode.window.onDidChangeActiveTextEditor((textEditor: vscode.TextEditor) => { diff --git a/src/providers/FileSystemPovider/FileSystemProvider.ts b/src/providers/FileSystemPovider/FileSystemProvider.ts index 0b404cb5..12f5a57d 100644 --- a/src/providers/FileSystemPovider/FileSystemProvider.ts +++ b/src/providers/FileSystemPovider/FileSystemProvider.ts @@ -1,5 +1,6 @@ import * as path from "path"; import * as vscode from "vscode"; +import * as url from "url"; import { AtelierAPI } from "../../api"; import { Directory } from "./Directory"; import { File } from "./File"; @@ -26,17 +27,36 @@ export class FileSystemProvider implements vscode.FileSystemProvider { public async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> { const api = new AtelierAPI(uri); const parent = await this._lookupAsDirectory(uri); - const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,0)`; - const folder = uri.path === "/" ? "/" : uri.path.replace(/\//g, ".") + "/"; - const spec = folder.slice(1) + "*.cls,*.inc,*.int,*.mac"; + const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)`; + const { query } = url.parse(decodeURIComponent(uri.toString()), true); + const type = String(query && query.type).toLowerCase() || "all"; + const csp = query.csp === "" || query.csp === "1"; + let filter = query.filter || ""; + if (csp) { + filter = filter || "*"; + } else if (type === "rtn") { + filter = "*.inc,*.int,*.mac"; + } else if (type === "cls") { + filter = "*.cls"; + } else { + filter = query.filter || "*.cls,*.inc,*.int,*.mac"; + } + const folder = csp ? (uri.path.endsWith("/") ? uri.path : uri.path + "/") : uri.path.replace(/\//g, "."); + const spec = csp ? folder + filter : folder.slice(1) + filter; + const dir = "1"; + const orderBy = "1"; + const system = api.ns === "%SYS" ? "1" : "0"; + const flat = String(query.flat) || "0"; + const notStudio = "0"; + const generated = String(query.generated) || "0"; return api - .actionQuery(sql, [spec]) + .actionQuery(sql, [spec, dir, orderBy, system, flat, notStudio, generated]) .then(data => data.result.content || []) .then(data => data.map(item => { const name = item.Name; const fullName = folder === "" ? name : folder + "/" + name; - if (item.IsDirectory.length) { + if (item.Type === "10" || item.Type === "9") { parent.entries.set(name, new Directory(name, fullName)); return [name, vscode.FileType.Directory]; } else { @@ -76,7 +96,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider { overwrite: boolean; } ): void | Thenable { - const fileName = uri.path.slice(1).replace(/\//g, "."); + const { query } = url.parse(decodeURIComponent(uri.toString()), true); + const csp = query.csp === "" || query.csp === "1"; + const fileName = csp ? uri.path : uri.path.slice(1).replace(/\//g, "."); if (fileName.startsWith(".")) { return; } @@ -143,10 +165,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider { } private async _lookupAsFile(uri: vscode.Uri): Promise { - // if (!uri.path.match(/\.\w+$/)) { - // return Promise.resolve(new Directory(uri.path)) - // } - const fileName = uri.path.slice(1).replace(/\//g, "."); + const { query } = url.parse(decodeURIComponent(uri.toString()), true); + const csp = query.csp === "" || query.csp === "1"; + const fileName = csp ? uri.path : uri.path.slice(1).replace(/\//g, "."); if (fileName.startsWith(".")) { throw vscode.FileSystemError.FileNotFound(); } @@ -155,7 +176,16 @@ export class FileSystemProvider implements vscode.FileSystemProvider { return api .getDoc(fileName) .then(data => data.result) - .then(({ ts, content }) => new File(name, fileName, ts, content.join("\n").length, content.join("\n"))) + .then( + ({ ts, content }) => + new File( + name, + fileName, + ts, + Array.isArray(content) ? content.join("\n").length : content.length, + Array.isArray(content) ? content.join("\n") : content + ) + ) .then(entry => this._lookupParentDirectory(uri).then(parent => { parent.entries.set(name, entry); diff --git a/src/utils/index.ts b/src/utils/index.ts index 6a90cf81..46ae8ac4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,6 @@ import fs = require("fs"); import path = require("path"); +import * as url from "url"; import { execSync } from "child_process"; import * as vscode from "vscode"; import { config, schemas, workspaceState } from "../extension"; @@ -22,7 +23,10 @@ export interface CurrentFile { export function currentFile(document?: vscode.TextDocument): CurrentFile { document = document || (vscode.window.activeTextEditor.document ? vscode.window.activeTextEditor.document : null); - if (!document || !document.fileName || !document.languageId || !document.languageId.startsWith("objectscript")) { + if ( + !schemas.includes(document.uri.scheme) && + (!document || !document.fileName || !document.languageId || !document.languageId.startsWith("objectscript")) + ) { return null; } const uri = document.uri; @@ -31,20 +35,16 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile { const fileExt = fileName.match(/\.(\w+)$/)[1].toLowerCase(); let name = ""; let ext = ""; - if (fileExt === "cls") { + const { query } = url.parse(decodeURIComponent(uri.toString()), true); + const csp = query.csp === "" || query.csp === "1"; + if (csp) { + name = fileName; + } else if (fileExt === "cls") { const match = content.match(/^Class (%?\w+(?:\.\w+)+)/im); if (match) { name = match[1]; ext = "cls"; } - } else if (fileExt === "csp") { - name = - config().conn.label.toLowerCase() + - fileName - .split(config().conn.label.toLowerCase())[1] - .replace(/\\/g, "/") - .replace(".csp", ""); - ext = "csp"; } else { const match = content.match(/^ROUTINE ([^\s]+)(?:\s+\[.*Type=([a-z]{3,}))?/i); name = match[1]; @@ -53,7 +53,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile { if (!name) { return null; } - name += "." + ext; + name += ext ? "." + ext : ""; return { content,