News for hackers. Stuff that matters.
Re:Comby - Structural code search and replace for every lang... by feanaro on Tuesday May 17, 2022 @03:09PM (#31415101)
A more interesting comparison than with Coccinelle is with semgrep (https://semgrep.dev/) since it also supports semantic/structural pattern matching over a number of languages, but also adds in a bunch of Boolean logic into the mix, as well as some more advanced semantic features like constant propagation.

Curious whether the teams behind these tools are aware of each other? I suppose it's unlikely that they're not.

Re:Comby - Structural code search and replace for every lang... by carlmr on Tuesday May 17, 2022 @06:00PM (#31416810)
Comby works with C++, which to me is a great advantage.
Re:Comby - Structural code search and replace for every lang... by fourthark on Tuesday May 17, 2022 @11:13PM (#31418867)
Semgrep has "experimental" support for C++. My understanding is that the major gap with both C & C++ support is macros, which are really hard.
Re:Comby - Structural code search and replace for every lang... by LesZedCB on Tuesday May 17, 2022 @03:47PM (#31415504)
yeah i just discovered semgrep a week ago! i'll have to download this and compare.

i found the CLI features lacking in semgrep (vs using a yaml config), so maybe this will have more support there.

Re:Comby - Structural code search and replace for every lang... by kretaceous on Tuesday May 17, 2022 @02:20PM (#31414509)
Okay wow. I didn't tools like this existed! There's been more than once where I've found myself in a situation like "find all code like this, change if this, delete if this". Regex can only get you so far.

Does someone know if this or something similar is available as a VSCode extension? It'd be fun to make one if not!

Re:Comby - Structural code search and replace for every lang... by vanesa- on Tuesday May 17, 2022 @07:06PM (#31417295)
Sourcegraph Community Manager here. You can use the Sourcegraph extension for VSCode [1] that would allow you to have the structural search powered by Comby (or literal or regular expression search) inside of VSCode.

You can't do batch changes[2] inside of VSCode yet, only via the Sourcegraph CLI[3]. We're working on expanding this.

[1] https://marketplace.visualstudio.com/items?itemName=sourcegr... [2] https://docs.sourcegraph.com/batch_changes/explanations/intr... [3] https://docs.sourcegraph.com/cli

Re:Comby - Structural code search and replace for every lang... by kretaceous on Tuesday May 17, 2022 @08:03PM (#31417685)
Thanks for letting me know. I'll try it right away.
Re:Comby - Structural code search and replace for every lang... by horlux on Wednesday May 18, 2022 @04:34AM (#31420468)
anything similar for vim?
Re:Comby - Structural code search and replace for every lang... by vanesa- on Wednesday May 18, 2022 @09:25PM (#31429643)
We don't have an extension for Vim yet, but you can use Sourcegraph CLI[1] in your terminal. Feel free to file a feature request[2] though, which should help bump up the prioritization of a proper Vim extension.

[1] https://docs.sourcegraph.com/cli [2] https://github.com/sourcegraph/sourcegraph/issues/new?assign...

Re:Comby - Structural code search and replace for every lang... by ducktective on Tuesday May 17, 2022 @03:30PM (#31415320)
language-server methods like rename
Re:Comby - Structural code search and replace for every lang... by kretaceous on Tuesday May 17, 2022 @07:55PM (#31417626)
Yes. I regularly use this feature sky-high I was looking for something more advanced as vanesa- spoke in the sibling comment.
Re:Comby - Structural code search and replace for every lang... by kretaceous on Tuesday May 17, 2022 @08:00PM (#31417658)
- sky-high + but

Swiping fiasco. When do we get the edit comment feature in HN? :)

Re:Comby - Structural code search and replace for every lang... by vore on Tuesday May 17, 2022 @08:18PM (#31417777)
You should be able to edit comments within 2? hours of posting. Maybe this link works for you? https://news.ycombinator.com/edit?id=31417626
Re:Comby - Structural code search and replace for every lang... by adamesque on Tuesday May 17, 2022 @02:09PM (#31414376)
I believe Sourcegraph uses Comby under the hood to an extent for structural matching as well!
Re:Comby - Structural code search and replace for every lang... by vanesa- on Tuesday May 17, 2022 @04:58PM (#31416202)
Yep! (Sourcegraph Community Manager here) We use Comby syntax for structural search: https://docs.sourcegraph.com/code_search/reference/structura...

We also have a few tutorials to make large-scale code changes across many repositories and code hosts (batch changes) with Comby:

- Refactor Go code using Comby: https://docs.sourcegraph.com/batch_changes/tutorials/refacto...

- Updating Go import statements using Comby: https://docs.sourcegraph.com/batch_changes/tutorials/updatin...

The author of Comby is a researcher at Sourcegraph building our search platform.

Re:Comby - Structural code search and replace for every lang... by picardo on Tuesday May 17, 2022 @01:31PM (#31413872)
Superb tool. I used Comby to create a massive (3000+ changes) PR in which I ported JS type annotations into TS typings.
Re:Comby - Structural code search and replace for every lang... by slightknack on Tuesday May 17, 2022 @01:17PM (#31413706)
I mocked up a prototype for something similar to this using TreeSitter and its query language the other day for some heavy refactoring I had to do. This looks like a really cool project, will have to try it out!
Re:Comby - Structural code search and replace for every lang... by CrazyPyroLinux on Tuesday May 17, 2022 @03:04PM (#31415054)
This looks a lot like https://semgrep.dev/ Interesting that they are both largely OCaml.
Re:Comby - Structural code search and replace for every lang... by jjice on Tuesday May 17, 2022 @03:07PM (#31415082)
ML style languages handle tree structures and traversal so well, I'm wondering if that's a large reason for using it.
Re:Comby - Structural code search and replace for every lang... by marcodiego on Tuesday May 17, 2022 @02:33PM (#31414682)
License?

Also, how does it compare to Coccinelle?

Re:Comby - Structural code search and replace for every lang... by smallnix on Tuesday May 17, 2022 @02:47PM (#31414844)
License seems to be apache V2, see https://github.com/comby-tools/comby/blob/master/LICENSE.

They have a comparison section in their faq (https://comby.dev/docs/faq):

"Coccinelle uses a declarative syntax for matching constructs like function calls, if-statements, expression blocks, and so on for the C language. Some notable differences are that Coccinelle provides a patch-like format to express transformations (handy when you want to inline smaller changes in a broader context) and metavariable declarations (handy for developing and organizing more sophisticated patterns). For an example, see the file null_ref.cocci. Coccinelle works only for the C language, and may struggle to parse files that contain non-standard C constructs, like GCC inline assembly. Recent Coccinelle work has started expanding support for Java. In contrast, Comby’s syntax targets a wide range of languages and is more robust to matching patterns in the presence of unrecognized constructs. Comby is more suited to writing quick find-replace patterns for languages beyond C, and works well on C languages too."

Re:Comby - Structural code search and replace for every lang... by jedisct1 on Wednesday May 18, 2022 @08:52AM (#31422110)
No support for Zig :(
Re:Comby - Structural code search and replace for every lang... by psanford on Wednesday May 18, 2022 @11:19AM (#31423892)
Odd, since the page linked says:

> Dedicated parsers refine how Comby understands code, but it also has basic out-of-the-box support for data formats like JSON, recent languages like Zig, or your own DSLs!

Re:Comby - Structural code search and replace for every lang... by otherflavors on Thursday May 19, 2022 @10:41AM (#31435286)
s/every language/some languages/