Skip to content

Commit fa0a5c5

Browse files
committed
fixed, issue with no file exist, correct using sessions
1 parent 4e545c6 commit fa0a5c5

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

src/api/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ export class AtelierAPI {
7171
};
7272
}
7373

74-
private get iris(): boolean {
75-
return workspaceState.get(this.configName + ":iris", false);
76-
}
77-
7874
private transformNameIfCsp(filename: string): string {
7975
// If a CSP file, change from
8076
// \csp\user\... to
@@ -131,12 +127,9 @@ export class AtelierAPI {
131127
}
132128

133129
public xdebugUrl(): string {
134-
const { host, username, https, port, password, apiVersion } = this.config;
130+
const { host, https, port, apiVersion } = this.config;
135131
const proto = https ? "wss" : "ws";
136-
const auth = this.iris
137-
? `IRISUsername=${username}&IRISPassword=${password}`
138-
: `CacheUserName=${username}&CachePassword=${password}`;
139-
return `${proto}://${host}:${port}/api/atelier/v${apiVersion}/%25SYS/debug?${auth}`;
132+
return `${proto}://${host}:${port}/api/atelier/v${apiVersion}/%25SYS/debug`;
140133
}
141134

142135
public updateCookies(newCookies: string[]): Promise<any> {

src/debug/debugSession.ts

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
9090
public constructor() {
9191
super();
9292

93-
const api = new AtelierAPI();
94-
this.cookies = api.cookies;
95-
if (!api.active) {
96-
throw new Error("Connection not active");
97-
}
98-
this._namespace = api.ns;
99-
this._url = api.xdebugUrl();
100-
10193
// this debugger uses zero-based lines and columns
10294
this.setDebuggerLinesStartAt1(false);
10395
this.setDebuggerColumnsStartAt1(false);
@@ -117,27 +109,37 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
117109
supportsStepBack: false,
118110
};
119111

120-
const socket = new WebSocket(this._url, {
121-
headers: {
122-
cookie: this.cookies,
123-
},
124-
});
112+
try {
113+
const api = new AtelierAPI();
114+
this.cookies = api.cookies;
115+
if (!api.active) {
116+
throw new Error("Connection not active");
117+
}
118+
this._namespace = api.ns;
119+
this._url = api.xdebugUrl();
125120

126-
const disposeConnection = (error?: Error): void => {
127-
this.sendEvent(new ThreadEvent("exited", this._connection.id));
128-
this._connection.close();
129-
this._connection = null;
130-
};
131-
this._connection = new xdebug.Connection(socket)
132-
.on("warning", (warning: string) => {
133-
this.sendEvent(new OutputEvent(warning + "\n"));
134-
})
135-
.on("close", disposeConnection)
136-
.on("stdout", (data: string) => {
137-
this.sendEvent(new OutputEvent(data, "stdout"));
121+
await api.serverInfo();
122+
123+
const socket = new WebSocket(this._url, {
124+
headers: {
125+
cookie: this.cookies,
126+
},
138127
});
139128

140-
try {
129+
const disposeConnection = (error?: Error): void => {
130+
this.sendEvent(new ThreadEvent("exited", this._connection.id));
131+
this._connection.close();
132+
this._connection = null;
133+
};
134+
this._connection = new xdebug.Connection(socket)
135+
.on("warning", (warning: string) => {
136+
this.sendEvent(new OutputEvent(warning + "\n"));
137+
})
138+
.on("close", disposeConnection)
139+
.on("stdout", (data: string) => {
140+
this.sendEvent(new OutputEvent(data, "stdout"));
141+
});
142+
141143
await this._connection.waitForInitPacket();
142144

143145
await this._connection.sendFeatureSetCommand("max_data", 8192);
@@ -326,26 +328,31 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
326328
const fileUri = DocumentContentProvider.getUri(routine, null, namespace).toString();
327329
const source = new Source(routine, fileUri);
328330
let line = stackFrame.line + 1;
329-
if (source.name.endsWith(".cls") && stackFrame.method !== "") {
330-
line = await vscode.workspace.openTextDocument(vscode.Uri.parse(source.path)).then((document) => {
331+
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;
332+
const stackFrameId = this._stackFrameIdCounter++;
333+
let noSource = false;
334+
try {
335+
const document = await vscode.workspace.openTextDocument(vscode.Uri.parse(source.path));
336+
if (source.name.endsWith(".cls") && stackFrame.method !== "") {
331337
const methodMatchPattern = new RegExp(`^(Class)?Method ${stackFrame.method}(?=[( ])`, "i");
332338
for (let i = 0; i < document.lineCount; i++) {
333-
const line = document.lineAt(i);
339+
const codeLine = document.lineAt(i);
334340

335-
const methodMatch = line.text.match(methodMatchPattern);
341+
const methodMatch = codeLine.text.match(methodMatchPattern);
336342
if (methodMatch) {
337-
return i + 2 + stackFrame.methodOffset;
343+
line = i + 2 + stackFrame.methodOffset;
344+
break;
338345
}
339346
}
340-
});
347+
}
348+
this._stackFrames.set(stackFrameId, stackFrame);
349+
} catch (ex) {
350+
noSource = true;
341351
}
342-
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;
343-
const stackFrameId = this._stackFrameIdCounter++;
344-
this._stackFrames.set(stackFrameId, stackFrame);
345352
return {
346353
id: stackFrameId,
347354
name: place,
348-
source,
355+
source: noSource ? null : source,
349356
line,
350357
column: 1,
351358
};

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
587587
placeHolder: "Please enter comma delimited arguments list",
588588
})
589589
.then((args) => {
590-
startDebugging(args);
590+
if (args) {
591+
startDebugging(args);
592+
}
591593
});
592594
}),
593595
vscode.commands.registerCommand("vscode-objectscript.pickProcess", async (config) => {

0 commit comments

Comments
 (0)