From 4d6d05d6d5cfee921fcf599d4cbc29bdfd289df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Marc=C3=A8=20i=20Igual?= Date: Wed, 29 May 2024 18:15:16 +0200 Subject: [PATCH] Sort CMakeLists.txt by depth (#3789) * Sort CMakeLists.txt by depth * Add changes to CHANGELOG.md --------- Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com> --- CHANGELOG.md | 1 + src/cmakeProject.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d64e5130f..98ffd010a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Improvements: - Add the ability to debug install targets [#532](https://github.com/microsoft/vscode-cmake-tools/issues/532) - Add a "Don't Show Again" option in the select CMakeLists.txt. - Log error statement if the environmentSetupScript fails. [#3566](https://github.com/microsoft/vscode-cmake-tools/issues/3566) +- Sort CMakeLists.txt by depth during selection [#3789](https://github.com/microsoft/vscode-cmake-tools/pull/3789) [@jmigual](https://github.com/jmigual) - [Experiment] Improve CMake Tools experience when opening a folder [#3588](https://github.com/microsoft/vscode-cmake-tools/issues/3588) Bug Fixes: diff --git a/src/cmakeProject.ts b/src/cmakeProject.ts index 71407efdd..d0bf518ba 100644 --- a/src/cmakeProject.ts +++ b/src/cmakeProject.ts @@ -884,6 +884,15 @@ export class CMakeProject { label: util.getRelativePath(file, this.folderPath) + "/CMakeLists.txt", fullPath: file })) : []; + + // Sort files by depth. In general the user may want to select the top-most CMakeLists.txt + items.sort((a, b) => { + const aDepth = a.fullPath.split(path.sep).length; + const bDepth = b.fullPath.split(path.sep).length; + + return aDepth - bDepth; + }); + const browse: string = localize("browse.for.cmakelists", "[Browse for CMakeLists.txt]"); const dontAskAgain: string = localize("do.not.ask.again", "[Don't Show Again]"); items.push({ label: browse, fullPath: "", description: localize("search.for.cmakelists", "Search for CMakeLists.txt on this computer") });