Skip to content

Commit c97b62b

Browse files
authored
Remove check for projectPath for resolveDebugConfiguration (#6754)
* Remove check for projectPath for resolveDebugConfiguration This PR allows projectPath to be null for resolveDebugConfigurationWithLaunchConfigurationService as that service can now handle it being null. Also updating error messaging an ensuring they are localized.
1 parent 0bbd442 commit c97b62b

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

l10n/bundle.l10n.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.": "Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.",
44
"Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.": "Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.",
55
"Does not contain .NET Core projects.": "Does not contain .NET Core projects.",
6+
"'{0}' was not set in the debug configuration.": "'{0}' was not set in the debug configuration.",
7+
"'{0}' request is not supported for the '{1}' configuration.": "'{0}' request is not supported for the '{1}' configuration.",
8+
"'{0}' was not provided in the debug configuration.": "'{0}' was not provided in the debug configuration.",
9+
"Can not find an opened workspace folder. Please open a folder before starting to debug with a '{0}' configuration'.": "Can not find an opened workspace folder. Please open a folder before starting to debug with a '{0}' configuration'.",
10+
"No launchable target found.": "No launchable target found.",
611
"No launchable target found for '{0}'": "No launchable target found for '{0}'",
712
"Cannot resolve .NET debug configurations. The server is still initializing or has exited unexpectedly.": "Cannot resolve .NET debug configurations. The server is still initializing or has exited unexpectedly.",
813
"Unable to determine a configuration for '{0}'. Please generate C# debug assets instead.": "Unable to determine a configuration for '{0}'. Please generate C# debug assets instead.",

src/lsptoolshost/services/IDotnetDebugConfigurationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface IDotnetDebugConfigurationServiceResult {
2323

2424
export interface IDotnetDebugConfigurationService {
2525
resolveDebugConfigurationWithLaunchConfigurationService(
26-
projectPath: string,
26+
projectPath: string | undefined,
2727
debugConfiguration: vscode.DebugConfiguration,
2828
token?: vscode.CancellationToken
2929
): Promise<IDotnetDebugConfigurationServiceResult>;

src/shared/dotnetConfigurationProvider.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function resolveWorkspaceFolderToken(projectPath: string, folderPath: string): s
5555
}
5656

5757
export class DotnetConfigurationResolver implements vscode.DebugConfigurationProvider {
58+
static dotnetType = 'dotnet';
59+
5860
constructor(
5961
private workspaceDebugInfoProvider: IWorkspaceDebugInformationProvider,
6062
private dotnetWorkspaceConfigurationProvider: DotnetWorkspaceConfigurationProvider
@@ -73,12 +75,24 @@ export class DotnetConfigurationResolver implements vscode.DebugConfigurationPro
7375
}
7476

7577
if (debugConfiguration.request !== 'launch') {
76-
throw new Error(`'${debugConfiguration.request}' is unsupported.`);
78+
if (!debugConfiguration.request) {
79+
throw new Error(vscode.l10n.t("'{0}' was not set in the debug configuration.", 'request'));
80+
} else {
81+
throw new Error(
82+
vscode.l10n.t(
83+
"'{0}' request is not supported for the '{1}' configuration.",
84+
debugConfiguration.request,
85+
DotnetConfigurationResolver.dotnetType
86+
)
87+
);
88+
}
7789
}
7890

79-
let projectPath: string = debugConfiguration.projectPath;
80-
if (folder && projectPath) {
81-
projectPath = resolveWorkspaceFolderToken(projectPath, folder.uri.fsPath);
91+
let projectPath: string | undefined = debugConfiguration.projectPath;
92+
if (folder) {
93+
if (projectPath) {
94+
projectPath = resolveWorkspaceFolderToken(projectPath, folder.uri.fsPath);
95+
}
8296

8397
const dotnetDebugServiceProxy = await getServiceBroker()?.getProxy<IDotnetDebugConfigurationService>(
8498
Descriptors.dotnetDebugConfigurationService
@@ -96,6 +110,11 @@ export class DotnetConfigurationResolver implements vscode.DebugConfigurationPro
96110
throw new UnavaliableLaunchServiceError();
97111
}
98112
} catch (e) {
113+
if (!projectPath) {
114+
throw new LaunchServiceError(
115+
vscode.l10n.t("'{0}' was not provided in the debug configuration.", 'projectPath')
116+
);
117+
}
99118
if (e instanceof UnavaliableLaunchServiceError) {
100119
return await this.resolveDebugConfigurationWithWorkspaceDebugInformationProvider(
101120
folder,
@@ -109,15 +128,20 @@ export class DotnetConfigurationResolver implements vscode.DebugConfigurationPro
109128
} finally {
110129
dotnetDebugServiceProxy?.dispose();
111130
}
131+
} else {
132+
throw new Error(
133+
vscode.l10n.t(
134+
"Can not find an opened workspace folder. Please open a folder before starting to debug with a '{0}' configuration'.",
135+
DotnetConfigurationResolver.dotnetType
136+
)
137+
);
112138
}
113-
114-
return debugConfiguration;
115139
}
116140

117141
//#endregion
118142

119143
private resolveDotnetDebugConfigurationServiceResult(
120-
projectPath: string,
144+
projectPath: string | undefined,
121145
result: IDotnetDebugConfigurationServiceResult
122146
): vscode.DebugConfiguration {
123147
if (result.error) {
@@ -135,7 +159,11 @@ export class DotnetConfigurationResolver implements vscode.DebugConfigurationPro
135159

136160
const debugConfigArray = result.configurations;
137161
if (debugConfigArray.length == 0) {
138-
throw new LaunchServiceError(vscode.l10n.t("No launchable target found for '{0}'", projectPath));
162+
if (!projectPath) {
163+
throw new LaunchServiceError(vscode.l10n.t('No launchable target found.'));
164+
} else {
165+
throw new LaunchServiceError(vscode.l10n.t("No launchable target found for '{0}'", projectPath));
166+
}
139167
}
140168
if (debugConfigArray.length == 1) {
141169
return debugConfigArray[0];

0 commit comments

Comments
 (0)