Skip to content

Commit 7249b95

Browse files
committed
multi-root for server explorer
1 parent 89a02fe commit 7249b95

16 files changed

+257
-150
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- Preview XML As UDL by command from Command Palette and from Context Menu
88
- Fixed highlighting for XData with css in style tag
99
- Show percent-member in outline
10-
- Multi-root workspace supported now, for different connections.
10+
- Multi-root workspace supported now, for different connections
11+
- Multi-root workspace also for server explorer
1112

1213
## [0.7.7]
1314

Diff for: api/index.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import * as httpModule from 'http';
22
import * as httpsModule from 'https';
33
import * as vscode from 'vscode';
4-
import { outputConsole } from '../utils';
5-
import { config } from '../extension';
4+
import { outputConsole, outputChannel } from '../utils';
5+
import { config, currentWorkspaceFolder } from '../extension';
6+
import { type } from 'os';
67

78
export class AtelierAPI {
89
private cookies: string[] = [];
10+
private _config: any;
11+
private _namespace: string;
912

10-
private get config(): any {
11-
return config().get('conn');
13+
private get ns(): string {
14+
return this._namespace || this._config.ns;
1215
}
1316

14-
private get ns(): string {
15-
return this.config.ns;
17+
constructor() {
18+
this.setConnection(currentWorkspaceFolder());
1619
}
1720

18-
constructor() {}
21+
setNamespace(namespace: string) {
22+
this._namespace = namespace;
23+
}
1924

2025
updateCookies(cookies: string[]) {
2126
cookies.forEach(cookie => {
@@ -29,8 +34,13 @@ export class AtelierAPI {
2934
});
3035
}
3136

37+
setConnection(workspaceFolderName: string) {
38+
let conn = config('conn', workspaceFolderName);
39+
this._config = conn;
40+
}
41+
3242
request(method: string, path?: string, params?: any, headers?: any, body?: any): Promise<any> {
33-
if (!config().conn.active) {
43+
if (!this._config.active) {
3444
return Promise.reject();
3545
}
3646
headers = {
@@ -60,8 +70,8 @@ export class AtelierAPI {
6070
}
6171
headers['Cache-Control'] = 'no-cache';
6272

63-
const { host, port, username, password } = this.config;
64-
const http: any = this.config.https ? httpsModule : httpModule;
73+
const { host, port, username, password } = this._config;
74+
const http: any = this._config.https ? httpsModule : httpModule;
6575
const agent = new http.Agent({ keepAlive: true, maxSockets: 10 });
6676
path = encodeURI(`/api/atelier/${path || ''}${buildParams()}`);
6777
console.log(`API request: ${method} ${path}`);

Diff for: commands/compile.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import vscode = require('vscode');
22
import fs = require('fs');
33
import { AtelierAPI } from '../api';
44
import { currentFile, CurrentFile, outputChannel } from '../utils';
5-
import { OBJECTSCRIPT_FILE_SCHEMA, documentContentProvider, config } from '../extension';
6-
7-
const api = new AtelierAPI();
5+
import { documentContentProvider, config } from '../extension';
6+
import { DocumentContentProvider } from '../providers/DocumentContentProvider';
87

98
async function compileFlags(): Promise<string> {
109
const defaultFlags = config().compileFlags;
@@ -15,6 +14,7 @@ async function compileFlags(): Promise<string> {
1514
}
1615

1716
async function importFile(file: CurrentFile, flags: string): Promise<any> {
17+
const api = new AtelierAPI();
1818
return api
1919
.putDoc(
2020
file.name,
@@ -34,12 +34,13 @@ async function importFile(file: CurrentFile, flags: string): Promise<any> {
3434

3535
function updateOthers(others: string[]) {
3636
others.forEach(item => {
37-
const uri = vscode.Uri.parse(encodeURI(`${OBJECTSCRIPT_FILE_SCHEMA}:///${item}`));
37+
const uri = DocumentContentProvider.getUri(item);
3838
documentContentProvider.update(uri);
3939
});
4040
}
4141

4242
async function loadChanges(file: CurrentFile): Promise<any> {
43+
const api = new AtelierAPI();
4344
return api.getDoc(file.name).then(data => {
4445
fs.writeFileSync(file.fileName, (data.result.content || []).join('\n'));
4546
api
@@ -50,6 +51,7 @@ async function loadChanges(file: CurrentFile): Promise<any> {
5051
}
5152

5253
async function compile(file: CurrentFile, flags: string): Promise<any> {
54+
const api = new AtelierAPI();
5355
return api
5456
.actionCompile([file.name], flags)
5557
.then(data => {
@@ -68,7 +70,7 @@ export async function importAndCompile(askFLags = false): Promise<any> {
6870
if (!file) {
6971
return;
7072
}
71-
if (!config().conn.active) {
73+
if (!config('conn').active) {
7274
return;
7375
}
7476
const defaultFlags = config().compileFlags;

Diff for: commands/export.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { ClassNode } from '../explorer/models/classesNode';
88
import { RoutineNode } from '../explorer/models/routineNode';
99
import { config } from '../extension';
1010

11-
const api = new AtelierAPI();
12-
1311
const filesFilter = (file: any) => {
1412
if (file.cat === 'CSP' || file.name.startsWith('%') || file.name.startsWith('INFORMATION.')) {
1513
return false;
@@ -30,9 +28,10 @@ const getFileName = (folder: string, name: string, split: boolean): string => {
3028
};
3129

3230
export async function exportFile(name: string, fileName: string): Promise<any> {
33-
if (!config().conn.active) {
31+
if (!config('conn').active) {
3432
return;
3533
}
34+
const api = new AtelierAPI();
3635
const log = status => outputChannel.appendLine(`export "${name}" as "${fileName}" - ${status}`);
3736
const folders = path.dirname(fileName);
3837
return mkdirSyncRecursive(folders)
@@ -65,9 +64,10 @@ export async function exportList(files: string[]): Promise<any> {
6564
}
6665

6766
export async function exportAll(): Promise<any> {
68-
if (!config().conn.active) {
67+
if (!config('conn').active) {
6968
return;
7069
}
70+
const api = new AtelierAPI();
7171
outputChannel.show(true);
7272
const { category, generated, filter } = config().get('export');
7373
const files = data => data.result.content.filter(filesFilter).map(file => file.name);
@@ -77,7 +77,7 @@ export async function exportAll(): Promise<any> {
7777
}
7878

7979
export async function exportExplorerItem(node: PackageNode | ClassNode | RoutineNode): Promise<any> {
80-
if (!config().conn.active) {
80+
if (!config('conn').active) {
8181
return;
8282
}
8383
const items = node instanceof PackageNode ? node.getClasses() : [node.fullName];

Diff for: commands/viewOthers.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,20 @@ import * as vscode from 'vscode';
22
import { OBJECTSCRIPT_FILE_SCHEMA, config } from '../extension';
33
import { AtelierAPI } from '../api';
44
import { currentFile } from '../utils';
5+
import { DocumentContentProvider } from '../providers/DocumentContentProvider';
56

67
export async function viewOthers(): Promise<void> {
78
const api = new AtelierAPI();
89
const file = currentFile();
910
if (!file) {
1011
return;
1112
}
12-
if (!config().conn.active) {
13+
if (!config('conn').active) {
1314
return;
1415
}
1516

1617
const open = item => {
17-
let uri = vscode.Uri.file(item).with({
18-
scheme: OBJECTSCRIPT_FILE_SCHEMA
19-
});
20-
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) {
21-
if (file.uri.scheme === 'file') {
22-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(file.uri);
23-
uri = uri.with({
24-
authority: workspaceFolder.name
25-
});
26-
} else {
27-
uri = uri.with({
28-
authority: file.uri.authority
29-
});
30-
}
31-
}
18+
let uri = DocumentContentProvider.getUri(item);
3219
vscode.window.showTextDocument(uri);
3320
};
3421

Diff for: commands/xml2doc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { XmlContentProvider } from '../providers/XmlContentProvider';
44

55
export async function xml2doc(context: vscode.ExtensionContext, textEditor: vscode.TextEditor): Promise<void> {
66
const xmlContentProvider: XmlContentProvider = context.workspaceState.get('xmlContentProvider');
7-
if (!config().conn.active) {
7+
if (!config('conn').active) {
88
return;
99
}
1010

Diff for: explorer/explorer.ts

+19-43
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@ import { NodeBase } from './models/nodeBase';
33
import { RootNode } from './models/rootNode';
44
import { AtelierAPI } from './../api';
55

6-
import { config } from '../extension';
6+
import { config, workspaceState } from '../extension';
7+
import { outputChannel } from '../utils';
8+
import { WorkspaceNode } from './models/workspaceNode';
79

810
export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<NodeBase> {
911
onDidChange?: vscode.Event<vscode.Uri>;
1012
private _onDidChangeTreeData: vscode.EventEmitter<NodeBase> = new vscode.EventEmitter<NodeBase>();
1113
readonly onDidChangeTreeData: vscode.Event<NodeBase> = this._onDidChangeTreeData.event;
12-
private _classesNode: RootNode;
13-
private _routinesNode: RootNode;
14-
private _api: AtelierAPI;
1514
private _showSystem = false;
1615

17-
private get _namespace(): string {
18-
return config().conn.ns;
19-
}
20-
21-
constructor() {
22-
this._api = new AtelierAPI();
23-
}
16+
constructor() {}
2417

2518
get showSystem(): boolean {
2619
return this._showSystem;
@@ -32,10 +25,7 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
3225
}
3326

3427
refresh(): void {
35-
this._api = new AtelierAPI();
3628
this._onDidChangeTreeData.fire(null);
37-
this._onDidChangeTreeData.fire(this._classesNode);
38-
this._onDidChangeTreeData.fire(this._routinesNode);
3929
}
4030

4131
getTreeItem(element: NodeBase): vscode.TreeItem {
@@ -49,37 +39,23 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
4939
return element.getChildren(element);
5040
}
5141

52-
private async getRootNodes(): Promise<RootNode[]> {
53-
const rootNodes: RootNode[] = [];
54-
let node: RootNode;
55-
let data: any;
56-
57-
data = await this.getDocNames('CLS');
58-
node = new RootNode('Classes', 'classesRootNode', this._onDidChangeTreeData, data);
59-
this._classesNode = node;
60-
rootNodes.push(node);
42+
private async getRootNodes(): Promise<NodeBase[]> {
43+
const rootNodes: NodeBase[] = [];
44+
let node: NodeBase;
6145

62-
data = await this.getDocNames('RTN');
63-
node = new RootNode('Routines', 'routinesRootNode', this._onDidChangeTreeData, data);
64-
this._routinesNode = node;
65-
rootNodes.push(node);
46+
let workspaceFolders = vscode.workspace.workspaceFolders || [];
47+
workspaceFolders.forEach(workspaceFolder => {
48+
let conn: any = config('conn', workspaceFolder.name);
49+
if (conn.active) {
50+
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, workspaceFolder.uri);
51+
rootNodes.push(node);
6652

53+
if (this.showSystem) {
54+
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, workspaceFolder.uri, true);
55+
rootNodes.push(node);
56+
}
57+
}
58+
});
6759
return rootNodes;
6860
}
69-
70-
getDocNames(category: string): Promise<any> {
71-
const excludeSystem =
72-
this._showSystem || this._namespace === '%SYS'
73-
? () => true
74-
: ({ db }) => !['IRISLIB', 'IRISSYS', 'CACHELIB', 'CACHESYS'].includes(db);
75-
76-
return this._api
77-
.getDocNames({
78-
category
79-
})
80-
.then(data => {
81-
let content = data.result.content;
82-
return content.filter(excludeSystem);
83-
});
84-
}
8561
}

Diff for: explorer/models/classesNode.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import * as vscode from 'vscode';
22
import { NodeBase } from './nodeBase';
3-
import { OBJECTSCRIPT_FILE_SCHEMA } from '../../extension';
3+
import { DocumentContentProvider } from '../../providers/DocumentContentProvider';
4+
import { outputChannel } from '../../utils';
45

56
export class ClassNode extends NodeBase {
67
public static readonly contextValue: string = 'classNode';
7-
constructor(public readonly label: string, public readonly fullName: string) {
8+
constructor(
9+
public readonly label: string,
10+
public readonly fullName: string,
11+
private _workspaceFolder: string,
12+
private _namespace: string
13+
) {
814
super(label);
915
}
1016

@@ -17,7 +23,7 @@ export class ClassNode extends NodeBase {
1723
contextValue: 'classNode',
1824
command: {
1925
command: 'vscode-objectscript.explorer.openClass',
20-
arguments: [vscode.Uri.parse(encodeURI(`${OBJECTSCRIPT_FILE_SCHEMA}:///${this.fullName}`))],
26+
arguments: [DocumentContentProvider.getUri(this.fullName, this._workspaceFolder, this._namespace)],
2127
title: 'Open class'
2228
}
2329
// iconPath: {

Diff for: explorer/models/nodeBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as vscode from "vscode";
1+
import * as vscode from 'vscode';
22

33
export class NodeBase {
44
readonly label: string;

Diff for: explorer/models/packageNode.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { ClassNode } from './classesNode';
44

55
export class PackageNode extends NodeBase {
66
public static readonly contextValue: string = 'packageNode';
7-
constructor(public readonly label: string, private readonly _items) {
7+
constructor(
8+
public readonly label: string,
9+
private readonly _items,
10+
private readonly _workspaceFolder: string,
11+
private _namespace: string
12+
) {
813
super(label);
914
}
1015

@@ -24,7 +29,9 @@ export class PackageNode extends NodeBase {
2429

2530
async getChildren(element): Promise<NodeBase[]> {
2631
return this._items.map(({ name, fullName, nodes }) =>
27-
nodes.length ? new PackageNode(name, nodes) : new ClassNode(name, fullName)
32+
nodes.length
33+
? new PackageNode(name, nodes, this._workspaceFolder, this._namespace)
34+
: new ClassNode(name, fullName, this._workspaceFolder, this._namespace)
2835
);
2936
}
3037

0 commit comments

Comments
 (0)