comby icon indicating copy to clipboard operation
comby copied to clipboard

Extensions for VSCode, Vim and Emacs

Open autosquid opened this issue 4 years ago • 15 comments

Maybe we can have an extension for VSCode to provide a useful text replace tool.

autosquid avatar Sep 23 '19 02:09 autosquid

That would be wonderful. Let's use this issue to track progress. Perhaps external contributors may be interested in implement these features, especially since others may be more familiar with the editors. Right now there are a few core features planned in the roadmap, which may get updated with editor extensions over time.

rvantonder avatar Sep 23 '19 04:09 rvantonder

Onivim might be a good target editor as well. It is written in Reason so it might be an easier path to integration.

tjbell avatar Oct 08 '19 17:10 tjbell

@tjbell Onivim will (or maybe already does) support vscode extensions.

I've started writing a vscode extension. There are a lot of choices I don't like, but vscode doesn't allow to write a nice search and replace extension. Its own search-and-replace is kinda "hardcoded". I published the extension, here I used one of the favicon from comby.dev as logo. Any PR is welcome, or issue. And also, I haven't licensed it yet, and I don't really know how I should proceed with regard to the logo there's probably a copyright or something. Note that I just worked a few hours on this, it's really a prototype, I'm not even cleaning properly the strings for the command line call. I'm mostly exploring how this should be done

giltho avatar Nov 25 '19 01:11 giltho

@giltho: thanks for posting your update here. This is really neat, especially the selective replace parts in the UI!

I used one of the favicon from comby.dev as logo.

That's fine. I'll update CONTRIBUTING.md to make things around this sort of thing clear :)

Any PR is welcome, or issue. And also, I haven't licensed it yet, ... Note that I just worked a few hours on this. I'm mostly exploring how this should be done.

Sounds good. Keep us posted as you develop a better idea of how you plan to go about things.

rvantonder avatar Nov 25 '19 08:11 rvantonder

@giltho I really like the extension, but I also need more instructions/examples for JavaScript from @rvantonder since I tried something like const :[x] = ':[y]'; and it does not match all constants that have string but pretty much everthing ???

st-schneider avatar Nov 26 '19 08:11 st-schneider

Hi @bm-stschneider -- please bring questions about usage and patterns over to the gitter channel.

rvantonder avatar Nov 26 '19 08:11 rvantonder

Hi! I really like this cool project. And I wrote simple wrapper for emacs - https://github.com/s-kostyaev/comby.el

s-kostyaev avatar Jun 23 '20 15:06 s-kostyaev

@s-kostyaev this is great. I'll add a section about editor support to the comby.dev site and link to this project.

rvantonder avatar Jun 24 '20 02:06 rvantonder

I think a Comby VSCode extension is crucial to get much more adoption. Also it ease the experience for existing comby users as well. I use https://comby.live quite a lot, similar to https://regexr.com/ when writing / testing regular expressions. ~~However, translating the template into a bash command is kind of complicated~~ Just noticed the "Run in Terminal" button for the first time 😍 . Anyway, a proper integration into VSCode would be really useful IMO.

vscode doesn't allow to write a nice search and replace extension. Its own search-and-replace is kinda "hardcoded".

Does it have to be integrated into the native search and replace bar? Sure, this would be nice, but what if Comby adds a new panel like shown in this quick mockup.

Group 2

stefanbuck avatar Nov 05 '20 21:11 stefanbuck

Would be great to do that. When I wrote the "extension" (very much in quote since it's barely a proof of concept...), such custom panels weren't possible.

I think it is still the case that, so far, the only custom panel you can create is a tree view. Tree views don't have inputs... VScode doesn't expose an API to extend the search panel either, so I don't see much of an elegant solution for now.

The perfect solution would be to make the search view customisable in my opinion. That would mean writing a big PR to VSCode, but I'm pretty sure the VSCode team would be happy merging any elegant solution. If I ever have time, I'll probably try, but right now I can't :(

By the way, @rvantonder, I haven't pushed to the extension for quite a while, I don't know when I'll have time again to work on it. If at any moment you wish that I transfer the ownership of the project or remove the extension or any other thing, please do tell me :) I do wish to take any action that you feel is the best for comby

giltho avatar Nov 05 '20 22:11 giltho

Hello there, I started to integrate Comby into my workflow too, and I wrote a set of rules for Lisp (only Common Lisp so far) with an integration with Emacs. It differs from comby.el in that the latter gives you a prompt to write your own rules on the fly, while colisper comes with a set of rules for CL, an interface to select them, and a script to run them on the terminal. It needs more work but I use it.

vindarel avatar Nov 05 '20 23:11 vindarel

@vindarel Hi! You can use comby.el not only for interactive usage, but also as library to exucte set of rules. I was thinking of creating package for simple golang refactoring on top of comby.el, but I have found already implemented features inside gopls.

s-kostyaev avatar Nov 06 '20 03:11 s-kostyaev

I'll look into it then, thanks.

vindarel avatar Nov 06 '20 10:11 vindarel

I think it's possible nowadays to add a WebView to the sidebar in VS Code, i.e. you could implement an interface similar to the search sidebar in HTML (even optimize it for comby, e.g. use multi-line text inputs): https://github.com/microsoft/vscode/commit/6b083b455be2c60c4df6104896cf9ee5af127cda And maybe the results could actually use a tree view that opens diffs for each file?

felixfbecker avatar Nov 06 '20 10:11 felixfbecker

Hi all, I guess that more reliable approach will be use select-n-replace-with-piped-output method.

For VS Code there is that extension available: https://github.com/popurax/vscode-filtertext It has the idea, but does not work properly: it should pipe selection to any particular shell or binary, and with flags also. I'll try to repair that extension in spare time though.

For Notepad++ there is a NPPExec plugin that do all right.


I do it on Win10 machine with Ubuntu 20.04 on top of WSL2, pwsh it's just a name for PowerShell7 given by MS.

NPPExec script is this (taken from https://community.notepad-plus-plus.org/topic/16158/is-it-possible-to-run-text-through-an-external-program/3):

cmd.exe /c exit %RANDOM%	  // cannot access $(SYS.RANDOM) directly through NppExec, but can tell cmd.exe to return it as a value
set destfile = $(SYS.TEMP)\NppFilterDestinatino_$(EXITCODE).tmp  // create random destfile name
set sourcefile = $(SYS.TEMP)\NppFilterSource_$(EXITCODE).tmp     // create associated sourcefile name
sel_saveto "$(sourcefile)" :a	                                                           // save selection to the sourcefile	(use :a to save as ansi, to prevent unicode prefix ÿþ getting embedded)
pwsh c:\yer_path\script.ps1  "$(destfile)" "$(sourcefile)" 	//
sel_loadfrom "$(destfile)"	 
pwsh -command "Remove-Item -Force '$(sourcefile)'"
pwsh -command "Remove-Item -Force "$(destfile)"  

And the .ps1-script body will be like:

$dest_file   = $args[0]
$source_file = $args[1] 
  
$cmd0 = "/mnt/c/yer_path/shell-script.sh" # or whatever path you enjoy to have there
$listo=@( 
    $cmd0 
    $dest_file.Replace('\', '\\')
    $source_file.Replace('\', '\\')
    (Get-Content -Path $source_file -Raw)
)
# .Replace('\', '\\') - 'cause single slash get lost during arg-pass

Start-Process   wsl -ArgumentList $listo -NoNewWindow -PassThru -Wait | Out-Null

WSL script be like:

# mutating windows-path to wsl-mnt path
destfile=$(wslpath -a "$1")
srcfile=$(wslpath -a "$2") 

# whatever template and rule you wanted, by now it just make 'a s d f' -> 's d f'
comby_res=$(comby 'a :[1]' ':[1]' -f $srcfile -stdout -matcher .generic) 

echo -e "\n [ Here it goes ]" > $destfile 
echo "$comby_res" >> $destfile
echo -e " [ over. ]" >> $destfile

With a setup like that you can call literally any scenario, not only with comby, but mixing comby with python, semgrep, sed, awk, whatever. And those scripts may just be called by their purposes, like 'remove null-checks' or 'refactor my fancy stuff into proper code-style approved code-piece'.

Of cource in that manner you can run this on any shells and machines, not just Win10+pwsh+wsl.


So, in my opinion the extension for VS Code \ vim \ other should work in the same fashion. May be with proper sctucture of final .sh-scripts logic and special tab-layout for editing this. It will be much more flexible and more in the spirit of comby than just comby-extension.

moonbaseDelta avatar Apr 01 '21 00:04 moonbaseDelta