Skip to content

Commit

Permalink
Merge pull request #168 from ty-d/CSPandOtherFiles
Browse files Browse the repository at this point in the history
Add CSP and other files to explorer
  • Loading branch information
rajrsingh authored Jul 1, 2020
2 parents be47b2f + ea9d73a commit 74cfce9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
"group": "objectscript@2"
},
{
"command": "vscode-objectscript.studio.actions",
"when": "resourceScheme == isfs && vscode-objectscript.connectActive"
},
{
"command": "vscode-objectscript.previewXml",
"when": "editorLangId =~ /^xml/",
Expand Down
13 changes: 13 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export class AtelierAPI {
return workspaceState.get(this.workspaceFolder + ":iris", false);
}

private transformNameIfCsp(filename: string): string {
// If a CSP file, change from
// \csp\user\... to
// csp/user/...
if (filename.startsWith("\\")) {
return filename.substring(1).replace(/\\/g, "/");
}
return filename;
}

public constructor(wsOrFile?: string | vscode.Uri) {
let workspaceFolderName = "";
if (wsOrFile) {
Expand Down Expand Up @@ -265,6 +275,7 @@ export class AtelierAPI {
format,
};
}
name = this.transformNameIfCsp(name);
return this.request(1, "GET", `${this.ns}/doc/${name}`, params);
}
// api v1+
Expand All @@ -274,6 +285,7 @@ export class AtelierAPI {
// v1+
public putDoc(name: string, data: { enc: boolean; content: string[] }, ignoreConflict?: boolean): Promise<any> {
const params = { ignoreConflict };
name = this.transformNameIfCsp(name);
return this.request(1, "PUT", `${this.ns}/doc/${name}`, data, params);
}
// v1+
Expand Down Expand Up @@ -315,6 +327,7 @@ export class AtelierAPI {
}
// v1+
public actionCompile(docs: string[], flags?: string, source = false): Promise<any> {
docs = docs.map((doc) => this.transformNameIfCsp(doc));
return this.request(1, "POST", `${this.ns}/action/compile`, docs, {
flags,
source,
Expand Down
43 changes: 39 additions & 4 deletions src/explorer/models/rootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import { ClassNode } from "./classesNode";
export class RootNode extends NodeBase {
public readonly contextValue: string;
private readonly _category: string;
private readonly isCsp: boolean;

public constructor(label: string, fullName: string, contextValue: string, category: string, options: NodeOptions) {
public constructor(
label: string,
fullName: string,
contextValue: string,
category: string,
options: NodeOptions,
isCsp = false
) {
super(label, fullName, options);
this.contextValue = contextValue;
this._category = category;
this.isCsp = isCsp;
}

public get category(): string {
Expand All @@ -29,7 +38,7 @@ export class RootNode extends NodeBase {
}

public async getChildren(element): Promise<NodeBase[]> {
const path = this instanceof PackageNode ? this.fullName + "/" : "";
const path = this instanceof PackageNode || this.isCsp ? this.fullName + "/" : "";
return this.getItems(path, this._category);
}

Expand All @@ -42,14 +51,20 @@ export class RootNode extends NodeBase {
spec = "*.cls";
break;
case "RTN":
spec = "*.mac,*.int";
spec = "*.mac,*.int,*.bas";
break;
case "INC":
spec = "*.inc";
break;
case "ALL":
spec = "*.cls,*.mac,*.int,*.inc";
break;
case "CSP":
spec = "*";
break;
case "OTH":
spec = "*";
break;
default:
return;
}
Expand All @@ -72,7 +87,12 @@ export class RootNode extends NodeBase {
})
.then((data) =>
data.map((el) => {
const fullName = (this instanceof PackageNode ? this.fullName + "." : "") + el.Name;
let fullName = el.Name;
if (this instanceof PackageNode) {
fullName = this.fullName + "." + el.Name;
} else if (this.isCsp) {
fullName = this.fullName + "/" + el.Name;
}
return {
...el,
fullName,
Expand All @@ -84,16 +104,31 @@ export class RootNode extends NodeBase {
public getItems(path: string, category: string): Promise<NodeBase[]> {
return this.getList(path, category, false).then((data) =>
data
.filter((el) => {
if (category === "OTH") {
return el.Type === "100";
} else if (category === "CSP") {
return el.Type === "10" || el.Type === "5";
} else {
return true;
}
})
.map((el) => {
switch (el.Type) {
case "9":
return new PackageNode(el.Name, el.fullName, category, this.options);
case "4":
case "5":
case "100":
return new ClassNode(el.Name, el.fullName, this.options);
case "0":
case "1":
case "2":
case "3":
case "11":
return new RoutineNode(el.Name, el.fullName, this.options);
case "10":
return new RootNode(el.Name, el.fullName, "dataNode:CSPApplication", this._category, this.options, true);
default:
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions src/explorer/models/workspaceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class WorkspaceNode extends NodeBase {
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.options);
children.push(node);

node = new RootNode("CSP Files", "", "dataRootNode:cspRootNode", "CSP", this.options);
children.push(node);

node = new RootNode("Other", "", "dataRootNode:otherRootNode", "OTH", this.options);
children.push(node);

return children;
}
}
13 changes: 10 additions & 3 deletions src/providers/DocumentContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
});
}
}
const isCsp = name.includes("/");
if (namespace && namespace !== "") {
uri = uri.with({
query: `ns=${namespace}`,
});
if (isCsp) {
uri = uri.with({
query: `ns=${namespace}&csp=1`,
});
} else {
uri = uri.with({
query: `ns=${namespace}`,
});
}
}
return uri;
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
if (match) {
[, name, ext = "cls"] = match;
}
} else {
} else if (fileExt.match(/(mac|int|inc)/i)) {
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
if (match) {
[, name, ext = "mac"] = match;
} else {
[name, ext = "mac"] = path.basename(document.fileName).split(".");
}
} else {
name = fileName;
}
if (!name) {
return null;
Expand Down

0 comments on commit 74cfce9

Please sign in to comment.