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

feat(vscode-avalonia): prompt users to choose a solution file if workspace contains multiple #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/vscode-avalonia/src/services/solutionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as os from "os";
import * as path from "path";

import * as vscode from "vscode";
//import "vscode"; // required for 'using' statement. Type 'Disposable' must be in global namespace.

import * as sln from "../models/solutionModel";
import { spawn } from "child_process";
Expand Down Expand Up @@ -69,11 +70,33 @@ function updateSolutionModel(context: vscode.ExtensionContext, jsonContect: stri
context.workspaceState.update(AppConstants.solutionData, data);
}

/**TODO: Try getting 'current' solution file from exports (or language servers) of
* ms-dotnettools.csharp (CSharpExtensionExports | OmnisharpExtensionExports),
* Ionide.Ionide-fsharp (prefers OmniSharp when available),
* ms-dotnettools.csdevkit (basically Roslyn LSP with VS features)
*/
async function getSolutionFile(): Promise<string | undefined> {
const filePattern = "**/*.sln";
const files = await vscode.workspace.findFiles(filePattern);

if (files.length > 0) {
if (files.length > 1) {
// todo: refactor try-catch-finally to `using` statement when electron and vscode support [ECMAScript Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
const tokenSource = new (class extends vscode.CancellationTokenSource { /* [Symbol.dispose] = () => { this.dispose(); }; */ });
try {
return await vscode.window.showQuickPick(
files.map((uri) => uri.fsPath),
{
title: 'Choose Solution File',
canPickMany: false
} as vscode.QuickPickOptions,
tokenSource.token
); // may be `undefined`. Why? User cancellation?
} catch { }
finally {
tokenSource.dispose();
}
}
return files[0].fsPath;
}

Expand Down