Skip to content

Commit 516e4a3

Browse files
committed
fixed issues with debugging on isfs
1 parent 71f6b31 commit 516e4a3

File tree

4 files changed

+62
-48
lines changed

4 files changed

+62
-48
lines changed

src/debug/debugSession.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
8585

8686
private _evalResultProperties = new Map<number, xdebug.EvalResultProperty>();
8787

88+
private _workspace: string;
89+
8890
private cookies: string[] = [];
8991

9092
public constructor() {
@@ -110,7 +112,10 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
110112
};
111113

112114
try {
113-
const api = new AtelierAPI();
115+
const file = currentFile();
116+
this._workspace = file?.workspaceFolder;
117+
118+
const api = new AtelierAPI(file?.uri);
114119
this.cookies = api.cookies;
115120
if (!api.active) {
116121
throw new Error("Connection not active");
@@ -328,7 +333,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
328333
const [, namespace, name] = decodeURI(stackFrame.fileUri).match(/^dbgp:\/\/\|([^|]+)\|(.*)$/);
329334
const routine = name;
330335
// const routine = name.includes(".") ? name : name + ".int";
331-
const fileUri = DocumentContentProvider.getUri(routine, null, namespace).toString();
336+
const fileUri = DocumentContentProvider.getUri(routine, this._workspace, namespace).toString();
332337
const source = new Source(routine, fileUri);
333338
let line = stackFrame.line + 1;
334339
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;

src/debug/xdebugConnection.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// tslint:disable:max-classes-per-file
21
import * as iconv from "iconv-lite";
3-
// import * as net from "net";
42
import * as WebSocket from "ws";
53
import { DbgpConnection } from "./dbgp";
64

@@ -146,7 +144,7 @@ export abstract class Breakpoint {
146144
public constructor(breakpointNode: Element, connection: Connection);
147145
/** To create a new breakpoint in derived classes */
148146
public constructor(type: BreakpointType);
149-
public constructor(...rest) {
147+
public constructor(...rest: any[]) {
150148
if (typeof rest[0] === "object") {
151149
// from XML
152150
const breakpointNode: Element = rest[0];
@@ -175,7 +173,7 @@ export class LineBreakpoint extends Breakpoint {
175173
public constructor(breakpointNode: Element, connection: Connection);
176174
/** contructs a line breakpoint for passing to sendSetBreakpointCommand */
177175
public constructor(fileUri: string, line: number);
178-
public constructor(...rest) {
176+
public constructor(...rest: any[]) {
179177
if (typeof rest[0] === "object") {
180178
const breakpointNode: Element = rest[0];
181179
const connection: Connection = rest[1];
@@ -197,7 +195,7 @@ export class ClassLineBreakpoint extends LineBreakpoint {
197195

198196
/** contructs a line breakpoint for passing to sendSetBreakpointCommand */
199197
public constructor(fileUri: string, line: number, method: string, methodOffset: number);
200-
public constructor(...rest) {
198+
public constructor(...rest: any[]) {
201199
if (typeof rest[0] === "object") {
202200
const breakpointNode: Element = rest[0];
203201
const connection: Connection = rest[1];
@@ -218,7 +216,7 @@ export class RoutineLineBreakpoint extends LineBreakpoint {
218216

219217
/** contructs a line breakpoint for passing to sendSetBreakpointCommand */
220218
public constructor(fileUri: string, line: number, method: string, methodOffset: number);
221-
public constructor(...rest) {
219+
public constructor(...rest: any[]) {
222220
if (typeof rest[0] === "object") {
223221
const breakpointNode: Element = rest[0];
224222
const connection: Connection = rest[1];
@@ -245,7 +243,7 @@ export class ConditionalBreakpoint extends Breakpoint {
245243
public constructor(breakpointNode: Element, connection: Connection);
246244
/** Contructs a breakpoint object for passing to sendSetBreakpointCommand */
247245
public constructor(expression: string, fileUri: string, line?: number);
248-
public constructor(...rest) {
246+
public constructor(...rest: any[]) {
249247
if (typeof rest[0] === "object") {
250248
// from XML
251249
const breakpointNode: Element = rest[0];
@@ -427,6 +425,13 @@ export abstract class BaseProperty {
427425
this.value = iconv.encode(propertyNode.textContent, ENCODING) + "";
428426
}
429427
}
428+
if (this.value === "<UNDEFINED>") {
429+
this.value = undefined;
430+
this.type = "undefined";
431+
}
432+
if (this.type == "string" && Number(this.value).toString() === this.value) {
433+
this.type = this.value.includes(".") ? "float" : "int";
434+
}
430435
}
431436
}
432437

src/providers/ObjectScriptClassCodeLensProvider.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { config } from "../extension";
3+
import { currentFile } from "../utils";
34

45
export class ObjectScriptClassCodeLensProvider implements vscode.CodeLensProvider {
56
public provideCodeLenses(
@@ -17,50 +18,49 @@ export class ObjectScriptClassCodeLensProvider implements vscode.CodeLensProvide
1718
}
1819

1920
private classMethods(document: vscode.TextDocument): vscode.CodeLens[] {
21+
const file = currentFile(document);
2022
const result = new Array<vscode.CodeLens>();
2123

22-
let inComment = false;
23-
let className = "";
24-
for (let i = 0; i < document.lineCount; i++) {
25-
const line = document.lineAt(i);
26-
const text = this.stripLineComments(line.text);
24+
if (file.name.match(/\.cls$/i)) {
25+
const className = file.name.split(".").slice(0, -1).join(".");
2726

28-
if (text.match(/\/\*/)) {
29-
inComment = true;
30-
}
27+
let inComment = false;
28+
for (let i = 0; i < document.lineCount; i++) {
29+
const line = document.lineAt(i);
30+
const text = this.stripLineComments(line.text);
3131

32-
if (inComment) {
33-
if (text.match(/\*\//)) {
34-
inComment = false;
32+
if (text.match(/\/\*/)) {
33+
inComment = true;
3534
}
36-
continue;
37-
}
38-
if (!className.length) {
39-
const classNameMatch = text.match(/(?<=^Class\s)[^ ]+/i);
40-
if (classNameMatch) {
41-
[className] = classNameMatch;
35+
36+
if (inComment) {
37+
if (text.match(/\*\//)) {
38+
inComment = false;
39+
}
40+
continue;
4241
}
43-
}
44-
const { debugThisMethod } = config("debug");
45-
const methodMatch = text.match(/(?<=^ClassMethod\s)([^(]+)(\(.)/i);
46-
if (methodMatch) {
47-
const [, name, parens] = methodMatch;
48-
const program = `##class(${className}).${name}`;
49-
const askArgs = parens !== "()";
50-
if (debugThisMethod) {
51-
result.push(
52-
new vscode.CodeLens(
53-
new vscode.Range(
54-
new vscode.Position(i, methodMatch.index),
55-
new vscode.Position(i, methodMatch.index + name.length)
56-
),
57-
{
58-
title: `Debug this method`,
59-
command: "vscode-objectscript.debug",
60-
arguments: [program, askArgs],
61-
}
62-
)
63-
);
42+
43+
const { debugThisMethod } = config("debug");
44+
const methodMatch = text.match(/(?<=^ClassMethod\s)([^(]+)(\(.)/i);
45+
if (methodMatch) {
46+
const [, name, parens] = methodMatch;
47+
const program = `##class(${className}).${name}`;
48+
const askArgs = parens !== "()";
49+
if (debugThisMethod) {
50+
result.push(
51+
new vscode.CodeLens(
52+
new vscode.Range(
53+
new vscode.Position(i, methodMatch.index),
54+
new vscode.Position(i, methodMatch.index + name.length)
55+
),
56+
{
57+
title: `Debug this method`,
58+
command: "vscode-objectscript.debug",
59+
arguments: [program, askArgs],
60+
}
61+
)
62+
);
63+
}
6464
}
6565
}
6666
}

src/utils/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
222222
return vscode.workspace.getWorkspaceFolder(uri).name;
223223
}
224224
} else if (schemas.includes(uri.scheme)) {
225-
return uri.authority;
225+
const rootUri = uri.with({ path: "/" }).toString();
226+
const foundFolder = vscode.workspace.workspaceFolders.find(
227+
(workspaceFolder) => workspaceFolder.uri.toString() == rootUri
228+
);
229+
return foundFolder ? foundFolder.name : uri.authority;
226230
}
227231
}
228232
const firstFolder =

0 commit comments

Comments
 (0)