Skip to content

Commit b98c94a

Browse files
feat: WebStorm support
1 parent 945ea5a commit b98c94a

File tree

2 files changed

+105
-97
lines changed

2 files changed

+105
-97
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import fs from 'fs/promises';
2+
import path from 'path';
3+
import { getModuleDirname, getProjectDirname } from '../getDirname.js';
4+
import { Logger } from '../logger.js';
5+
6+
export async function getRuntimeExecutableForIde() {
7+
let runtimeExecutable: string | undefined;
8+
const localRuntimeExecutable = '${workspaceFolder}/node_modules/.bin/lld';
9+
10+
const moduleDirname = getModuleDirname();
11+
const projectDirname = getProjectDirname();
12+
13+
const localFolder = path.resolve(
14+
path.join(projectDirname, 'node_modules/.bin/lld'),
15+
);
16+
17+
//if installed locally
18+
if (moduleDirname.startsWith('/home/')) {
19+
Logger.verbose('Lambda Live Debugger is installed locally');
20+
// check if file exists
21+
try {
22+
Logger.verbose(
23+
'Checking local folder for runtimeExecutable setting for VsCode configuration',
24+
localFolder,
25+
);
26+
await fs.access(localFolder, fs.constants.F_OK);
27+
runtimeExecutable = localRuntimeExecutable;
28+
//Logger.log("Found local folder", localFolder);
29+
} catch {
30+
//Logger.log("Not found", localFolder);
31+
}
32+
} else {
33+
Logger.verbose('Lambda Live Debugger is installed globally');
34+
}
35+
36+
if (!runtimeExecutable) {
37+
Logger.verbose(
38+
`Setting absolute path for runtimeExecutable setting for VsCode configuration`,
39+
);
40+
const localFolderSubfolder = path.resolve('node_modules/.bin/lld');
41+
const globalModule1 = path.join(moduleDirname, '..', '..', '.bin/lld');
42+
const globalModule2 = path.join(moduleDirname, '..', '..', 'bin/lld');
43+
const globalModule3 = path.join(
44+
moduleDirname,
45+
'..',
46+
'..',
47+
'..',
48+
'..',
49+
'bin/lld',
50+
);
51+
const possibleFolders = {
52+
[localFolder]: '${workspaceFolder}/node_modules/.bin/lld',
53+
[localFolderSubfolder]: localFolderSubfolder,
54+
[globalModule1]: globalModule1,
55+
[globalModule2]: globalModule2,
56+
[globalModule3]: globalModule3,
57+
};
58+
59+
Logger.verbose(
60+
`Checking the following possible folders for lld executable:`,
61+
JSON.stringify(possibleFolders, null, 2),
62+
);
63+
64+
// check each possible folder and set the runtimeExecutable
65+
for (const folder in possibleFolders) {
66+
try {
67+
//Logger.log("Checking folder", folder);
68+
await fs.access(folder, fs.constants.F_OK);
69+
runtimeExecutable = possibleFolders[folder];
70+
Logger.verbose(`Found folder with lld executable: ${folder}`);
71+
break;
72+
} catch {
73+
// Not found
74+
}
75+
}
76+
77+
if (!runtimeExecutable) {
78+
Logger.error(
79+
`Could not find lld executable. Please check the setting runtimeExecutable in '.vscode/launch.json'.`,
80+
);
81+
}
82+
}
83+
84+
return runtimeExecutable;
85+
}

src/vsCode.ts

Lines changed: 20 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,109 +9,32 @@ import {
99
FormattingOptions,
1010
} from 'jsonc-parser';
1111
import { VsCodeLaunch } from './types/vsCodeConfig.js';
12-
import { getModuleDirname, getProjectDirname } from './getDirname.js';
12+
import { getProjectDirname } from './getDirname.js';
1313
import { Logger } from './logger.js';
14+
import { getRuntimeExecutableForIde } from './utils/getRuntimeExecutableForIde.js';
1415

1516
async 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

11740
async function readLaunchJson(filePath: string): Promise<{

0 commit comments

Comments
 (0)