Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a prompt if we have more than one solution file #6132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
"View Debug Docs": "View Debug Docs",
"Ignore": "Ignore",
"Run and Debug: A valid browser is not installed": "Run and Debug: A valid browser is not installed",
"Your workspace has multiple Visual Studio Solution files; please select one to get full IntelliSense.": "Your workspace has multiple Visual Studio Solution files; please select one to get full IntelliSense.",
"Choose": "Choose",
"Choose and set default": "Choose and set default",
"Do not load any": "Do not load any",
"Restart Language Server": "Restart Language Server",
"pipeArgs must be a string or a string array type": "pipeArgs must be a string or a string array type",
"Name not defined in current configuration.": "Name not defined in current configuration.",
Expand Down
8 changes: 5 additions & 3 deletions src/lsptoolshost/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ async function completionComplexEdit(
}
}

async function openSolution(languageServer: RoslynLanguageServer): Promise<void> {
async function openSolution(languageServer: RoslynLanguageServer): Promise<vscode.Uri | undefined> {
if (!vscode.workspace.workspaceFolders) {
return;
return undefined;
}

const solutionFiles = await vscode.workspace.findFiles('**/*.sln');
Expand All @@ -159,6 +159,8 @@ async function openSolution(languageServer: RoslynLanguageServer): Promise<void>
});

if (launchTarget) {
languageServer.openSolution(vscode.Uri.file(launchTarget.target));
const uri = vscode.Uri.file(launchTarget.target);
languageServer.openSolution(uri);
return uri;
}
}
26 changes: 26 additions & 0 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,32 @@ export class RoslynLanguageServer {
if (solutionUris) {
if (solutionUris.length === 1) {
this.openSolution(solutionUris[0]);
Copy link
Member

@genlu genlu Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm a bit late to the party. Since we are trying to improve this area, could we also show the solution picker if default solution can't be opened and there's other solution files in the hierarchy?

[Error - 1:58:27 PM] [LanguageServerHost]Microsoft.Build.Exceptions.InvalidProjectFileException: The project file could not be loaded. Could not find file 'c:\Users\gel\source\repos\ConsoleApp16\ConsoleApp16.sln'. c:\Users\gel\source\repos\ConsoleApp16\ConsoleApp16.sln

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@genlu We could, although I'm still curious how you got an error like that in the first place. 😄

} else if (solutionUris.length > 1) {
// We have more than one solution, so we'll prompt the user to use the picker.
const chosen = await vscode.window.showInformationMessage(
vscode.l10n.t(
'Your workspace has multiple Visual Studio Solution files; please select one to get full IntelliSense.'
),
{ title: vscode.l10n.t('Choose'), action: 'open' },
{ title: vscode.l10n.t('Choose and set default'), action: 'openAndSetDefault' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other option:
'Choose default'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but decided to make it a bit clearer the second button is first button plus something more. But if we have to save room this would proably be where I'd do it.

{ title: vscode.l10n.t('Do not load any'), action: 'disable' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other option:
'Disable load'

);

if (chosen) {
if (chosen.action === 'disable') {
vscode.workspace.getConfiguration().update('dotnet.defaultSolution', 'disable', false);
} else {
const chosenSolution: vscode.Uri | undefined = await vscode.commands.executeCommand(
'dotnet.openSolution'
);
if (chosen.action === 'openAndSetDefault' && chosenSolution) {
const relativePath = vscode.workspace.asRelativePath(chosenSolution);
vscode.workspace
.getConfiguration()
.update('dotnet.defaultSolution', relativePath, false);
}
}
}
} else if (solutionUris.length === 0) {
// We have no solutions, so we'll enumerate what project files we have and just use those.
const projectUris = await vscode.workspace.findFiles(
Expand Down
Loading