Skip to content

Commit 74cfce9

Browse files
authored
Merge pull request #168 from ty-d/CSPandOtherFiles
Add CSP and other files to explorer
2 parents be47b2f + ea9d73a commit 74cfce9

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive",
207207
"group": "objectscript@2"
208208
},
209+
{
210+
"command": "vscode-objectscript.studio.actions",
211+
"when": "resourceScheme == isfs && vscode-objectscript.connectActive"
212+
},
209213
{
210214
"command": "vscode-objectscript.previewXml",
211215
"when": "editorLangId =~ /^xml/",

src/api/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export class AtelierAPI {
2424
return workspaceState.get(this.workspaceFolder + ":iris", false);
2525
}
2626

27+
private transformNameIfCsp(filename: string): string {
28+
// If a CSP file, change from
29+
// \csp\user\... to
30+
// csp/user/...
31+
if (filename.startsWith("\\")) {
32+
return filename.substring(1).replace(/\\/g, "/");
33+
}
34+
return filename;
35+
}
36+
2737
public constructor(wsOrFile?: string | vscode.Uri) {
2838
let workspaceFolderName = "";
2939
if (wsOrFile) {
@@ -265,6 +275,7 @@ export class AtelierAPI {
265275
format,
266276
};
267277
}
278+
name = this.transformNameIfCsp(name);
268279
return this.request(1, "GET", `${this.ns}/doc/${name}`, params);
269280
}
270281
// api v1+
@@ -274,6 +285,7 @@ export class AtelierAPI {
274285
// v1+
275286
public putDoc(name: string, data: { enc: boolean; content: string[] }, ignoreConflict?: boolean): Promise<any> {
276287
const params = { ignoreConflict };
288+
name = this.transformNameIfCsp(name);
277289
return this.request(1, "PUT", `${this.ns}/doc/${name}`, data, params);
278290
}
279291
// v1+
@@ -315,6 +327,7 @@ export class AtelierAPI {
315327
}
316328
// v1+
317329
public actionCompile(docs: string[], flags?: string, source = false): Promise<any> {
330+
docs = docs.map((doc) => this.transformNameIfCsp(doc));
318331
return this.request(1, "POST", `${this.ns}/action/compile`, docs, {
319332
flags,
320333
source,

src/explorer/models/rootNode.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ import { ClassNode } from "./classesNode";
99
export class RootNode extends NodeBase {
1010
public readonly contextValue: string;
1111
private readonly _category: string;
12+
private readonly isCsp: boolean;
1213

13-
public constructor(label: string, fullName: string, contextValue: string, category: string, options: NodeOptions) {
14+
public constructor(
15+
label: string,
16+
fullName: string,
17+
contextValue: string,
18+
category: string,
19+
options: NodeOptions,
20+
isCsp = false
21+
) {
1422
super(label, fullName, options);
1523
this.contextValue = contextValue;
1624
this._category = category;
25+
this.isCsp = isCsp;
1726
}
1827

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

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

@@ -42,14 +51,20 @@ export class RootNode extends NodeBase {
4251
spec = "*.cls";
4352
break;
4453
case "RTN":
45-
spec = "*.mac,*.int";
54+
spec = "*.mac,*.int,*.bas";
4655
break;
4756
case "INC":
4857
spec = "*.inc";
4958
break;
5059
case "ALL":
5160
spec = "*.cls,*.mac,*.int,*.inc";
5261
break;
62+
case "CSP":
63+
spec = "*";
64+
break;
65+
case "OTH":
66+
spec = "*";
67+
break;
5368
default:
5469
return;
5570
}
@@ -72,7 +87,12 @@ export class RootNode extends NodeBase {
7287
})
7388
.then((data) =>
7489
data.map((el) => {
75-
const fullName = (this instanceof PackageNode ? this.fullName + "." : "") + el.Name;
90+
let fullName = el.Name;
91+
if (this instanceof PackageNode) {
92+
fullName = this.fullName + "." + el.Name;
93+
} else if (this.isCsp) {
94+
fullName = this.fullName + "/" + el.Name;
95+
}
7696
return {
7797
...el,
7898
fullName,
@@ -84,16 +104,31 @@ export class RootNode extends NodeBase {
84104
public getItems(path: string, category: string): Promise<NodeBase[]> {
85105
return this.getList(path, category, false).then((data) =>
86106
data
107+
.filter((el) => {
108+
if (category === "OTH") {
109+
return el.Type === "100";
110+
} else if (category === "CSP") {
111+
return el.Type === "10" || el.Type === "5";
112+
} else {
113+
return true;
114+
}
115+
})
87116
.map((el) => {
88117
switch (el.Type) {
89118
case "9":
90119
return new PackageNode(el.Name, el.fullName, category, this.options);
91120
case "4":
121+
case "5":
122+
case "100":
92123
return new ClassNode(el.Name, el.fullName, this.options);
93124
case "0":
94125
case "1":
95126
case "2":
127+
case "3":
128+
case "11":
96129
return new RoutineNode(el.Name, el.fullName, this.options);
130+
case "10":
131+
return new RootNode(el.Name, el.fullName, "dataNode:CSPApplication", this._category, this.options, true);
97132
default:
98133
return null;
99134
}

src/explorer/models/workspaceNode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export class WorkspaceNode extends NodeBase {
3535
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.options);
3636
children.push(node);
3737

38+
node = new RootNode("CSP Files", "", "dataRootNode:cspRootNode", "CSP", this.options);
39+
children.push(node);
40+
41+
node = new RootNode("Other", "", "dataRootNode:otherRootNode", "OTH", this.options);
42+
children.push(node);
43+
3844
return children;
3945
}
4046
}

src/providers/DocumentContentProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,17 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
6161
});
6262
}
6363
}
64+
const isCsp = name.includes("/");
6465
if (namespace && namespace !== "") {
65-
uri = uri.with({
66-
query: `ns=${namespace}`,
67-
});
66+
if (isCsp) {
67+
uri = uri.with({
68+
query: `ns=${namespace}&csp=1`,
69+
});
70+
} else {
71+
uri = uri.with({
72+
query: `ns=${namespace}`,
73+
});
74+
}
6875
}
6976
return uri;
7077
}

src/utils/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
5353
if (match) {
5454
[, name, ext = "cls"] = match;
5555
}
56-
} else {
56+
} else if (fileExt.match(/(mac|int|inc)/i)) {
5757
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
5858
if (match) {
5959
[, name, ext = "mac"] = match;
6060
} else {
6161
[name, ext = "mac"] = path.basename(document.fileName).split(".");
6262
}
63+
} else {
64+
name = fileName;
6365
}
6466
if (!name) {
6567
return null;

0 commit comments

Comments
 (0)