Skip to content

Commit 1a2098f

Browse files
fix: Handling global installation
1 parent bc08a89 commit 1a2098f

File tree

3 files changed

+75
-62
lines changed

3 files changed

+75
-62
lines changed

src/jetBrains.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ const workspaceXmlPath = path.join(
1111
'workspace.xml',
1212
);
1313

14-
async function getWebStormLaunchConfig() {
15-
let runtimeExecutable = await getRuntimeExecutableForIde();
14+
async function getJetBrainsLaunchConfig() {
15+
let runtimeExecutable = await getRuntimeExecutableForIde(false);
16+
17+
if (!runtimeExecutable) {
18+
return undefined;
19+
}
20+
1621
runtimeExecutable = runtimeExecutable.replace(
1722
'${workspaceFolder}',
1823
'$PROJECT_DIR$',
@@ -57,7 +62,7 @@ async function writeWorkspaceXml(filePath: string, json: any) {
5762
});
5863
const xmlString = builder.build(json);
5964
await fs.writeFile(filePath, xmlString, 'utf-8');
60-
Logger.verbose(`Updated WebStorm configuration at ${filePath}`);
65+
Logger.verbose(`Updated JetBrains IDE configuration at ${filePath}`);
6166
} catch (err) {
6267
throw new Error(`Error writing ${filePath}`, { cause: err });
6368
}
@@ -80,9 +85,16 @@ async function isConfigured() {
8085
}
8186

8287
async function addConfiguration() {
83-
Logger.verbose('Adding WebStorm run/debug configuration');
88+
Logger.verbose('Adding JetBrains IDE run/debug configuration');
8489
const { json } = await readWorkspaceXml(workspaceXmlPath);
85-
const config = await getWebStormLaunchConfig();
90+
const config = await getJetBrainsLaunchConfig();
91+
92+
if (!config) {
93+
Logger.error(
94+
'Cannot find a locally installed Lambda Live Debugger. The JetBrains IDE debugger cannot use a globally installed version.',
95+
);
96+
return;
97+
}
8698

8799
if (!json) {
88100
// Create new workspace.xml if it does not exist

src/utils/getRuntimeExecutableForIde.ts

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Logger } from '../logger.js';
77
* Get the runtime executable for the IDE, like WebStorm or VSCode
88
* @returns
99
*/
10-
export async function getRuntimeExecutableForIde() {
10+
export async function getRuntimeExecutableForIde(allowGlobal = true) {
1111
let runtimeExecutable: string | undefined;
1212
const localRuntimeExecutable = '${workspaceFolder}/node_modules/.bin/lld';
1313

@@ -19,68 +19,69 @@ export async function getRuntimeExecutableForIde() {
1919
);
2020

2121
//if installed locally
22-
if (moduleDirname.startsWith('/home/')) {
23-
Logger.verbose('Lambda Live Debugger is installed locally');
24-
// check if file exists
25-
try {
26-
Logger.verbose(
27-
'Checking local folder for runtimeExecutable setting for VsCode configuration',
28-
localFolder,
29-
);
30-
await fs.access(localFolder, fs.constants.F_OK);
31-
runtimeExecutable = localRuntimeExecutable;
32-
} catch {
33-
// Not found
34-
}
35-
} else {
36-
Logger.verbose('Lambda Live Debugger is installed globally');
22+
Logger.verbose('Lambda Live Debugger is installed locally');
23+
try {
24+
Logger.verbose(
25+
'Checking local folder for runtimeExecutable setting for VsCode configuration',
26+
localFolder,
27+
);
28+
await fs.access(localFolder, fs.constants.F_OK);
29+
runtimeExecutable = localRuntimeExecutable;
30+
} catch {
31+
// Not found
3732
}
3833

3934
if (!runtimeExecutable) {
40-
Logger.verbose(
41-
`Setting absolute path for runtimeExecutable setting for VsCode configuration`,
42-
);
43-
const localFolderSubfolder = path.resolve('node_modules/.bin/lld');
44-
const globalModule1 = path.join(moduleDirname, '..', '..', '.bin/lld');
45-
const globalModule2 = path.join(moduleDirname, '..', '..', 'bin/lld');
46-
const globalModule3 = path.join(
47-
moduleDirname,
48-
'..',
49-
'..',
50-
'..',
51-
'..',
52-
'bin/lld',
53-
);
54-
const possibleFolders = {
55-
[localFolder]: '${workspaceFolder}/node_modules/.bin/lld',
56-
[localFolderSubfolder]: localFolderSubfolder,
57-
[globalModule1]: globalModule1,
58-
[globalModule2]: globalModule2,
59-
[globalModule3]: globalModule3,
60-
};
35+
Logger.verbose('Lambda Live Debugger is installed globally');
6136

62-
Logger.verbose(
63-
`Checking the following possible folders for lld executable:`,
64-
JSON.stringify(possibleFolders, null, 2),
65-
);
37+
if (allowGlobal) {
38+
Logger.verbose(
39+
`Setting absolute path for runtimeExecutable setting for VsCode configuration`,
40+
);
41+
const localFolderSubfolder = path.resolve('node_modules/.bin/lld');
42+
const globalModule1 = path.join(moduleDirname, '..', '..', '.bin/lld');
43+
const globalModule2 = path.join(moduleDirname, '..', '..', 'bin/lld');
44+
const globalModule3 = path.join(
45+
moduleDirname,
46+
'..',
47+
'..',
48+
'..',
49+
'..',
50+
'bin/lld',
51+
);
52+
const possibleFolders = {
53+
[localFolder]: '${workspaceFolder}/node_modules/.bin/lld',
54+
[localFolderSubfolder]: localFolderSubfolder,
55+
[globalModule1]: globalModule1,
56+
[globalModule2]: globalModule2,
57+
[globalModule3]: globalModule3,
58+
};
59+
60+
Logger.verbose(
61+
`Checking the following possible folders for lld executable:`,
62+
JSON.stringify(possibleFolders, null, 2),
63+
);
6664

67-
// check each possible folder and set the runtimeExecutable
68-
for (const folder in possibleFolders) {
69-
try {
70-
//Logger.log("Checking folder", folder);
71-
await fs.access(folder, fs.constants.F_OK);
72-
runtimeExecutable = possibleFolders[folder];
73-
Logger.verbose(`Found folder with lld executable: ${folder}`);
74-
break;
75-
} catch {
76-
// Not found
65+
// check each possible folder and set the runtimeExecutable
66+
for (const folder in possibleFolders) {
67+
try {
68+
//Logger.log("Checking folder", folder);
69+
await fs.access(folder, fs.constants.F_OK);
70+
runtimeExecutable = possibleFolders[folder];
71+
Logger.verbose(`Found folder with lld executable: ${folder}`);
72+
break;
73+
} catch {
74+
// Not found
75+
}
7776
}
78-
}
7977

80-
if (!runtimeExecutable) {
81-
Logger.error(
82-
`Could not find lld executable. Please check your IDE debugger settings.`,
83-
);
78+
if (!runtimeExecutable) {
79+
Logger.error(
80+
`Could not find lld executable. Please check your IDE debugger settings.`,
81+
);
82+
}
83+
} else {
84+
return null;
8485
}
8586
}
8687

src/vsCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function getVsCodeLaunchConfig() {
2323
name: 'Lambda Live Debugger',
2424
type: 'node',
2525
request: 'launch',
26-
runtimeExecutable: runtimeExecutable,
26+
runtimeExecutable: runtimeExecutable!,
2727
runtimeArgs: [],
2828
console: 'integratedTerminal',
2929
skipFiles: ['<node_internals>/**'],

0 commit comments

Comments
 (0)