Skip to content

Commit 39fd781

Browse files
committed
support for custom address in isfs
1 parent d8a2547 commit 39fd781

File tree

11 files changed

+1734
-444
lines changed

11 files changed

+1734
-444
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@
479479
},
480480
"objectscript.conn.docker-compose": {
481481
"description": "Connect to server running in docker-compose",
482-
"type": "object"
482+
"type": "object",
483+
"scope": "resource"
483484
},
484485
"objectscript.conn.docker-compose.service": {
485486
"description": "Name of service in docker-compose",

src/api/index.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ export class AtelierAPI {
2020
return this.namespace || this.config.ns;
2121
}
2222

23-
private get apiVersion(): number {
24-
return workspaceState.get(this.workspaceFolder + ":apiVersion", DEFAULT_API_VERSION);
25-
}
26-
27-
private get port(): number {
28-
return workspaceState.get(this.workspaceFolder + ":port", this.config.port);
29-
}
30-
31-
private get password(): string {
32-
return workspaceState.get(this.workspaceFolder + ":password", this.config.password);
33-
}
34-
3523
private get iris(): boolean {
3624
return workspaceState.get(this.workspaceFolder + ":iris", false);
3725
}
@@ -74,14 +62,12 @@ export class AtelierAPI {
7462
}
7563

7664
public xdebugUrl(): string {
77-
const { host, username, https } = this.config;
78-
const port = this.port;
79-
const password = this.password;
65+
const { host, username, https, port, password, apiVersion } = this.config;
8066
const proto = https ? "wss" : "ws";
8167
const auth = this.iris
8268
? `IRISUsername=${username}&IRISPassword=${password}`
8369
: `CacheUserName=${username}&CachePassword=${password}`;
84-
return `${proto}://${host}:${port}/api/atelier/v${this.apiVersion}/%25SYS/debug?${auth}`;
70+
return `${proto}://${host}:${port}/api/atelier/v${apiVersion}/%25SYS/debug?${auth}`;
8571
}
8672

8773
public updateCookies(newCookies: string[]): Promise<any> {
@@ -102,8 +88,11 @@ export class AtelierAPI {
10288
this.workspaceFolder = workspaceFolderName;
10389
const conn = config("conn", workspaceFolderName);
10490
this.config = conn;
105-
const { name, host } = this.config;
106-
const port = this.port;
91+
this.config.port = workspaceState.get(this.workspaceFolder + ":port", this.config.port);
92+
this.config.password = workspaceState.get(this.workspaceFolder + ":password", this.config.password);
93+
this.config.apiVersion = workspaceState.get(this.workspaceFolder + ":apiVersion", DEFAULT_API_VERSION);
94+
95+
const { name, host, port } = this.config;
10796
this.cache = new Cache(extensionContext, `API:${name}:${host}:${port}`);
10897
}
10998

@@ -115,14 +104,15 @@ export class AtelierAPI {
115104
params?: any,
116105
headers?: any
117106
): Promise<any> {
118-
if (minVersion > this.apiVersion) {
119-
return Promise.reject(`${path} not supported by API version ${this.apiVersion}`);
107+
const { active, apiVersion, host, username, https, port, password } = this.config;
108+
if (!active) {
109+
return Promise.reject();
120110
}
121-
if (minVersion && minVersion > 0) {
122-
path = `v${this.apiVersion}/${path}`;
111+
if (minVersion > apiVersion) {
112+
return Promise.reject(`${path} not supported by API version ${apiVersion}`);
123113
}
124-
if (!this.config.active) {
125-
return Promise.reject();
114+
if (minVersion && minVersion > 0) {
115+
path = `v${apiVersion}/${path}`;
126116
}
127117
headers = {
128118
...headers,
@@ -149,9 +139,6 @@ export class AtelierAPI {
149139
}
150140
headers["Cache-Control"] = "no-cache";
151141

152-
const { host, username, https } = this.config;
153-
const port = this.port;
154-
const password = this.password;
155142
const proto = this.config.https ? "https" : "http";
156143
const http: any = this.config.https ? httpsModule : httpModule;
157144
const agent = new http.Agent({

src/commands/compile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ async function compile(docs: CurrentFile[], flags?: string): Promise<any> {
7777
},
7878
() =>
7979
api
80-
.actionCompile(docs.map(el => el.name), flags)
80+
.actionCompile(
81+
docs.map(el => el.name),
82+
flags
83+
)
8184
.then(data => {
8285
const info = docs.length > 1 ? "" : `${docs[0].name}: `;
8386
if (data.status && data.status.errors && data.status.errors.length) {

src/debug/debugSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
8585
private _evalResultProperties = new Map<number, xdebug.EvalResultProperty>();
8686

8787
public constructor() {
88-
super("mock-debug.txt");
88+
super();
8989

9090
const api = new AtelierAPI();
9191
this._namespace = api.ns;

src/extension.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml";
99
export const FILESYSTEM_SCHEMA = "isfs";
1010
export const schemas = [OBJECTSCRIPT_FILE_SCHEMA, OBJECTSCRIPTXML_FILE_SCHEMA, FILESYSTEM_SCHEMA];
1111

12+
import * as url from "url";
1213
import WebSocket = require("ws");
1314
import {
1415
importAndCompile,
@@ -76,6 +77,25 @@ export const config = (setting?: string, workspaceFolderName?: string): any => {
7677

7778
if (["conn", "export"].includes(setting)) {
7879
if (workspaceFolderName && workspaceFolderName !== "") {
80+
if (workspaceFolderName.match(/.+:\d+$/)) {
81+
const { port, hostname: host, auth, query } = url.parse("http://" + workspaceFolderName, true);
82+
const { ns = "USER", https = false } = query;
83+
const [username, password] = (auth || "_SYSTEM:SYS").split(":");
84+
if (setting == "conn") {
85+
return {
86+
active: true,
87+
https,
88+
ns,
89+
host,
90+
port,
91+
username,
92+
password,
93+
};
94+
} else if (setting == "export") {
95+
return {};
96+
}
97+
}
98+
7999
const workspaceFolder = vscode.workspace.workspaceFolders.find(
80100
el => el.name.toLowerCase() === workspaceFolderName.toLowerCase()
81101
);
@@ -101,6 +121,8 @@ export function getXmlUri(uri: vscode.Uri): vscode.Uri {
101121
}
102122
let reporter: TelemetryReporter;
103123

124+
let connectionSocket: WebSocket;
125+
104126
export const checkConnection = (clearCookies = false): void => {
105127
const conn = config("conn");
106128
let connInfo = `${conn.host}:${conn.port}[${conn.ns}]`;
@@ -112,7 +134,7 @@ export const checkConnection = (clearCookies = false): void => {
112134
return;
113135
}
114136
workspaceState.update(currentWorkspaceFolder() + ":port", undefined);
115-
const { port: dockerPort, docker: withDocker } = portFromDockerCompose(config("conn.docker-compose"), conn.port);
137+
const { port: dockerPort, docker: withDocker } = portFromDockerCompose();
116138
workspaceState.update(currentWorkspaceFolder() + ":docker", withDocker);
117139
if (withDocker) {
118140
terminalWithDocker();
@@ -126,6 +148,9 @@ export const checkConnection = (clearCookies = false): void => {
126148
if (clearCookies) {
127149
api.clearCookies();
128150
}
151+
if (connectionSocket && connectionSocket.url == api.xdebugUrl() && connectionSocket.OPEN) {
152+
return;
153+
}
129154
api
130155
.serverInfo()
131156
.then(info => {
@@ -135,11 +160,11 @@ export const checkConnection = (clearCookies = false): void => {
135160
healthshare: hasHS ? "yes" : "no",
136161
});
137162
/// Use xdebug's websocket, to catch when server disconnected
138-
const socket = new WebSocket(api.xdebugUrl());
139-
socket.onopen = () => {
163+
connectionSocket = new WebSocket(api.xdebugUrl());
164+
connectionSocket.onopen = () => {
140165
panel.text = `${connInfo} - Connected`;
141166
};
142-
socket.onclose = event => {
167+
connectionSocket.onclose = event => {
143168
panel.text = `${connInfo} - Disconnected`;
144169
};
145170
})

src/providers/DocumentContentProvider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
3131
const wFolderUri = workspaceFolderUri(workspaceFolder);
3232
let uri: vscode.Uri;
3333
if (wFolderUri.scheme === FILESYSTEM_SCHEMA) {
34+
const fileExt = name.split(".").pop();
35+
const fileName = name
36+
.split(".")
37+
.slice(0, -1)
38+
.join(fileExt.match(/cls/i) ? "/" : ".");
39+
name = fileName + "." + fileExt;
3440
uri = wFolderUri.with({
3541
path: `/${name}`,
3642
});
43+
vfs = true;
3744
} else {
3845
const found = this.getAsFile(name, workspaceFolder);
3946
if (found) {

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ObjectScriptDiagnosticProvider {
4747
}
4848

4949
const memberMatch = text.match(
50-
/^(Class|Property|Relationship|Index|ClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s(\b[^ (]+\b)/i
50+
/^(Class|Property|Relationship|Index|(?:(?:Client)?(?:Class)?Method)|ClientClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s(\b[^ (]+\b)/i
5151
);
5252
if (memberMatch) {
5353
const [fullMatch, type, name] = memberMatch;
@@ -222,9 +222,11 @@ export class ObjectScriptDiagnosticProvider {
222222
const [, found] = functionsMatch;
223223
const pos = functionsMatch.index;
224224
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + found.length));
225-
const systemFunction = [...systemFunctions, ...systemVariables, ...structuredSystemVariables].find(el =>
226-
el.alias.includes(found.toUpperCase())
227-
);
225+
const systemFunction: CompletionModel = [
226+
...systemFunctions,
227+
...systemVariables,
228+
...structuredSystemVariables,
229+
].find(el => el.alias.includes(found.toUpperCase()));
228230
if (!systemFunction) {
229231
result.push({
230232
range,

src/providers/WorkspaceSymbolProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
1111
if (query.length < 3) {
1212
return null;
1313
}
14-
return Promise.all([this.byClasses(query), this.byRoutines(query), this.byMethods(query)]).then(
15-
([classes, routines, methods]) => [...classes, ...routines, ...methods]
16-
);
14+
return Promise.all([
15+
this.byClasses(query),
16+
this.byRoutines(query),
17+
this.byMethods(query),
18+
]).then(([classes, routines, methods]) => [...classes, ...routines, ...methods]);
1719
}
1820

1921
public async byClasses(query: string): Promise<vscode.SymbolInformation[]> {

src/providers/completion/model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface CompletionModel {
2+
label: string;
3+
alias: string[];
4+
deprecated?: boolean;
5+
documentation: string[];
6+
link?: string;
7+
code?: string;
8+
}

src/utils/index.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
3232
const uri = document.uri;
3333
const fileName = document.fileName;
3434
const content = document.getText();
35-
const fileExt = fileName.match(/\.(\w+)$/)[1].toLowerCase();
35+
const fileExt = fileName
36+
.split(".")
37+
.pop()
38+
.toLowerCase();
3639
let name = "";
3740
let ext = "";
3841
const { query } = url.parse(decodeURIComponent(uri.toString()), true);
@@ -42,13 +45,11 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
4245
} else if (fileExt === "cls") {
4346
const match = content.match(/^Class (%?\w+(?:\.\w+)+)/im);
4447
if (match) {
45-
name = match[1];
46-
ext = "cls";
48+
[, name, ext = "cls"] = match;
4749
}
4850
} else {
4951
const match = content.match(/^ROUTINE ([^\s]+)(?:\s+\[.*Type=([a-z]{3,}))?/i);
50-
name = match[1];
51-
ext = match[2] || "mac";
52+
[, name, ext = "mac"] = match;
5253
}
5354
if (!name) {
5455
return null;
@@ -107,8 +108,9 @@ export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
107108
}
108109

109110
export function workspaceFolderUri(workspaceFolder: string = currentWorkspaceFolder()): vscode.Uri {
110-
return vscode.workspace.workspaceFolders.find(
111-
(el): boolean => el.name.toLowerCase() === workspaceFolder.toLowerCase()
111+
return (
112+
vscode.workspace.workspaceFolders.find((el): boolean => el.name.toLowerCase() === workspaceFolder.toLowerCase()) ||
113+
vscode.workspace.workspaceFolders.find((el): boolean => el.uri.authority == workspaceFolder)
112114
).uri;
113115
}
114116

@@ -123,12 +125,10 @@ export function notNull(el: any): boolean {
123125
return el !== null;
124126
}
125127

126-
export function portFromDockerCompose(options, defaultPort: number): { port: number; docker: boolean } {
128+
export function portFromDockerCompose(): { port: number; docker: boolean } {
129+
const { "docker-compose": dockerCompose, port: defaultPort } = config("conn");
127130
const result = { port: defaultPort, docker: false };
128-
if (!options) {
129-
return result;
130-
}
131-
const { file = "docker-compose.yml", service, internalPort = 52773 } = options;
131+
const { service, file = "docker-compose.yml", internalPort = 52773 } = dockerCompose;
132132
if (!internalPort || !file || !service || service === "") {
133133
return result;
134134
}
@@ -155,13 +155,16 @@ export function portFromDockerCompose(options, defaultPort: number): { port: num
155155
}
156156

157157
export function terminalWithDocker() {
158-
const { ns } = config("conn");
159-
const { service } = config("conn.docker-compose");
158+
const { ns, "docker-compose": dockerCompose } = config("conn");
159+
const { service, file = "docker-compose.yml" } = dockerCompose;
160+
const workspace = currentWorkspaceFolder();
160161

161-
const terminalName = `ObjectScript:${service}`;
162+
const terminalName = `ObjectScript:${workspace}`;
162163
let terminal = vscode.window.terminals.find(el => el.name === terminalName);
163164
if (!terminal) {
164165
terminal = vscode.window.createTerminal(terminalName, "docker-compose", [
166+
"-f",
167+
file,
165168
"exec",
166169
service,
167170
"/bin/bash",

0 commit comments

Comments
 (0)