Skip to content

Commit 9399783

Browse files
authored
Don't call openTextDocument in debugger (#1042)
1 parent c3f9c95 commit 9399783

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

src/commands/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ function importFiles(files: string[], noCompile = false) {
405405
vscode.workspace.fs
406406
.readFile(vscode.Uri.file(file))
407407
.then((contentBytes) => new TextDecoder().decode(contentBytes))
408-
.then((content) => currentFileFromContent(file, content))
408+
.then((content) => currentFileFromContent(vscode.Uri.file(file), content))
409409
.then((curFile) =>
410410
importFile(curFile).then((data) => {
411411
outputChannel.appendLine("Imported file: " + curFile.fileName);

src/debug/debugSession.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import vscode = require("vscode");
2-
import { currentFile } from "../utils";
2+
import { currentFile, currentFileFromContent } from "../utils";
33
import { Subject } from "await-notify";
44
import {
55
InitializedEvent,
@@ -19,7 +19,6 @@ import WebSocket = require("ws");
1919
import { AtelierAPI } from "../api";
2020
import * as xdebug from "./xdebugConnection";
2121
import { schemas } from "../extension";
22-
import * as url from "url";
2322
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
2423
import { formatPropertyValue } from "./utils";
2524

@@ -40,20 +39,15 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
4039
/** converts a uri from VS Code to a server-side XDebug file URI with respect to source root settings */
4140
async function convertClientPathToDebugger(uri: vscode.Uri, namespace: string): Promise<string> {
4241
const { scheme, path } = uri;
43-
const { query } = url.parse(uri.toString(true), true);
42+
const params = new URLSearchParams(uri.query);
4443
let fileName: string;
4544
if (scheme && schemas.includes(scheme)) {
46-
if (query.ns && query.ns !== "") {
47-
namespace = query.ns.toString();
45+
if (params.has("ns") && params.get("ns") !== "") {
46+
namespace = params.get("ns");
4847
}
4948
fileName = path.slice(1).replace(/\//g, ".");
5049
} else {
51-
fileName = await vscode.workspace
52-
.openTextDocument(uri)
53-
.then(currentFile)
54-
.then((curFile) => {
55-
return curFile.name;
56-
});
50+
fileName = currentFileFromContent(uri, new TextDecoder().decode(await vscode.workspace.fs.readFile(uri)))?.name;
5751
}
5852

5953
namespace = encodeURIComponent(namespace);
@@ -294,7 +288,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
294288
currentSymbol.detail.toLowerCase() !== "query"
295289
) {
296290
// This breakpoint is in a method
297-
const currentdoc = await vscode.workspace.openTextDocument(uri);
291+
const currentdoc = new TextDecoder().decode(await vscode.workspace.fs.readFile(uri)).split(/\r?\n/);
298292
if (languageServer) {
299293
// selectionRange.start.line is the method definition line
300294
for (
@@ -303,7 +297,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
303297
methodlinenum++
304298
) {
305299
// Find the offset of this breakpoint in the method
306-
const methodlinetext: string = currentdoc.lineAt(methodlinenum).text.trim();
300+
const methodlinetext: string = currentdoc[methodlinenum].trim();
307301
if (methodlinetext.endsWith("{")) {
308302
// This is the last line of the method definition, so count from here
309303
if (breakpoint.condition) {
@@ -527,15 +521,15 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
527521
}
528522
}
529523
if (currentSymbol !== undefined) {
530-
const currentdoc = await vscode.workspace.openTextDocument(fileUri);
524+
const currentdoc = new TextDecoder().decode(await vscode.workspace.fs.readFile(fileUri)).split(/\r?\n/);
531525
if (languageServer) {
532526
for (
533527
let methodlinenum = currentSymbol.selectionRange.start.line;
534528
methodlinenum <= currentSymbol.range.end.line;
535529
methodlinenum++
536530
) {
537531
// Find the offset of this breakpoint in the method
538-
const methodlinetext: string = currentdoc.lineAt(methodlinenum).text.trim();
532+
const methodlinetext: string = currentdoc[methodlinenum].trim();
539533
if (methodlinetext.endsWith("{")) {
540534
// This is the last line of the method definition, so count from here
541535
line = methodlinenum + stackFrame.methodOffset + 1;

src/utils/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path = require("path");
2-
import * as url from "url";
32
import { exec } from "child_process";
43
import * as vscode from "vscode";
54
import { config, schemas, workspaceState, terminals, extensionContext, cspApps } from "../extension";
@@ -141,8 +140,8 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
141140
}
142141
}
143142

144-
export function currentFileFromContent(fileName: string, content: string): CurrentFile {
145-
const uri = vscode.Uri.file(fileName);
143+
export function currentFileFromContent(uri: vscode.Uri, content: string): CurrentFile {
144+
const fileName = uri.fsPath;
146145
const workspaceFolder = workspaceFolderOfUri(uri);
147146
if (!workspaceFolder) {
148147
// No workspace folders are open
@@ -220,8 +219,8 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
220219
const content = document.getText();
221220
let name = "";
222221
let ext = "";
223-
const { query } = url.parse(uri.toString(true), true);
224-
const csp = query.csp === "" || query.csp === "1";
222+
const params = new URLSearchParams(uri.query);
223+
const csp = params.has("csp") && ["", "1"].includes(params.get("csp"));
225224
if (csp) {
226225
name = uri.path;
227226
} else if (fileExt === "cls") {

0 commit comments

Comments
 (0)