Skip to content

Commit 5bfde00

Browse files
committed
CSP support with server-editing, more filtering options
1 parent 92320d3 commit 5bfde00

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ export class AtelierAPI {
188188
return this.cookies;
189189
}
190190
const data = response.body;
191+
/// deconde encoded content
192+
if (data.result && data.result.enc && data.result.content) {
193+
data.result.enc = false;
194+
data.result.content = Buffer.from(data.result.content.join(""), "base64");
195+
}
191196
if (data.console) {
192197
outputConsole(data.console);
193198
}

src/extension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
179179
});
180180

181181
workspace.onDidSaveTextDocument(file => {
182-
if (!languages.includes(file.languageId)) {
183-
return;
182+
if (schemas.includes(file.uri.scheme) || languages.includes(file.languageId)) {
183+
vscode.commands.executeCommand("vscode-objectscript.compile");
184184
}
185-
vscode.commands.executeCommand("vscode-objectscript.compile");
186185
});
187186

188187
vscode.window.onDidChangeActiveTextEditor((textEditor: vscode.TextEditor) => {

src/providers/FileSystemPovider/FileSystemProvider.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as vscode from "vscode";
3+
import * as url from "url";
34
import { AtelierAPI } from "../../api";
45
import { Directory } from "./Directory";
56
import { File } from "./File";
@@ -26,17 +27,36 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
2627
public async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> {
2728
const api = new AtelierAPI(uri);
2829
const parent = await this._lookupAsDirectory(uri);
29-
const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,0)`;
30-
const folder = uri.path === "/" ? "/" : uri.path.replace(/\//g, ".") + "/";
31-
const spec = folder.slice(1) + "*.cls,*.inc,*.int,*.mac";
30+
const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)`;
31+
const { query } = url.parse(decodeURIComponent(uri.toString()), true);
32+
const type = String(query && query.type).toLowerCase() || "all";
33+
const csp = query.csp === "" || query.csp === "1";
34+
let filter = query.filter || "";
35+
if (csp) {
36+
filter = filter || "*";
37+
} else if (type === "rtn") {
38+
filter = "*.inc,*.int,*.mac";
39+
} else if (type === "cls") {
40+
filter = "*.cls";
41+
} else {
42+
filter = query.filter || "*.cls,*.inc,*.int,*.mac";
43+
}
44+
const folder = csp ? (uri.path.endsWith("/") ? uri.path : uri.path + "/") : uri.path.replace(/\//g, ".");
45+
const spec = csp ? folder + filter : folder.slice(1) + filter;
46+
const dir = "1";
47+
const orderBy = "1";
48+
const system = api.ns === "%SYS" ? "1" : "0";
49+
const flat = String(query.flat) || "0";
50+
const notStudio = "0";
51+
const generated = String(query.generated) || "0";
3252
return api
33-
.actionQuery(sql, [spec])
53+
.actionQuery(sql, [spec, dir, orderBy, system, flat, notStudio, generated])
3454
.then(data => data.result.content || [])
3555
.then(data =>
3656
data.map(item => {
3757
const name = item.Name;
3858
const fullName = folder === "" ? name : folder + "/" + name;
39-
if (item.IsDirectory.length) {
59+
if (item.Type === "10" || item.Type === "9") {
4060
parent.entries.set(name, new Directory(name, fullName));
4161
return [name, vscode.FileType.Directory];
4262
} else {
@@ -76,7 +96,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
7696
overwrite: boolean;
7797
}
7898
): void | Thenable<void> {
79-
const fileName = uri.path.slice(1).replace(/\//g, ".");
99+
const { query } = url.parse(decodeURIComponent(uri.toString()), true);
100+
const csp = query.csp === "" || query.csp === "1";
101+
const fileName = csp ? uri.path : uri.path.slice(1).replace(/\//g, ".");
80102
if (fileName.startsWith(".")) {
81103
return;
82104
}
@@ -143,10 +165,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
143165
}
144166

145167
private async _lookupAsFile(uri: vscode.Uri): Promise<File> {
146-
// if (!uri.path.match(/\.\w+$/)) {
147-
// return Promise.resolve(new Directory(uri.path))
148-
// }
149-
const fileName = uri.path.slice(1).replace(/\//g, ".");
168+
const { query } = url.parse(decodeURIComponent(uri.toString()), true);
169+
const csp = query.csp === "" || query.csp === "1";
170+
const fileName = csp ? uri.path : uri.path.slice(1).replace(/\//g, ".");
150171
if (fileName.startsWith(".")) {
151172
throw vscode.FileSystemError.FileNotFound();
152173
}
@@ -155,7 +176,16 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
155176
return api
156177
.getDoc(fileName)
157178
.then(data => data.result)
158-
.then(({ ts, content }) => new File(name, fileName, ts, content.join("\n").length, content.join("\n")))
179+
.then(
180+
({ ts, content }) =>
181+
new File(
182+
name,
183+
fileName,
184+
ts,
185+
Array.isArray(content) ? content.join("\n").length : content.length,
186+
Array.isArray(content) ? content.join("\n") : content
187+
)
188+
)
159189
.then(entry =>
160190
this._lookupParentDirectory(uri).then(parent => {
161191
parent.entries.set(name, entry);

src/utils/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs = require("fs");
22
import path = require("path");
3+
import * as url from "url";
34
import { execSync } from "child_process";
45
import * as vscode from "vscode";
56
import { config, schemas, workspaceState } from "../extension";
@@ -22,7 +23,10 @@ export interface CurrentFile {
2223

2324
export function currentFile(document?: vscode.TextDocument): CurrentFile {
2425
document = document || (vscode.window.activeTextEditor.document ? vscode.window.activeTextEditor.document : null);
25-
if (!document || !document.fileName || !document.languageId || !document.languageId.startsWith("objectscript")) {
26+
if (
27+
!schemas.includes(document.uri.scheme) &&
28+
(!document || !document.fileName || !document.languageId || !document.languageId.startsWith("objectscript"))
29+
) {
2630
return null;
2731
}
2832
const uri = document.uri;
@@ -31,20 +35,16 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
3135
const fileExt = fileName.match(/\.(\w+)$/)[1].toLowerCase();
3236
let name = "";
3337
let ext = "";
34-
if (fileExt === "cls") {
38+
const { query } = url.parse(decodeURIComponent(uri.toString()), true);
39+
const csp = query.csp === "" || query.csp === "1";
40+
if (csp) {
41+
name = fileName;
42+
} else if (fileExt === "cls") {
3543
const match = content.match(/^Class (%?\w+(?:\.\w+)+)/im);
3644
if (match) {
3745
name = match[1];
3846
ext = "cls";
3947
}
40-
} else if (fileExt === "csp") {
41-
name =
42-
config().conn.label.toLowerCase() +
43-
fileName
44-
.split(config().conn.label.toLowerCase())[1]
45-
.replace(/\\/g, "/")
46-
.replace(".csp", "");
47-
ext = "csp";
4848
} else {
4949
const match = content.match(/^ROUTINE ([^\s]+)(?:\s+\[.*Type=([a-z]{3,}))?/i);
5050
name = match[1];
@@ -53,7 +53,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
5353
if (!name) {
5454
return null;
5555
}
56-
name += "." + ext;
56+
name += ext ? "." + ext : "";
5757

5858
return {
5959
content,

0 commit comments

Comments
 (0)