11import vscode = require( "vscode" ) ;
2- import { currentFile } from "../utils" ;
2+ import { currentFile , currentFileFromContent } from "../utils" ;
33import { Subject } from "await-notify" ;
44import {
55 InitializedEvent ,
@@ -19,7 +19,6 @@ import WebSocket = require("ws");
1919import { AtelierAPI } from "../api" ;
2020import * as xdebug from "./xdebugConnection" ;
2121import { schemas } from "../extension" ;
22- import * as url from "url" ;
2322import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
2423import { 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 */
4140async 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 ;
0 commit comments