Comment by h1fra
2 years ago
I have been using since the beta, truly the most impressive product released in the last 5 years (along with chatgpt). The amount of indexed code, the quickness and the precision of this search is simply stunning.
2 years ago
I have been using since the beta, truly the most impressive product released in the last 5 years (along with chatgpt). The amount of indexed code, the quickness and the precision of this search is simply stunning.
Absolutely. GitHub Code Search is by far the most valuable online development tool I have used the past year. It is so much more useful than Copilot or any of the AI LLMs in my experience.
With Code Search, I have:
* Rewritten a CMake build system, which would have been practically impossible without access to real-world examples because of how poorly designed and documented it is;
* Validated machine-generated translations by looking up language strings from projects that used human translators;
* Tracked down bugs in unfamiliar codebases, using symbol-based navigation, without the downtime of fetching a bunch of files and waiting for a language server to process them locally;
* Reviewed how projects were using the APIs of a library I work on to determine whether high-maintenance features were actually used, and whether tricky features were being used correctly or needed redesigning to reduce programmer error
Kudos to the team at GitHub. Genuinely stellar work.
That's really interesting, do you have any examples handy of search queries you used?
For CMake stuff I would search like `<function name> path:/CMakeLists\.txt$|cmake/`.
For translations I would search a phrase using `<phrase> lang:"Gettext Catalog" path:/<language iso code>/`.
For reviewing library consumers I would just search for `<my library name> (<function name> OR <other function name> OR <third function name>) NOT path:<my library name>/**`.
There may be better queries for some of these, but I really didn’t have to do any magic or weird tricks. Everything more or less just works.
I'm not the one you asked to, but here my usages:
Searching how an API is used.
Searching how people configured something.
Searching accidental uses of an attribute:
https://github.com/dotnet/csharplang/discussions/5657#discus...
It's amazing for searching examples of rarely used / non-public APIs
Is the difference that now the basic search functionality actually works?
The previous standard GitHub search I found to be remarkably bad. I would be looking at some small public repo, search for an exact string match I know exists in the code, scope the search to that repo only, and still see zero results. Even copy-pasting a line of code from a file in the repo often resulted in zero matches.
I don't get it too. Maybe one needs to enable something. The search is still useless. Locally I use git-grep.
You might want to consider replacing git-grep with ripgrep.
It seems you still need to enable the feature. Click your user icon in the top right -> choose "Feature preview" in the dropdown -> enable the "New Code Search and Code View" feature.
3 replies →
Same experience here. Are there advertisement accounts posting here or something? Legitimately weird.
1 reply →
I'm pretty sure sourcegraph.com has been doing all that (search all GH repos, exact search in quotes, case-sensitive search, regex search, limit files using filename regex) for longer than 5 years.
Could you elaborate more on why this is a significant feature?
I can see how it would be handy to search a codebase online, especially one you don't have cloned locally, but for my own codebases, I can search the entire thing just fine in VS Code with ctrl-shft-f.
It's not only about searching your own repository, it allows you to search through every single public repository on GitHub. I personally use it a lot to learn more obscure APIs which are badly documented or which I'm just not used to, simply search for the method I'm trying to use and find infinite examples of real world usage, along with the code license right next to it.
It's also great if you drank the GitHub kool-aid as you can do a single search and find related code snippets, issues, pull requests and discussions that could possibly help. I'm personally not to big into the ecosystem, in fact I'm considering moving to Fossil so I can have everything inside the repo, but for those who are it's a great feature.
Ever wanted to use an API and found the documentation to be lacking?
GitHub code search pretty much solves that. For any API you can find an example of someone else using it.
I've been using it for this for a year now and I wouldn't want to live without it.
> For any API you can find an example of someone else using it.
Amazing. This was the light bulb moment for me. I work at [big tech co] and we have an internal code search tool, and anytime I need to use a new API I pull it up to find examples of how it's used.
Now I can do this for the entire world of OSS, amazing.
I think others have pretty much summarised it already:
Searching for non-documented or badly documented API, find implementation of an algorithm or specific pattern, find how people are using a niche tool, etc.
I have even used it to find my own API in the wild to look for potential breaking changes and improvements to do.
For me it's been very useful at finding codebases with work done on extremely specific niche things that would've been near impossible to find otherwise (e.g. tools for obscure protocols hidden away on obtusely named repos)
Yes, it comes pretty close. Well done!