@@ -9,109 +9,32 @@ import {
99 FormattingOptions ,
1010} from 'jsonc-parser' ;
1111import { VsCodeLaunch } from './types/vsCodeConfig.js' ;
12- import { getModuleDirname , getProjectDirname } from './getDirname.js' ;
12+ import { getProjectDirname } from './getDirname.js' ;
1313import { Logger } from './logger.js' ;
14+ import { getRuntimeExecutableForIde } from './utils/getRuntimeExecutableForIde.js' ;
1415
1516async function getVsCodeLaunchConfig ( ) {
16- const localRuntimeExecutable = '${workspaceFolder}/node_modules/.bin/lld' ;
17-
18- const config : VsCodeLaunch = {
19- version : '0.2.0' ,
20- configurations : [
21- {
22- name : 'Lambda Live Debugger' ,
23- type : 'node' ,
24- request : 'launch' ,
25- runtimeExecutable : localRuntimeExecutable ,
26- runtimeArgs : [ ] ,
27- console : 'integratedTerminal' ,
28- skipFiles : [ '<node_internals>/**' ] ,
29- env : { } ,
30- } ,
31- ] ,
32- } ;
33-
34- const moduleDirname = getModuleDirname ( ) ;
35- //Logger.log("Module folder", moduleDirname);
36- const projectDirname = getProjectDirname ( ) ;
37-
38- //Logger.log("Current folder", currentFolder);
39- const localFolder = path . resolve (
40- path . join ( projectDirname , 'node_modules/.bin/lld' ) ,
41- ) ;
42-
43- let runtimeExecutableSet = false ;
44-
45- //if installed locally
46- if ( moduleDirname . startsWith ( '/home/' ) ) {
47- Logger . verbose ( 'Lambda Live Debugger is installed locally' ) ;
48- // check if file exists
49- try {
50- Logger . verbose (
51- 'Checking local folder for runtimeExecutable setting for VsCode configuration' ,
52- localFolder ,
53- ) ;
54- await fs . access ( localFolder , fs . constants . F_OK ) ;
55- config . configurations ! [ 0 ] . runtimeExecutable = localRuntimeExecutable ;
56- runtimeExecutableSet = true ;
57- //Logger.log("Found local folder", localFolder);
58- } catch {
59- //Logger.log("Not found", localFolder);
60- }
61- } else {
62- Logger . verbose ( 'Lambda Live Debugger is installed globally' ) ;
63- }
64-
65- if ( ! runtimeExecutableSet ) {
66- Logger . verbose (
67- `Setting absolute path for runtimeExecutable setting for VsCode configuration` ,
68- ) ;
69- const localFolderSubfolder = path . resolve ( 'node_modules/.bin/lld' ) ;
70- const globalModule1 = path . join ( moduleDirname , '..' , '..' , '.bin/lld' ) ;
71- const globalModule2 = path . join ( moduleDirname , '..' , '..' , 'bin/lld' ) ;
72- const globalModule3 = path . join (
73- moduleDirname ,
74- '..' ,
75- '..' ,
76- '..' ,
77- '..' ,
78- 'bin/lld' ,
79- ) ;
80- const possibleFolders = {
81- [ localFolder ] : '${workspaceFolder}/node_modules/.bin/lld' ,
82- [ localFolderSubfolder ] : localFolderSubfolder ,
83- [ globalModule1 ] : globalModule1 ,
84- [ globalModule2 ] : globalModule2 ,
85- [ globalModule3 ] : globalModule3 ,
17+ const runtimeExecutable = await getRuntimeExecutableForIde ( ) ;
18+
19+ if ( runtimeExecutable ) {
20+ const config : VsCodeLaunch = {
21+ version : '0.2.0' ,
22+ configurations : [
23+ {
24+ name : 'Lambda Live Debugger' ,
25+ type : 'node' ,
26+ request : 'launch' ,
27+ runtimeExecutable : runtimeExecutable ,
28+ runtimeArgs : [ ] ,
29+ console : 'integratedTerminal' ,
30+ skipFiles : [ '<node_internals>/**' ] ,
31+ env : { } ,
32+ } ,
33+ ] ,
8634 } ;
8735
88- Logger . verbose (
89- `Checking the following possible folders for lld executable:` ,
90- JSON . stringify ( possibleFolders , null , 2 ) ,
91- ) ;
92-
93- // check each possible folder and set the runtimeExecutable
94- for ( const folder in possibleFolders ) {
95- try {
96- //Logger.log("Checking folder", folder);
97- await fs . access ( folder , fs . constants . F_OK ) ;
98- config . configurations ! [ 0 ] . runtimeExecutable = possibleFolders [ folder ] ;
99- runtimeExecutableSet = true ;
100- Logger . verbose ( `Found folder with lld executable: ${ folder } ` ) ;
101- break ;
102- } catch {
103- // Not found
104- }
105- }
106-
107- if ( ! runtimeExecutableSet ) {
108- Logger . error (
109- `Could not find lld executable. Please check the setting runtimeExecutable in '.vscode/launch.json'.` ,
110- ) ;
111- }
36+ return config ;
11237 }
113-
114- return config ;
11538}
11639
11740async function readLaunchJson ( filePath : string ) : Promise < {
0 commit comments