Skip to content

Commit 2221664

Browse files
committed
More small fixes
1 parent 7ad032d commit 2221664

File tree

3 files changed

+98
-89
lines changed

3 files changed

+98
-89
lines changed

src/commands/compile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ async function importFiles(files: vscode.Uri[], noCompile = false) {
465465
}
466466

467467
export async function importFolder(uri: vscode.Uri, noCompile = false): Promise<any> {
468+
if (!(uri instanceof vscode.Uri)) return;
468469
if (filesystemSchemas.includes(uri.scheme)) return; // Not for server-side URIs
469470
if ((await vscode.workspace.fs.stat(uri)).type != vscode.FileType.Directory) {
470471
return importFiles([uri], noCompile);

src/debug/debugSession.ts

Lines changed: 93 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -660,104 +660,108 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
660660
response: DebugProtocol.StackTraceResponse,
661661
args: DebugProtocol.StackTraceArguments
662662
): Promise<void> {
663-
const stack = await this._connection.sendStackGetCommand();
664-
665-
/** Is set to true if we're at the CSP or unit test ending watchpoint.
666-
* We need to do this so VS Code doesn't try to open the source of
667-
* a stack frame before the debug session terminates. */
668-
let noStack = false;
669-
const stackFrames = await Promise.all(
670-
stack.stack.map(async (stackFrame: xdebug.StackFrame, index): Promise<StackFrame> => {
671-
if (noStack) return; // Stack frames won't be sent
672-
const [, namespace, docName] = decodeURI(stackFrame.fileUri).match(/^dbgp:\/\/\|([^|]+)\|(.*)$/);
673-
const fileUri = DocumentContentProvider.getUri(
674-
docName,
675-
this._workspace,
676-
namespace,
677-
undefined,
678-
this._workspaceFolderUri
679-
);
680-
const source = new Source(docName, fileUri.toString());
681-
let line = stackFrame.line + 1;
682-
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;
683-
const stackFrameId = this._stackFrameIdCounter++;
684-
if (index == 0 && this._break) {
685-
const csp = this._isCsp && ["%SYS.cspServer.mac", "%SYS.cspServer.int"].includes(source.name);
686-
const unitTest = this._isUnitTest && source.name.startsWith("%Api.Atelier.v");
687-
if (csp || unitTest) {
688-
// Check if we're at our special watchpoint
689-
const { result } = await this._connection.sendEvalCommand(
690-
csp ? this._cspWatchpointCondition : this._unitTestWatchpointCondition
691-
);
692-
if (result.type == "int" && result.value == "1") {
693-
// Stop the debugging session
694-
const xdebugResponse = await this._connection.sendDetachCommand();
695-
this._checkStatus(xdebugResponse);
696-
noStack = true;
697-
return;
663+
try {
664+
const stack = await this._connection.sendStackGetCommand();
665+
666+
/** Is set to true if we're at the CSP or unit test ending watchpoint.
667+
* We need to do this so VS Code doesn't try to open the source of
668+
* a stack frame before the debug session terminates. */
669+
let noStack = false;
670+
const stackFrames = await Promise.all(
671+
stack.stack.map(async (stackFrame: xdebug.StackFrame, index): Promise<StackFrame> => {
672+
if (noStack) return; // Stack frames won't be sent
673+
const [, namespace, docName] = decodeURI(stackFrame.fileUri).match(/^dbgp:\/\/\|([^|]+)\|(.*)$/);
674+
const fileUri = DocumentContentProvider.getUri(
675+
docName,
676+
this._workspace,
677+
namespace,
678+
undefined,
679+
this._workspaceFolderUri
680+
);
681+
const source = new Source(docName, fileUri.toString());
682+
let line = stackFrame.line + 1;
683+
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;
684+
const stackFrameId = this._stackFrameIdCounter++;
685+
if (index == 0 && this._break) {
686+
const csp = this._isCsp && ["%SYS.cspServer.mac", "%SYS.cspServer.int"].includes(source.name);
687+
const unitTest = this._isUnitTest && source.name.startsWith("%Api.Atelier.v");
688+
if (csp || unitTest) {
689+
// Check if we're at our special watchpoint
690+
const { result } = await this._connection.sendEvalCommand(
691+
csp ? this._cspWatchpointCondition : this._unitTestWatchpointCondition
692+
);
693+
if (result.type == "int" && result.value == "1") {
694+
// Stop the debugging session
695+
const xdebugResponse = await this._connection.sendDetachCommand();
696+
this._checkStatus(xdebugResponse);
697+
noStack = true;
698+
return;
699+
}
698700
}
699701
}
700-
}
701-
const fileText = await this._getFileText(fileUri);
702-
const hasCmdLoc = typeof stackFrame.cmdBeginLine == "number";
703-
if (!fileText.length) {
704-
// Can't get the source for the document
705-
this._stackFrames.set(stackFrameId, stackFrame);
702+
const fileText = await this._getFileText(fileUri);
703+
const hasCmdLoc = typeof stackFrame.cmdBeginLine == "number";
704+
if (!fileText.length) {
705+
// Can't get the source for the document
706+
this._stackFrames.set(stackFrameId, stackFrame);
707+
return {
708+
id: stackFrameId,
709+
name: place,
710+
// Don't provide a source path so VS Code doesn't attempt
711+
// to open this file or provide an option to "create" it
712+
source: {
713+
name: docName,
714+
presentationHint: "deemphasize",
715+
},
716+
line,
717+
column: 0,
718+
};
719+
}
720+
let noSource = false;
721+
try {
722+
if (source.name.endsWith(".cls") && stackFrame.method !== "") {
723+
// Compute DocumentSymbols for this class
724+
const symbols: vscode.DocumentSymbol[] = (
725+
await vscode.commands.executeCommand<vscode.DocumentSymbol[]>(
726+
"vscode.executeDocumentSymbolProvider",
727+
fileUri
728+
)
729+
)[0].children;
730+
const newLine = methodOffsetToLine(symbols, fileText, stackFrame.method, stackFrame.methodOffset);
731+
if (newLine != undefined) line = newLine;
732+
}
733+
this._stackFrames.set(stackFrameId, stackFrame);
734+
} catch {
735+
noSource = true;
736+
}
737+
const lineDiff = line - stackFrame.line;
706738
return {
707739
id: stackFrameId,
708740
name: place,
709-
// Don't provide a source path so VS Code doesn't attempt
710-
// to open this file or provide an option to "create" it
711-
source: {
712-
name: docName,
713-
presentationHint: "deemphasize",
714-
},
741+
source: noSource ? null : source,
715742
line,
716-
column: 0,
743+
column: hasCmdLoc ? stackFrame.cmdBeginPos + 1 : 0,
744+
endLine: hasCmdLoc ? stackFrame.cmdEndLine + lineDiff : undefined,
745+
endColumn: hasCmdLoc
746+
? (stackFrame.cmdEndPos == 0
747+
? // A command that ends at position zero means "rest of this line"
748+
fileText.split(/\r?\n/)[stackFrame.cmdEndLine + lineDiff - 1].length
749+
: stackFrame.cmdEndPos) + 1
750+
: undefined,
717751
};
718-
}
719-
let noSource = false;
720-
try {
721-
if (source.name.endsWith(".cls") && stackFrame.method !== "") {
722-
// Compute DocumentSymbols for this class
723-
const symbols: vscode.DocumentSymbol[] = (
724-
await vscode.commands.executeCommand<vscode.DocumentSymbol[]>(
725-
"vscode.executeDocumentSymbolProvider",
726-
fileUri
727-
)
728-
)[0].children;
729-
const newLine = methodOffsetToLine(symbols, fileText, stackFrame.method, stackFrame.methodOffset);
730-
if (newLine != undefined) line = newLine;
731-
}
732-
this._stackFrames.set(stackFrameId, stackFrame);
733-
} catch {
734-
noSource = true;
735-
}
736-
const lineDiff = line - stackFrame.line;
737-
return {
738-
id: stackFrameId,
739-
name: place,
740-
source: noSource ? null : source,
741-
line,
742-
column: hasCmdLoc ? stackFrame.cmdBeginPos + 1 : 0,
743-
endLine: hasCmdLoc ? stackFrame.cmdEndLine + lineDiff : undefined,
744-
endColumn: hasCmdLoc
745-
? (stackFrame.cmdEndPos == 0
746-
? // A command that ends at position zero means "rest of this line"
747-
fileText.split(/\r?\n/)[stackFrame.cmdEndLine + lineDiff - 1].length
748-
: stackFrame.cmdEndPos) + 1
749-
: undefined,
750-
};
751-
})
752-
);
752+
})
753+
);
753754

754-
this._break = false;
755-
if (!noStack) {
756-
response.body = {
757-
stackFrames,
758-
};
755+
this._break = false;
756+
if (!noStack) {
757+
response.body = {
758+
stackFrames,
759+
};
760+
}
761+
this.sendResponse(response);
762+
} catch (error) {
763+
this.sendErrorResponse(response, error);
759764
}
760-
this.sendResponse(response);
761765
}
762766

763767
protected async scopesRequest(

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,10 +1152,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
11521152
}),
11531153
vscode.commands.registerCommand("vscode-objectscript.compileFolder", (_file, files) => {
11541154
sendCommandTelemetryEvent("compileFolder");
1155+
if (!_file && !files?.length) return;
1156+
files = files ?? [_file];
11551157
Promise.all(files.map((file) => importFileOrFolder(file, false)));
11561158
}),
11571159
vscode.commands.registerCommand("vscode-objectscript.importFolder", (_file, files) => {
11581160
sendCommandTelemetryEvent("importFolder");
1161+
if (!_file && !files?.length) return;
1162+
files = files ?? [_file];
11591163
Promise.all(files.map((file) => importFileOrFolder(file, true)));
11601164
}),
11611165
vscode.commands.registerCommand("vscode-objectscript.export", () => {

0 commit comments

Comments
 (0)