Skip to content

Commit

Permalink
Merge pull request #2045 from BetterThanTomorrow/2043-sort-connect-pr…
Browse files Browse the repository at this point in the history
…ojects

Sort REPL connect/jack-in projects
  • Loading branch information
PEZ authored Jan 28, 2023
2 parents 3946ea6 + 78e744b commit fd6efa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes to Calva.

- [Sort aliases for deps.edn projects](https://github.com/BetterThanTomorrow/calva/issues/2035)
- Fix: [Indenter and formatter not in agreement about some forms](https://github.com/BetterThanTomorrow/calva/issues/2032)
- [Sort pre-selected project at the top in REPL connect menu](https://github.com/BetterThanTomorrow/calva/issues/2043)

## [2.0.327] - 2023-01-26

Expand Down
17 changes: 16 additions & 1 deletion src/project-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export async function pickProjectRoot(
return rootToUri(uris[0]);
}

const project_root_options = uris.map((root_or_uri) => {
const sorted = sortPreSelectedFirst(uris, selected);

const project_root_options = sorted.map((root_or_uri) => {
let uri;
let reason;
if (root_or_uri instanceof vscode.Uri) {
Expand Down Expand Up @@ -169,3 +171,16 @@ export async function pickProjectRoot(

return selected_root?.value;
}

function sortPreSelectedFirst(uris: (ProjectRoot | vscode.Uri)[], selected: vscode.Uri) {
return [...uris].sort((a, b) => {
if (!selected) {
return 0;
}
return rootToUri(a).fsPath === selected.fsPath
? -1
: rootToUri(b).fsPath === selected.fsPath
? 1
: 0;
});
}

0 comments on commit fd6efa2

Please sign in to comment.