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 :pipe-all command that pipes entire document and ignores shell output #12298

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

the-dipsy
Copy link

@the-dipsy the-dipsy commented Dec 19, 2024

With the addition of the hopefully soon to be merged command expansion, we can call shell commands, passing them the current file name, line, and column numbers. In combination with the amazing shell piping commands this would allow building tools like GitHub Copilot and Copilot Chat, that can insert, replace, or describe code based on the entire file context.

I did not find a way to make the current content of the unsaved buffer available to such a program though, which kind of defeats the purpose of passing line and column numbers to shell commands.

My suggestion is this:

Add a :pipe-all command that acts like the :pipe-to command but pipes the entire buffer contents to the shell command.

@darshanCommits
Copy link

how is it different from selecting entire buffer (%) and then :pipe-to ?

@the-dipsy
Copy link
Author

how is it different from selecting entire buffer (%) and then :pipe-to ?

Oops, forgot to explain that part. The use case would be chaining this command with other commands inside a key mapping. Suppose we wanted to build an AI tool for refactoring the current selection. The tool would be informed about the buffer content using something like :pipe-all my-tool set-buffer first and then the selection would be piped through it with something like :pipe my-tool refactor --row %{linenumber} --col %{cursorcolumn}. Of course I don't want to loose the current selection by using % in the first step.

@darshanCommits
Copy link

Fair point, seems more convincing now.

@the-dipsy
Copy link
Author

An entirely different approach to my use case would be to implement a language server. As far as I can see, we do not currently support binding keys to custom language server commands though, right?

@carrascomj
Copy link

An entirely different approach to my use case would be to implement a language server. As far as I can see, we do not currently support binding keys to custom language server commands though, right?

LSP code actions are implemented, so you could attach the custom LSP to all files (or the desired ones) and press Space-a, but that does not preclude this feature in my opinion.

@the-dipsy
Copy link
Author

An entirely different approach to my use case would be to implement a language server. As far as I can see, we do not currently support binding keys to custom language server commands though, right?

LSP code actions are implemented, so you could attach the custom LSP to all files (or the desired ones) and press Space-a, but that does not preclude this feature in my opinion.

Yep, code actions are no acceptable solution for me. I am however considering building a language server that additionally listens on some socket, such that it can be remote controlled with normal :sh command calls. I haven't looked into whether helix accepts unsolicited ApplyEdit requests from the language server. In any case :pipe-all might be a useful addition.

@david-crespo
Copy link
Contributor

Cool idea. Another approach would be to use the filename command expansion to get your command to read the file contents from disk.

@the-dipsy
Copy link
Author

the-dipsy commented Dec 21, 2024

Cool idea. Another approach would be to use the filename command expansion to get your command to read the file contents from disk.

That would be a viable yet hacky workaround in combination with saving the file before every command execution.

That would not usually be what the user expects though. It also wouldn't work with buffers that are not yet associated with a file on disk.

@david-crespo
Copy link
Contributor

david-crespo commented Dec 21, 2024

Ah, true! I agree it would be strange to write the file first.

@RoloEdits
Copy link
Contributor

I wonder if there should be a %{buffer} variable instead? Would that solve your issue?

@the-dipsy
Copy link
Author

I wonder if there should be a %{buffer} variable instead? Would that solve your issue?

That was my initial idea as well. With larger files this would hit the operating systems maximum argument length though I think.

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

Successfully merging this pull request may close these issues.

5 participants