From fc86cf1dc09c29fe6e7c337a65c380d5fe019ccc Mon Sep 17 00:00:00 2001 From: JackBoosY <398808571@qq.com> Date: Sat, 18 Nov 2023 14:16:44 +0800 Subject: [PATCH] set target / host triplet use selection --- package.json | 2 +- src/configuration.ts | 90 +++++++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index cfabf26..9792d54 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "icon": "images/vcpkg-logo.png", "publisher": "JackBoosY", "license": "MIT", - "version": "2.0.6", + "version": "2.0.7", "engines": { "vscode": "^1.76.0" }, diff --git a/src/configuration.ts b/src/configuration.ts index 6b340c9..81c1582 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -633,44 +633,72 @@ export class ConfigurationManager implements vscode.Disposable vscode.window.showInformationMessage('Current triplet is: ' + this.getCurrentTriplet()); } - async setTargetTriplet() + private getAllSupportedTriplets() { - vscode.window.showInputBox().then(async result => { - if (result?.length) + let triplets = []; + let vcpkgPath = workspace.getConfiguration('vcpkg').get(this._vcpkgPathConfig); + + // for official triplets + let officialTriplets = fs.readdirSync(vcpkgPath + '/triplets'); + for (let i = 0; i < officialTriplets.length; i++) + { + let curr = officialTriplets[i]; + if (curr.indexOf('.cmake') !== -1) { - // the correct triplet name is "-" - if (result.match(".+\-.+") !== null) - { - this.updateVcpkgSetting(this._targetTripletConfig, result); - this.logInfo('update target triplet to: ' + result); - vscode.window.showInformationMessage('Update target triplet to: ' + result); - } - else - { - vscode.window.showErrorMessage('Invalide triplet name.'); - } + triplets.push({label: curr.substring(0, curr.indexOf('.cmake')), description: 'official triplet'}); + } + } + + // for unofficial triplets + let unofficialTriplets = fs.readdirSync(vcpkgPath + '/triplets/community'); + for (let i = 0; i < unofficialTriplets.length; i++) + { + let curr = unofficialTriplets[i]; + if (curr.indexOf('.cmake') !== -1) + { + triplets.push({label: curr.substring(0, curr.indexOf('.cmake')), description: 'unofficial triplet'}); } - }); + } + + // TODO: for custom triplets + + return triplets; + } + + async setTargetTriplet() + { + let triplets = this.getAllSupportedTriplets(); + if (triplets.length === 0) + { + vscode.window.showErrorMessage('Please check your vcpkg path first.'); + return; + } + + let result = await vscode.window.showQuickPick(triplets, {canPickMany: false, placeHolder: "Choose a triplet"}); + if (result !== undefined) + { + this.updateVcpkgSetting(this._targetTripletConfig, result.label); + this.logInfo('update target triplet to: ' + result.label); + vscode.window.showInformationMessage('Update target triplet to: ' + result.label); + } } async setHostTriplet() { - vscode.window.showInputBox().then(async result => { - if (result?.length) - { - // the correct triplet name is "-" - if (result.match(".+\-.+") !== null) - { - this.updateVcpkgSetting(this._hostTripletConfig, result); - this.logInfo('update host triplet to: ' + result); - vscode.window.showInformationMessage('Update host triplet to: ' + result); - } - else - { - vscode.window.showErrorMessage('Invalide triplet name.'); - } - } - }); + let triplets = this.getAllSupportedTriplets(); + if (triplets.length === 0) + { + vscode.window.showErrorMessage('Please check your vcpkg path first.'); + return; + } + + let result = await vscode.window.showQuickPick(triplets, {canPickMany: false, placeHolder: "Choose a triplet"}); + if (result !== undefined) + { + this.updateVcpkgSetting(this._targetTripletConfig, result.label); + this.logInfo('update host triplet to: ' + result.label); + vscode.window.showInformationMessage('Update host triplet to: ' + result.label); + } } async getCurrentTriplet()