From 03aef481f272390dcf05c96419bc7d71c436cc47 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Wed, 7 Feb 2024 06:55:14 -0800 Subject: [PATCH] feat(vscode-avalonia): prompt users to choose a solution file if workspace contains multiple Commented code will not work until tc39/proposal-explicit-resource-management formally part of the ES. It can be compiled with ESNext, but it not supported in VSCode's runtime. --- .../src/services/solutionParser.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/vscode-avalonia/src/services/solutionParser.ts b/src/vscode-avalonia/src/services/solutionParser.ts index 308c21e..bbdac95 100644 --- a/src/vscode-avalonia/src/services/solutionParser.ts +++ b/src/vscode-avalonia/src/services/solutionParser.ts @@ -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"; @@ -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 { 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; }