Skip to content

Commit 80cb7ac

Browse files
Merge pull request #238 from gjsjohnmurray/fix-237
fix #237 Don't open wrong local document from ObjectScript Explorer
2 parents 20b1f0b + a1e6555 commit 80cb7ac

File tree

11 files changed

+115
-33
lines changed

11 files changed

+115
-33
lines changed

src/commands/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { DocumentContentProvider } from "../providers/DocumentContentProvider";
1717
import { currentFile, CurrentFile, outputChannel } from "../utils";
1818
import { RootNode } from "../explorer/models/rootNode";
1919
import { PackageNode } from "../explorer/models/packageNode";
20-
import { ClassNode } from "../explorer/models/classesNode";
20+
import { ClassNode } from "../explorer/models/classNode";
2121
import { RoutineNode } from "../explorer/models/routineNode";
2222

2323
async function compileFlags(): Promise<string> {

src/commands/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22

33
import { AtelierAPI } from "../api";
4-
import { ClassNode } from "../explorer/models/classesNode";
4+
import { ClassNode } from "../explorer/models/classNode";
55
import { PackageNode } from "../explorer/models/packageNode";
66
import { RootNode } from "../explorer/models/rootNode";
77
import { RoutineNode } from "../explorer/models/routineNode";

src/commands/export.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ export const getFileName = (folder: string, name: string, split: boolean, addCat
4747
return [folder, cat, name].filter(notNull).join(path.sep);
4848
};
4949

50+
export const getFolderName = (folder: string, name: string, split: boolean, cat: string = null): string => {
51+
const folderNameArray: string[] = name.split(".");
52+
if (split) {
53+
return [folder, cat, ...folderNameArray].filter(notNull).join(path.sep);
54+
}
55+
return [folder, cat, name].filter(notNull).join(path.sep);
56+
};
57+
5058
export async function exportFile(
5159
workspaceFolder: string,
5260
namespace: string,
@@ -186,13 +194,15 @@ export async function exportAll(workspaceFolder?: string): Promise<any> {
186194
}
187195

188196
export async function exportExplorerItem(nodes: NodeBase[]): Promise<any> {
189-
const origNamespace = config("conn").ns;
190197
const node = nodes[0];
198+
const origNamespace = config("conn", node.workspaceFolder).ns;
191199
if (origNamespace !== node.namespace) {
192200
const answer = await vscode.window.showWarningMessage(
193201
`
194-
You are about to export items from another namespace.
195-
Edits to these files in your local workspace will be compiled in the primary namespace of your workspace root, not the namespace from which you originally exported them.
202+
You are about to export from namespace ${node.namespace}.
203+
204+
Future edits to the file(s) in your local workspace will be saved and compiled in the primary namespace of your workspace root, ${origNamespace}, not the namespace from which you originally exported.
205+
196206
Would you like to continue?`,
197207
{
198208
modal: true,

src/commands/studio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AtelierAPI } from "../api";
33
import { config, FILESYSTEM_SCHEMA } from "../extension";
44
import { outputChannel, outputConsole, currentFile } from "../utils";
55
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
6-
import { ClassNode } from "../explorer/models/classesNode";
6+
import { ClassNode } from "../explorer/models/classNode";
77
import { PackageNode } from "../explorer/models/packageNode";
88
import { RoutineNode } from "../explorer/models/routineNode";
99
import { NodeBase } from "../explorer/models/nodeBase";

src/explorer/models/classesNode.ts renamed to src/explorer/models/classNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ export class ClassNode extends NodeBase {
1010

1111
public getTreeItem(): vscode.TreeItem {
1212
const displayName: string = this.label;
13+
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
14+
const isLocalFile = itemUri.scheme === "file";
1315

1416
return {
1517
collapsibleState: vscode.TreeItemCollapsibleState.None,
1618
command: {
17-
arguments: [DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace)],
19+
arguments: [itemUri],
1820
command: "vscode-objectscript.explorer.openClass",
1921
title: "Open class",
2022
},
23+
resourceUri: isLocalFile ? itemUri : undefined,
2124
contextValue: "dataNode:classNode",
2225
label: `${displayName}`,
23-
// iconPath: {
24-
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'class.svg'),
25-
// dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'class.svg')
26-
// }
26+
tooltip: isLocalFile ? undefined : this.fullName,
2727
};
2828
}
2929
}

src/explorer/models/cspFileNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ export class CSPFileNode extends NodeBase {
1010

1111
public getTreeItem(): vscode.TreeItem {
1212
const displayName: string = this.label;
13+
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
14+
const isLocalFile = itemUri.scheme === "file";
1315

1416
return {
1517
collapsibleState: vscode.TreeItemCollapsibleState.None,
1618
command: {
17-
arguments: [DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace)],
19+
arguments: [itemUri],
1820
command: "vscode-objectscript.explorer.openCSPFile",
1921
title: "Open File",
2022
},
23+
resourceUri: isLocalFile ? itemUri : undefined,
2124
contextValue: CSPFileNode.contextValue,
2225
label: `${displayName}`,
26+
tooltip: isLocalFile ? undefined : this.fullName,
2327
};
2428
}
2529
}

src/explorer/models/packageNode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import { RootNode } from "./rootNode";
33
import { NodeOptions } from "./nodeBase";
4+
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
45

56
export class PackageNode extends RootNode {
67
public constructor(label: string, fullName: string, category: string, options: NodeOptions) {
@@ -9,15 +10,16 @@ export class PackageNode extends RootNode {
910

1011
public getTreeItem(): vscode.TreeItem {
1112
const displayName: string = this.label;
13+
const localFolderPath = DocumentContentProvider.getAsFolder(this.fullName, this.workspaceFolder, "cls");
14+
const localUri = localFolderPath ? vscode.Uri.file(localFolderPath) : undefined;
1215

1316
return {
1417
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
18+
resourceUri: !this.extraNode ? localUri : undefined,
1519
contextValue: this.contextValue,
1620
label: `${displayName}`,
17-
// iconPath: {
18-
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'package.svg'),
19-
// dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'package.svg')
20-
// }
21+
tooltip: this.fullName,
22+
//iconPath: new vscode.ThemeIcon("package"),
2123
};
2224
}
2325

src/explorer/models/rootNode.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,39 @@ import { NodeBase, NodeOptions } from "./nodeBase";
44
import { PackageNode } from "./packageNode";
55
import { RoutineNode } from "./routineNode";
66
import { AtelierAPI } from "../../api";
7-
import { ClassNode } from "./classesNode";
7+
import { ClassNode } from "./classNode";
88
import { CSPFileNode } from "./cspFileNode";
99
import { StudioOpenDialog } from "../../queries";
1010

11+
type IconPath =
12+
| string
13+
| vscode.Uri
14+
| {
15+
light: string | vscode.Uri;
16+
dark: string | vscode.Uri;
17+
}
18+
| vscode.ThemeIcon;
19+
1120
export class RootNode extends NodeBase {
1221
public readonly contextValue: string;
1322
private readonly _category: string;
1423
private readonly isCsp: boolean;
24+
private readonly iconPath: IconPath;
1525

1626
public constructor(
1727
label: string,
1828
fullName: string,
1929
contextValue: string,
2030
category: string,
2131
options: NodeOptions,
22-
isCsp = false
32+
isCsp = false,
33+
iconPath?: IconPath
2334
) {
2435
super(label, fullName, options);
2536
this.contextValue = contextValue;
2637
this._category = category;
2738
this.isCsp = isCsp;
39+
this.iconPath = iconPath;
2840
}
2941

3042
public get category(): string {
@@ -36,6 +48,8 @@ export class RootNode extends NodeBase {
3648
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
3749
contextValue: this.contextValue,
3850
label: this.label,
51+
tooltip: this.isCsp ? this.fullName : undefined,
52+
iconPath: this.iconPath,
3953
};
4054
}
4155

src/explorer/models/routineNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ export class RoutineNode extends NodeBase {
1010

1111
public getTreeItem(): vscode.TreeItem {
1212
const displayName: string = this.label;
13+
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
14+
const isLocalFile = itemUri.scheme === "file";
1315

1416
return {
1517
collapsibleState: vscode.TreeItemCollapsibleState.None,
1618
command: {
17-
arguments: [DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace)],
19+
arguments: [itemUri],
1820
command: "vscode-objectscript.explorer.openRoutine",
1921
title: "Open routine",
2022
},
23+
resourceUri: isLocalFile ? itemUri : undefined,
2124
contextValue: "dataNode:routineNode",
2225
label: `${displayName}`,
23-
// iconPath: {
24-
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'routine.svg'),
25-
// dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'routine.svg')
26-
// }
26+
tooltip: isLocalFile ? undefined : this.fullName,
2727
};
2828
}
2929
}

src/explorer/models/workspaceNode.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,59 @@ export class WorkspaceNode extends NodeBase {
3333
const children = [];
3434
let node: RootNode;
3535

36-
node = new RootNode("Classes", "", "dataRootNode:classesRootNode", "CLS", this.options);
36+
node = new RootNode(
37+
"Classes",
38+
"",
39+
"dataRootNode:classesRootNode",
40+
"CLS",
41+
this.options,
42+
false
43+
//new vscode.ThemeIcon("symbol-class")
44+
);
3745
children.push(node);
3846

39-
node = new RootNode("Routines", "", "dataRootNode:routinesRootNode", "RTN", this.options);
47+
node = new RootNode(
48+
"Routines",
49+
"",
50+
"dataRootNode:routinesRootNode",
51+
"RTN",
52+
this.options,
53+
false
54+
//new vscode.ThemeIcon("note")
55+
);
4056
children.push(node);
4157

42-
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.options);
58+
node = new RootNode(
59+
"Includes",
60+
"",
61+
"dataRootNode:routinesRootNode",
62+
"INC",
63+
this.options,
64+
false
65+
//new vscode.ThemeIcon("file-symlink-file")
66+
);
4367
children.push(node);
4468

45-
node = new RootNode("CSP Files", "", "dataRootNode:cspRootNode", "CSP", this.options);
69+
node = new RootNode(
70+
"CSP Files",
71+
"",
72+
"dataRootNode:cspRootNode",
73+
"CSP",
74+
this.options,
75+
false
76+
//new vscode.ThemeIcon("symbol-file")
77+
);
4678
children.push(node);
4779

48-
node = new RootNode("Other", "", "dataRootNode:otherRootNode", "OTH", this.options);
80+
node = new RootNode(
81+
"Other",
82+
"",
83+
"dataRootNode:otherRootNode",
84+
"OTH",
85+
this.options,
86+
false
87+
//new vscode.ThemeIcon("symbol-misc")
88+
);
4989
children.push(node);
5090

5191
return children;

0 commit comments

Comments
 (0)