Skip to content

Commit

Permalink
Merge branch dev into published
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Sep 29, 2024
2 parents 335af4e + 1b052df commit fa3daa6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changes to Calva.

## [Unreleased]

## [2.0.477] - 2024-09-29

- Fix: [Global custom repl command keys override workspace dittos, should be the other way around](https://github.com/BetterThanTomorrow/calva/issues/2640)

## [2.0.476] - 2024-09-28

- Fix: [Formatting and some pretty printing croaks on new Clojure 1.12.0 syntax](https://github.com/BetterThanTomorrow/calva/issues/2637)
Expand Down
8 changes: 3 additions & 5 deletions docs/site/custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ There are also substitutions available, which will take elements from the curren

## User and Workspace Settings

Settings from your User (global) level and the workspace are merged.
Settings from your User (global) level and the workspace are concatenated. Except for the `key` field, are merged.

With these **User** settings:

Expand Down Expand Up @@ -89,9 +89,7 @@ And these **Workspace** settings:

```

Issuing **Run Custom REPL Command** will then render this VS Code menu:

![](images/custom-command-menu.png)
Issuing **Run Custom REPL Command** will then render a VS Code menu with all the commands, where the Workspace configured commands will be listed first.

The default keyboard shortcut for the command is `ctrl+alt+space space`. (Beware: on MacOS it may conflict with the default shortuct for Input Sources - Select next source in Input menu.)

Expand All @@ -103,7 +101,7 @@ There are four ways to bind shortcuts to custom commands:
* The digits `0` through `9`
* The English letters `a` through `z`
* Arrow keys `right`, `left`, `up`, or `down`
* One of `tab`, `backspace`, `,`, `.`, or `-`
* One of `tab`, `backspace`, `,`, `.`, or `-`
2. Bind `calva.runCustomREPLCommand` to a shortcut with whatever code you want to evaluate in the `args` slot. You have access to the substitution variables here as well.
3. Bind `calva.runCustomREPLCommand` to a keyboard shortcut referencing the `key` of one of your `calva.customREPLCommandSnippets`. (If not using any of the `key`s mentioned in **1.**)
4. Bind `calva.runCustomREPLCommand` to a shortcut with a `customREPLCommandSnippets` in the `args` slot. You have access to the substitution variables here as well.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Calva: Clojure & ClojureScript Interactive Programming",
"description": "Integrated REPL, formatter, Paredit, and more. Powered by cider-nrepl and clojure-lsp.",
"icon": "assets/calva.png",
"version": "2.0.476",
"version": "2.0.477",
"publisher": "betterthantomorrow",
"author": {
"name": "Better Than Tomorrow",
Expand Down
30 changes: 17 additions & 13 deletions src/custom-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR
const workspaceSnippets = getConfig().customREPLCommandSnippetsWorkspace;
const workspaceFolderSnippets = getConfig().customREPLCommandSnippetsWorkspaceFolder;
let snippets = [
...(globalSnippets ? globalSnippets : []),
...(workspaceSnippets ? workspaceSnippets : []),
...(workspaceFolderSnippets ? workspaceFolderSnippets : []),
...(workspaceSnippets ? workspaceSnippets : []),
...(globalSnippets ? globalSnippets : []),
];
if (snippets.length < 1) {
snippets = getConfig().customREPLCommandSnippets;
}
const snippetsDict = {};
const snippetsKeyDict = {};
const snippetsMenuItems: string[] = [];
const snippetsMenuItems: vscode.QuickPickItem[] = [];
snippets.forEach((c: CustomREPLCommandSnippet) => {
const undefs = ['name', 'snippet'].filter((k) => {
return !c[k];
Expand All @@ -107,11 +106,16 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR
const entry = { ...c };
entry.ns = entry.ns ? entry.ns : editorNS;
entry.repl = entry.repl ? entry.repl : editorRepl;
const prefix = entry.key !== undefined ? `${entry.key}: ` : '';
const item = `${prefix}${entry.name} (${entry.repl})`;
const item = {
label: `${entry.key ? entry.key + ': ' : ''}${entry.name}`,
detail: `${entry.snippet}`,
description: `${entry.repl}`,
snippet: entry.snippet,
};
snippetsMenuItems.push(item);
snippetsDict[item] = entry;
snippetsKeyDict[entry.key] = item;
if (!snippetsDict[entry.key]) {
snippetsDict[entry.key] = entry;
}
});

if (configErrors.length > 0) {
Expand All @@ -123,20 +127,20 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR
return;
}

let pick: string;
let pick: any;
if (codeOrKey === undefined) {
// Called without args, show snippets menu
if (snippetsMenuItems.length > 0) {
try {
const pickResult = await util.quickPickSingle({
values: snippetsMenuItems.map((a) => ({ label: a })),
values: snippetsMenuItems,
placeHolder: 'Choose a command to run at the REPL',
saveAs: 'runCustomREPLCommand',
});
if (pickResult === undefined || pickResult.label.length < 1) {
return;
}
pick = pickResult.label; // Assign the label property to pick
pick = pickResult;
} catch (e) {
console.error(e);
}
Expand All @@ -151,10 +155,10 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR

if (pick === undefined) {
// still no pick, but codeOrKey might be one
pick = snippetsKeyDict[codeOrKey];
pick = snippetsDict[codeOrKey];
}

return pick !== undefined ? snippetsDict[pick] : { snippet: codeOrKey };
return pick ?? { snippet: codeOrKey };
}

export function makeContext(editor: vscode.TextEditor, ns: string, editorNS: string, repl: string) {
Expand Down

0 comments on commit fa3daa6

Please sign in to comment.