calva

Max 2025-06-25T12:56:11.403579Z

I just filed https://github.com/BetterThanTomorrow/calva/issues/2872, which has been an issue that's been bugging me for a while. I'm happy to take a shot at a PR if it's something straightforward and you can point me in the right direction. If not, let me know if there's anything I can do to assist!

pez 2025-06-25T13:12:52.872229Z

Thanks! I commented on the issue.

2025-06-25T22:11:33.254179Z

I gather from the f1 menu's gear button that the command is editor.action.addCommentLine, which is to say, not part of Calva?

pez 2025-06-25T22:22:16.239539Z

It’s a VS Code built-in command.

Max 2026-02-13T22:42:11.342039Z

@pez thoughts on this?

pez 2026-02-13T23:05:02.027349Z

It’s quite strange why Calva makes a difference. I don’t really have a clue. But it won’t matter this time because @jonurnieta is introducing a structural toggle-comment command: https://github.com/BetterThanTomorrow/calva/pull/3047

Max 2026-02-12T04:09:24.041689Z

I know this thread has been on ice for a long time, but this issue has been annoying me again so I'm making an attempt to revive it. For those just tuning in, here's the issue I want to fix. Say you have this form (where | is the cursor):

(assoc {}
       |
       :foo
       1)
If you trigger editor.action.commentLine, you'd like to get this:
(assoc {}
       ;; |
       :foo
       1)
What you get instead is this:
(assoc {}
      ;;  |
       :foo
       1)
I've previously determined that this behavior is definitely coming from vscode, not calva. But I discovered today that calva does produce the correct behavior in this scenario:
(defn a []
  |
  b)
And without calva, it does this instead:
(defn a []
;;   |
  b)
That means Calva's definitely doing something in the defn scenario, and could be changed to do something in the assoc scenario. Any ideas on where in Calva's code it's overriding vscode's default behavior in the defn case?

pez 2026-02-12T09:05:43.761189Z

I’m thinking that a way to deal with it is to add a command to calva for commenting lines and then users can override the default shortcut to use Calva’s command instead. Similar to how you can bind ; to our custom command for inserting ;, I have this in my keybindings.json:

{
    "command": "paredit.insertSemiColon",
    "key": ";",
    "when": "calva:keybindingsEnabled && editorLangId == clojure && editorTextFocus && paredit:keyMap == strict && !editorReadOnly && !editorHasMultipleSelections && !calva:cursorInComment"
  },

jramosg 2026-02-12T09:21:25.623909Z

what do you think about calling getIndent for the commented lines? it could be a calva command that runs with same shortcut as editor.action.commentLine Another option is , without Calva command, adding a fn to fix commented line indents after comment toggle is done

pez 2026-02-12T12:00:06.557909Z

If we can detect when comment toggle is done, that would be cleanest. But only if there is a clean way to detect this. Which I doubt a bit that there is. So separate calva command for toggling comments on a line is the way to go, I think. And this command should use the existing insertSemoColon strategy so that the toggle is structural.

pez 2026-02-12T12:30:21.812989Z

The fact that we want the toggle to be structural is, alone, pointing us towards a custom command, I think.

jramosg 2026-02-12T12:33:12.288699Z

for detecting when toggle comment is done, I think there is not direct way of doing that, it could be done on edit checking if line starts with ";"

jramosg 2026-02-12T12:34:21.555649Z

otherwise a calva command that acts like editor.action.commentLine + indents could solve it

pez 2026-02-12T12:43:52.251399Z

> a calva command that acts like editor.action.commentLine + indents could solve it Like a structural editor.action.commentLine , right? 😃

pez 2026-02-12T12:44:49.965569Z

It would be extremely messy to check if edits starts with ; and decide if this is because of toggle.

Max 2026-02-12T14:28:12.134399Z

I'm still curious about what's causing the correct indenting in the defn case. It must be something in calva because when calva is disabled, it indents wrong. Any ideas?

Max 2026-02-12T14:30:17.526609Z

Fwiw if I hit tab it moves the ;; to the correct indentation, so calva’s formatter does work correctly when prompted to do so. You still end up with extra spaces after the ;; though

pez 2026-02-12T14:38:05.115079Z

I think it could be Calva’s language configurations that make defn work. It is the default 2-space indent that we would get if we didn’t also do dynamic indentation.

Max 2026-02-12T14:44:27.477499Z

I'll look into that, I was looking at calva’s language definition and the default clojure one side by side and nothing initially jumped out at me

pez 2026-02-12T14:54:16.252569Z

Yeah, didn’t remember about the default Clojure one, tbh. But Calva has a dynamic language definition provider. Was that the one you looked at?

pez 2026-02-12T14:55:04.218039Z

I don’t recall how dynamic. Just that it isn’t in json, but in typescript.

Max 2026-02-12T14:55:41.728789Z

No, I was looking at the static one that’s checked into calva. Where would I go looking for the dynamic one?

pez 2026-02-12T14:59:38.506029Z

Maybe I am misleading you with calling it language definition. I mean this thing in extension.ts:

function getLanguageConfiguration(): vscode.LanguageConfiguration {
  const languageConfiguration = {
    onEnterRules: isOldIndentEngineInPlay()
      ? [
          // When cljfmt is used for indenting, disable all vscode default indentation
          // (By outdenting a lot, which is the only way I have found that works)
          {
            beforeText: /.*/,
            action: {
              indentAction: vscode.IndentAction.Outdent,
              removeText: Number.MAX_VALUE,
            },
          },
        ]
      : [],
  };
  console.log('Issue #2071: languageConfiguration', languageConfiguration);
  console.log('Issue #2071: formatOnType?', config.formatOnTypeEnabled());
  console.log(
    'Issue #2071: newIndentEngine?',
    vscode.workspace.getConfiguration('calva.fmt').get('newIndentEngine')
  );
  return languageConfiguration;
}

Max 2026-02-12T17:10:37.165229Z

As far as I can tell, the language configuration calva is setting is just this: {onEnterRules: []}. I'm not sure how that would result in the behavior we're seeing? That must be merged with some kind of existing language configuration, like the one in calva's static language-configuration.json, right?

Max 2026-02-12T17:11:56.956969Z

It appears that the only difference between calva's language-configuration.json and the default vscode one is that calva's sets wordPattern