Skip to content

Commit c482df7

Browse files
committed
Lint
1 parent 2487fbb commit c482df7

File tree

1 file changed

+75
-76
lines changed

1 file changed

+75
-76
lines changed

src/debugAdapter2/goDlvDebug.ts

+75-76
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ import {
1717
logger,
1818
Logger,
1919
LoggingDebugSession,
20-
TerminatedEvent,
21-
OutputEvent
20+
OutputEvent,
21+
TerminatedEvent
2222
} from 'vscode-debugadapter';
2323
import { DebugProtocol } from 'vscode-debugprotocol';
2424

2525
import {
2626
envPath,
27-
parseEnvFile,
28-
getBinPathWithPreferredGopathGoroot
27+
getBinPathWithPreferredGopathGoroot,
28+
parseEnvFile
2929
} from '../goPath';
3030
import { DAPClient } from './dapClient';
3131

32-
3332
interface LoadConfig {
3433
// FollowPointers requests pointers to be automatically dereferenced.
3534
followPointers: boolean;
@@ -264,73 +263,6 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
264263
});
265264
}
266265

267-
// Launch the debugee process without starting a debugger.
268-
// This implements the `Run > Run Without Debugger` functionality in vscode.
269-
// Note: this method currently assumes launchArgs.mode === 'debug'.
270-
private launchNoDebug(launchArgs: LaunchRequestArguments): void {
271-
let program = launchArgs.program;
272-
if (!program) {
273-
throw new Error('The program attribute is missing in the debug configuration in launch.json');
274-
}
275-
let programIsDirectory = false;
276-
try {
277-
programIsDirectory = fs.lstatSync(program).isDirectory();
278-
} catch (e) {
279-
throw new Error('The program attribute must point to valid directory, .go file or executable.');
280-
}
281-
if (!programIsDirectory && path.extname(program) !== '.go') {
282-
throw new Error('The program attribute must be a directory or .go file in debug mode');
283-
}
284-
285-
let goRunArgs = ['run'];
286-
if (launchArgs.buildFlags) {
287-
goRunArgs.push(launchArgs.buildFlags);
288-
}
289-
290-
if (programIsDirectory) {
291-
goRunArgs.push('.');
292-
} else {
293-
goRunArgs.push(program);
294-
}
295-
296-
if (launchArgs.args) {
297-
goRunArgs.push(...launchArgs.args);
298-
}
299-
300-
// Read env from disk and merge into env variables.
301-
const fileEnvs = [];
302-
if (typeof launchArgs.envFile === 'string') {
303-
fileEnvs.push(parseEnvFile(launchArgs.envFile));
304-
}
305-
if (Array.isArray(launchArgs.envFile)) {
306-
launchArgs.envFile.forEach((envFile) => {
307-
fileEnvs.push(parseEnvFile(envFile));
308-
});
309-
}
310-
311-
const launchArgsEnv = launchArgs.env || {};
312-
let programEnv = Object.assign({}, process.env, ...fileEnvs, launchArgsEnv);
313-
314-
const dirname = programIsDirectory ? program : path.dirname(program);
315-
const goExe = getBinPathWithPreferredGopathGoroot('go', []);
316-
log(`Current working directory: ${dirname}`);
317-
log(`Running: ${goExe} ${goRunArgs.join(' ')}`);
318-
319-
this.debugProcess = spawn(goExe, goRunArgs, {
320-
cwd: dirname,
321-
env: programEnv
322-
});
323-
this.debugProcess.stderr.on('data', (str) => {
324-
this.sendEvent(new OutputEvent(str.toString(), 'stderr'));
325-
});
326-
this.debugProcess.stdout.on('data', (str) => {
327-
this.sendEvent(new OutputEvent(str.toString(), 'stdout'));
328-
});
329-
this.debugProcess.on('close', (rc) => {
330-
this.sendEvent(new TerminatedEvent());
331-
});
332-
}
333-
334266
protected attachRequest(
335267
response: DebugProtocol.AttachResponse,
336268
args: AttachRequestArguments,
@@ -355,14 +287,14 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
355287
if (this.debugProcess !== null) {
356288
log(`killing debugee (pid: ${this.debugProcess.pid})...`);
357289

358-
// Kill the debuggee and notify the client when the killing is
290+
// Kill the debugee and notify the client when the killing is
359291
// completed, to ensure a clean shutdown sequence.
360292
killProcessTree(this.debugProcess).then(() => {
361293
super.disconnectRequest(response, args);
362294
log('DisconnectResponse');
363-
})
295+
});
364296
} else if (this.dlvClient !== null) {
365-
// Forward this DisconnectRequest to Delve.
297+
// Forward this DisconnectRequest to Delve.
366298
this.dlvClient.send(request);
367299
} else {
368300
logError(`both debug process and dlv client are null`);
@@ -661,6 +593,73 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
661593
): void {
662594
this.dlvClient.send(request);
663595
}
596+
597+
// Launch the debugee process without starting a debugger.
598+
// This implements the `Run > Run Without Debugger` functionality in vscode.
599+
// Note: this method currently assumes launchArgs.mode === 'debug'.
600+
private launchNoDebug(launchArgs: LaunchRequestArguments): void {
601+
const program = launchArgs.program;
602+
if (!program) {
603+
throw new Error('The program attribute is missing in the debug configuration in launch.json');
604+
}
605+
let programIsDirectory = false;
606+
try {
607+
programIsDirectory = fs.lstatSync(program).isDirectory();
608+
} catch (e) {
609+
throw new Error('The program attribute must point to valid directory, .go file or executable.');
610+
}
611+
if (!programIsDirectory && path.extname(program) !== '.go') {
612+
throw new Error('The program attribute must be a directory or .go file in debug mode');
613+
}
614+
615+
const goRunArgs = ['run'];
616+
if (launchArgs.buildFlags) {
617+
goRunArgs.push(launchArgs.buildFlags);
618+
}
619+
620+
if (programIsDirectory) {
621+
goRunArgs.push('.');
622+
} else {
623+
goRunArgs.push(program);
624+
}
625+
626+
if (launchArgs.args) {
627+
goRunArgs.push(...launchArgs.args);
628+
}
629+
630+
// Read env from disk and merge into env variables.
631+
const fileEnvs = [];
632+
if (typeof launchArgs.envFile === 'string') {
633+
fileEnvs.push(parseEnvFile(launchArgs.envFile));
634+
}
635+
if (Array.isArray(launchArgs.envFile)) {
636+
launchArgs.envFile.forEach((envFile) => {
637+
fileEnvs.push(parseEnvFile(envFile));
638+
});
639+
}
640+
641+
const launchArgsEnv = launchArgs.env || {};
642+
const programEnv = Object.assign({}, process.env, ...fileEnvs, launchArgsEnv);
643+
644+
const dirname = programIsDirectory ? program : path.dirname(program);
645+
const goExe = getBinPathWithPreferredGopathGoroot('go', []);
646+
log(`Current working directory: ${dirname}`);
647+
log(`Running: ${goExe} ${goRunArgs.join(' ')}`);
648+
649+
this.debugProcess = spawn(goExe, goRunArgs, {
650+
cwd: dirname,
651+
env: programEnv
652+
});
653+
this.debugProcess.stderr.on('data', (str) => {
654+
this.sendEvent(new OutputEvent(str.toString(), 'stderr'));
655+
});
656+
this.debugProcess.stdout.on('data', (str) => {
657+
this.sendEvent(new OutputEvent(str.toString(), 'stdout'));
658+
});
659+
this.debugProcess.on('close', (rc) => {
660+
this.sendEvent(new TerminatedEvent());
661+
});
662+
}
664663
}
665664

666665
// DelveClient provides a DAP client to talk to a DAP server in Delve.
@@ -786,4 +785,4 @@ function killProcessTree(p: ChildProcess): Promise<void> {
786785
resolve();
787786
});
788787
});
789-
}
788+
}

0 commit comments

Comments
 (0)