Skip to content

Commit 545c787

Browse files
committed
update attach
1 parent 839fea0 commit 545c787

3 files changed

Lines changed: 60 additions & 7 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@
238238
"type": "emmylua_launch",
239239
"request": "launch",
240240
"name": "%debug.launch.name%",
241-
"program": "",
242-
"workingDir": "",
241+
"program": "${file}",
242+
"workingDir": "${workspaceFolder}",
243243
"arguments": [],
244244
"newWindow": false
245245
}
@@ -252,8 +252,8 @@
252252
"type": "emmylua_launch",
253253
"request": "launch",
254254
"name": "%debug.launch.name%",
255-
"program": "",
256-
"workingDir": "",
255+
"program": "${file}",
256+
"workingDir": "${workspaceFolder}",
257257
"arguments": [],
258258
"newWindow": false
259259
}

src/debugger/attach/EmmyAttachDebuggerProvider.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export interface EmmyAttachDebugConfiguration extends DebugConfigurationBase {
1616

1717

1818
export class EmmyAttachDebuggerProvider extends DebuggerProvider {
19-
async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, configuration: EmmyAttachDebugConfiguration, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration> {
19+
async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, configuration: EmmyAttachDebugConfiguration, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration | undefined> {
20+
if (process.platform !== 'win32') {
21+
vscode.window.showErrorMessage('EmmyLua attach debug currently supports Windows only.');
22+
return undefined;
23+
}
24+
2025
configuration.extensionPath = this.context.extensionPath;
2126
configuration.sourcePaths = this.getSourceRoots();
2227
configuration.request = "attach";
@@ -76,7 +81,7 @@ export class EmmyAttachDebuggerProvider extends DebuggerProvider {
7681
reject();
7782
}
7883

79-
}).on("error", error => reject);
84+
}).on("error", error => reject(error));
8085
});
8186
}
8287
}

src/debugger/launch/EmmyLaunchDebuggerProvider.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as path from 'path';
23
import { DebugConfigurationBase } from "../base/DebugConfigurationBase";
34
import { DebuggerProvider } from "../base/DebuggerProvider";
45

@@ -12,10 +13,57 @@ export interface EmmyLaunchDebugConfiguration extends DebugConfigurationBase {
1213

1314

1415
export class EmmyLaunchDebuggerProvider extends DebuggerProvider {
15-
async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, configuration: EmmyLaunchDebugConfiguration, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration> {
16+
async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, configuration: EmmyLaunchDebugConfiguration, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration | undefined> {
17+
const resolvedProgram = this.resolveProgramPath(configuration.program);
18+
const resolvedWorkingDir = this.resolveWorkingDirectory(folder, configuration.workingDir, resolvedProgram);
19+
20+
if (this.isNullOrEmpty(resolvedProgram)) {
21+
vscode.window.showErrorMessage('EmmyLua launch debug requires a Lua entry file. Open a Lua file or set the program field in launch.json.');
22+
return undefined;
23+
}
24+
1625
configuration.extensionPath = this.context.extensionPath;
1726
configuration.sourcePaths = this.getSourceRoots();
1827
configuration.ext = this.getExt();
28+
configuration.request = 'launch';
29+
configuration.type = 'emmylua_launch';
30+
configuration.program = resolvedProgram;
31+
configuration.workingDir = resolvedWorkingDir;
32+
configuration.arguments = configuration.arguments ?? [];
1933
return configuration;
2034
}
35+
36+
private resolveProgramPath(configuredProgram?: string): string {
37+
if (!this.isNullOrEmpty(configuredProgram)) {
38+
return configuredProgram!.trim();
39+
}
40+
41+
const activeDocument = vscode.window.activeTextEditor?.document;
42+
if (activeDocument?.languageId === 'lua' && activeDocument.uri.scheme === 'file') {
43+
return activeDocument.uri.fsPath;
44+
}
45+
46+
return '';
47+
}
48+
49+
private resolveWorkingDirectory(
50+
folder: vscode.WorkspaceFolder | undefined,
51+
configuredWorkingDir: string | undefined,
52+
resolvedProgram: string
53+
): string {
54+
if (!this.isNullOrEmpty(configuredWorkingDir)) {
55+
return configuredWorkingDir!.trim();
56+
}
57+
58+
if (folder) {
59+
return folder.uri.fsPath;
60+
}
61+
62+
if (!this.isNullOrEmpty(resolvedProgram)) {
63+
return path.dirname(resolvedProgram);
64+
}
65+
66+
const firstWorkspaceFolder = vscode.workspace.workspaceFolders?.[0];
67+
return firstWorkspaceFolder?.uri.fsPath ?? '';
68+
}
2169
}

0 commit comments

Comments
 (0)