Skip to content

Commit

Permalink
fix(vscode-avalonia): prompt users to choose a solution file if works…
Browse files Browse the repository at this point in the history
…pace 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.
  • Loading branch information
BinToss committed Feb 7, 2024
1 parent e0cb3a6 commit c42184f
Showing 1 changed file with 23 additions and 0 deletions.
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, jsonContent: 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

0 comments on commit c42184f

Please sign in to comment.