Calling commands outside of magit buffer doesn't work?
The-Compiler opened this issue · comments
Not sure if this is a bug or just me doing something wrong, so I'm opening it as issue for now - feel free to convert it to a discussion if you prefer!
I'm trying to build a git sub-menu in VSpaceCode which lets me run magit commands without having to go to the magit status/dispatch buffer first:
With a couple of tweaks, I end up with this:
This seems to work fine for magit.committing
. For any other commands, I get e.g. "Error: command 'magit.diffing' not found.". However, all commands start working as soon as I run magit.committing
(or magit.status
/magit.dispatch
and close the magit buffer).
I'm guessing this is due to the activationEvents
in package.json
which doesn't include those commands.
What do you think about my use-case? Given that it works fine (other than the lazy activation), would it be okay to add all magit commands to those activation events?
It's ok by me,
Those commands could also be made available in the vscode command pallete.
package.json
"menus": {
"commandPalette": [
As they don't need a status buffer to work. :)
They already are in there, but with a "when": "editorLangId == magit"
- I assume that could be removed instead?
Additionally, a couple of commands don't seem to work that way:
magit.apply-at-point
magit.stage
magit.unstage
magit.stage-all
magit.unstage-all
The first 3 show a menu when run in the magit buffer without anything relevant at point. The latter two stage/unstage all files when executed there. But when any of those is run outside of the magit buffer, nothing seems to happen.
I assume this affects all commands using CommandPrimer.primeRepoAndView
, but the others probably are indeed useless without a respective item at point.
For stage-all
and unstage-all
I think this is an oversight - magitStageAll
and magitUnstageAll
don't need their currentView
arguments at all.
For the others, the commands already seem to handle the case where selectedView
is not one of the expected types, but they'd somehow need to handle the case where currentView
is not a magit buffer. What do you think about adding a new argument to primeRepoAndView
which controls whether the underlying function handles currentView
being null
(or undefined
?), and adjusting apply-at-point
, stage
and unstage
to handle that case?
Happy to submit a PR for all this - pretty much the first time I'd be doing something non-trivial in typescript, but the code looks quite clean from what I've seen so far!
Released in v0.6.16