Skip to content

Commit

Permalink
multi-root for server explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Jan 25, 2019
1 parent 89a02fe commit 7249b95
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 150 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
- Preview XML As UDL by command from Command Palette and from Context Menu
- Fixed highlighting for XData with css in style tag
- Show percent-member in outline
- Multi-root workspace supported now, for different connections.
- Multi-root workspace supported now, for different connections
- Multi-root workspace also for server explorer

## [0.7.7]

Expand Down
30 changes: 20 additions & 10 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import * as httpModule from 'http';
import * as httpsModule from 'https';
import * as vscode from 'vscode';
import { outputConsole } from '../utils';
import { config } from '../extension';
import { outputConsole, outputChannel } from '../utils';
import { config, currentWorkspaceFolder } from '../extension';
import { type } from 'os';

export class AtelierAPI {
private cookies: string[] = [];
private _config: any;
private _namespace: string;

private get config(): any {
return config().get('conn');
private get ns(): string {
return this._namespace || this._config.ns;
}

private get ns(): string {
return this.config.ns;
constructor() {
this.setConnection(currentWorkspaceFolder());
}

constructor() {}
setNamespace(namespace: string) {
this._namespace = namespace;
}

updateCookies(cookies: string[]) {
cookies.forEach(cookie => {
Expand All @@ -29,8 +34,13 @@ export class AtelierAPI {
});
}

setConnection(workspaceFolderName: string) {
let conn = config('conn', workspaceFolderName);
this._config = conn;
}

request(method: string, path?: string, params?: any, headers?: any, body?: any): Promise<any> {
if (!config().conn.active) {
if (!this._config.active) {
return Promise.reject();
}
headers = {
Expand Down Expand Up @@ -60,8 +70,8 @@ export class AtelierAPI {
}
headers['Cache-Control'] = 'no-cache';

const { host, port, username, password } = this.config;
const http: any = this.config.https ? httpsModule : httpModule;
const { host, port, username, password } = this._config;
const http: any = this._config.https ? httpsModule : httpModule;
const agent = new http.Agent({ keepAlive: true, maxSockets: 10 });
path = encodeURI(`/api/atelier/${path || ''}${buildParams()}`);
console.log(`API request: ${method} ${path}`);
Expand Down
12 changes: 7 additions & 5 deletions commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import vscode = require('vscode');
import fs = require('fs');
import { AtelierAPI } from '../api';
import { currentFile, CurrentFile, outputChannel } from '../utils';
import { OBJECTSCRIPT_FILE_SCHEMA, documentContentProvider, config } from '../extension';

const api = new AtelierAPI();
import { documentContentProvider, config } from '../extension';
import { DocumentContentProvider } from '../providers/DocumentContentProvider';

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

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

function updateOthers(others: string[]) {
others.forEach(item => {
const uri = vscode.Uri.parse(encodeURI(`${OBJECTSCRIPT_FILE_SCHEMA}:///${item}`));
const uri = DocumentContentProvider.getUri(item);
documentContentProvider.update(uri);
});
}

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

async function compile(file: CurrentFile, flags: string): Promise<any> {
const api = new AtelierAPI();
return api
.actionCompile([file.name], flags)
.then(data => {
Expand All @@ -68,7 +70,7 @@ export async function importAndCompile(askFLags = false): Promise<any> {
if (!file) {
return;
}
if (!config().conn.active) {
if (!config('conn').active) {
return;
}
const defaultFlags = config().compileFlags;
Expand Down
10 changes: 5 additions & 5 deletions commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { ClassNode } from '../explorer/models/classesNode';
import { RoutineNode } from '../explorer/models/routineNode';
import { config } from '../extension';

const api = new AtelierAPI();

const filesFilter = (file: any) => {
if (file.cat === 'CSP' || file.name.startsWith('%') || file.name.startsWith('INFORMATION.')) {
return false;
Expand All @@ -30,9 +28,10 @@ const getFileName = (folder: string, name: string, split: boolean): string => {
};

export async function exportFile(name: string, fileName: string): Promise<any> {
if (!config().conn.active) {
if (!config('conn').active) {
return;
}
const api = new AtelierAPI();
const log = status => outputChannel.appendLine(`export "${name}" as "${fileName}" - ${status}`);
const folders = path.dirname(fileName);
return mkdirSyncRecursive(folders)
Expand Down Expand Up @@ -65,9 +64,10 @@ export async function exportList(files: string[]): Promise<any> {
}

export async function exportAll(): Promise<any> {
if (!config().conn.active) {
if (!config('conn').active) {
return;
}
const api = new AtelierAPI();
outputChannel.show(true);
const { category, generated, filter } = config().get('export');
const files = data => data.result.content.filter(filesFilter).map(file => file.name);
Expand All @@ -77,7 +77,7 @@ export async function exportAll(): Promise<any> {
}

export async function exportExplorerItem(node: PackageNode | ClassNode | RoutineNode): Promise<any> {
if (!config().conn.active) {
if (!config('conn').active) {
return;
}
const items = node instanceof PackageNode ? node.getClasses() : [node.fullName];
Expand Down
19 changes: 3 additions & 16 deletions commands/viewOthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,20 @@ import * as vscode from 'vscode';
import { OBJECTSCRIPT_FILE_SCHEMA, config } from '../extension';
import { AtelierAPI } from '../api';
import { currentFile } from '../utils';
import { DocumentContentProvider } from '../providers/DocumentContentProvider';

export async function viewOthers(): Promise<void> {
const api = new AtelierAPI();
const file = currentFile();
if (!file) {
return;
}
if (!config().conn.active) {
if (!config('conn').active) {
return;
}

const open = item => {
let uri = vscode.Uri.file(item).with({
scheme: OBJECTSCRIPT_FILE_SCHEMA
});
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) {
if (file.uri.scheme === 'file') {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(file.uri);
uri = uri.with({
authority: workspaceFolder.name
});
} else {
uri = uri.with({
authority: file.uri.authority
});
}
}
let uri = DocumentContentProvider.getUri(item);
vscode.window.showTextDocument(uri);
};

Expand Down
2 changes: 1 addition & 1 deletion commands/xml2doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { XmlContentProvider } from '../providers/XmlContentProvider';

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

Expand Down
62 changes: 19 additions & 43 deletions explorer/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ import { NodeBase } from './models/nodeBase';
import { RootNode } from './models/rootNode';
import { AtelierAPI } from './../api';

import { config } from '../extension';
import { config, workspaceState } from '../extension';
import { outputChannel } from '../utils';
import { WorkspaceNode } from './models/workspaceNode';

export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<NodeBase> {
onDidChange?: vscode.Event<vscode.Uri>;
private _onDidChangeTreeData: vscode.EventEmitter<NodeBase> = new vscode.EventEmitter<NodeBase>();
readonly onDidChangeTreeData: vscode.Event<NodeBase> = this._onDidChangeTreeData.event;
private _classesNode: RootNode;
private _routinesNode: RootNode;
private _api: AtelierAPI;
private _showSystem = false;

private get _namespace(): string {
return config().conn.ns;
}

constructor() {
this._api = new AtelierAPI();
}
constructor() {}

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

refresh(): void {
this._api = new AtelierAPI();
this._onDidChangeTreeData.fire(null);
this._onDidChangeTreeData.fire(this._classesNode);
this._onDidChangeTreeData.fire(this._routinesNode);
}

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

private async getRootNodes(): Promise<RootNode[]> {
const rootNodes: RootNode[] = [];
let node: RootNode;
let data: any;

data = await this.getDocNames('CLS');
node = new RootNode('Classes', 'classesRootNode', this._onDidChangeTreeData, data);
this._classesNode = node;
rootNodes.push(node);
private async getRootNodes(): Promise<NodeBase[]> {
const rootNodes: NodeBase[] = [];
let node: NodeBase;

data = await this.getDocNames('RTN');
node = new RootNode('Routines', 'routinesRootNode', this._onDidChangeTreeData, data);
this._routinesNode = node;
rootNodes.push(node);
let workspaceFolders = vscode.workspace.workspaceFolders || [];
workspaceFolders.forEach(workspaceFolder => {
let conn: any = config('conn', workspaceFolder.name);
if (conn.active) {
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, workspaceFolder.uri);
rootNodes.push(node);

if (this.showSystem) {
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, workspaceFolder.uri, true);
rootNodes.push(node);
}
}
});
return rootNodes;
}

getDocNames(category: string): Promise<any> {
const excludeSystem =
this._showSystem || this._namespace === '%SYS'
? () => true
: ({ db }) => !['IRISLIB', 'IRISSYS', 'CACHELIB', 'CACHESYS'].includes(db);

return this._api
.getDocNames({
category
})
.then(data => {
let content = data.result.content;
return content.filter(excludeSystem);
});
}
}
12 changes: 9 additions & 3 deletions explorer/models/classesNode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as vscode from 'vscode';
import { NodeBase } from './nodeBase';
import { OBJECTSCRIPT_FILE_SCHEMA } from '../../extension';
import { DocumentContentProvider } from '../../providers/DocumentContentProvider';
import { outputChannel } from '../../utils';

export class ClassNode extends NodeBase {
public static readonly contextValue: string = 'classNode';
constructor(public readonly label: string, public readonly fullName: string) {
constructor(
public readonly label: string,
public readonly fullName: string,
private _workspaceFolder: string,
private _namespace: string
) {
super(label);
}

Expand All @@ -17,7 +23,7 @@ export class ClassNode extends NodeBase {
contextValue: 'classNode',
command: {
command: 'vscode-objectscript.explorer.openClass',
arguments: [vscode.Uri.parse(encodeURI(`${OBJECTSCRIPT_FILE_SCHEMA}:///${this.fullName}`))],
arguments: [DocumentContentProvider.getUri(this.fullName, this._workspaceFolder, this._namespace)],
title: 'Open class'
}
// iconPath: {
Expand Down
2 changes: 1 addition & 1 deletion explorer/models/nodeBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from "vscode";
import * as vscode from 'vscode';

export class NodeBase {
readonly label: string;
Expand Down
11 changes: 9 additions & 2 deletions explorer/models/packageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { ClassNode } from './classesNode';

export class PackageNode extends NodeBase {
public static readonly contextValue: string = 'packageNode';
constructor(public readonly label: string, private readonly _items) {
constructor(
public readonly label: string,
private readonly _items,
private readonly _workspaceFolder: string,
private _namespace: string
) {
super(label);
}

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

async getChildren(element): Promise<NodeBase[]> {
return this._items.map(({ name, fullName, nodes }) =>
nodes.length ? new PackageNode(name, nodes) : new ClassNode(name, fullName)
nodes.length
? new PackageNode(name, nodes, this._workspaceFolder, this._namespace)
: new ClassNode(name, fullName, this._workspaceFolder, this._namespace)
);
}

Expand Down
Loading

0 comments on commit 7249b95

Please sign in to comment.