Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Git Stage action to editor title (#187893) #190661

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gjsjohnmurray
Copy link
Contributor

This PR closes #187893

For git users it adds a Stage button to the editor title of a file with unstaged changes.

image

To achieve this I first added to core a new context key scmActiveResourceGroupMemberships which is an array of string ids of the resource groups the active resource is present in. The built-in Git extension uses this to contribute its Stage command to the title of an editor with unstaged changes.

I had to work around a limitation of the where-clause's in operator, which can only search an array-type context key for a value that matches another context key, not a constant.

I also used fractionally-negative order suffixes on the added command git.stage and its already-existing cousin git.openChange so they are adjacent but don't precede any editor/title/run contribution (screenshot shows this coming from the vscode-mock-debug extension).

If any existing users are upset by this button appearing they can easily use its context menu to demote it to the ... menu.

@gjsjohnmurray
Copy link
Contributor Author

/assign @lszomoru

@gjsjohnmurray
Copy link
Contributor Author

Updated from main and ready for your consideration @lszomoru

@gjsjohnmurray
Copy link
Contributor Author

@lszomoru any thoughts yet about this PR, which I submitted last August in response to you tagging the associated issue as "help wanted"?

@irvnriir
Copy link

I think that this requires ability to hide the actions from the More Actions menu too. Currently, hiding buttons on this toolbar puts them to the menu, that becomes an issue if custom Extension fills that menu with custom items.

@gjsjohnmurray
Copy link
Contributor Author

Rebased to main then force-pushed to resolve complex conflict.

Also fixed Command Palette Git: Stage Changes not working for an untracked file if "git.untrackedChanges": "separate".

@lszomoru lszomoru added the git GIT issues label Dec 1, 2024
@lszomoru
Copy link
Member

Sorry for not getting back to you on this until now.

To achieve this I first added to core a new context key scmActiveResourceGroupMemberships which is an array of string ids of the resource groups the active resource is present in. The built-in Git extension uses this to contribute its Stage command to the title of an editor with unstaged changes.

This is problematic from a performance perspective since you can have a large number of changed resources and we do not want push all this information from the git extension to core as a context key. We already have commands contributed by the git extension git.stageChanges and git.stageFile so we should find a way to surface these in the editor toolbar. We do have new API on core that "attaches" diff information to a TextEditor so maybe that is something that we could use. Let me think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
git GIT issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git - Allow staging a file without actually going to the git view
4 participants