全文搜索忽略评论

发布于 2024-12-03 04:59:10 字数 176 浏览 0 评论 0原文

我想要对我的 JavaScript 代码进行全文搜索,但我通常对注释中的匹配不感兴趣。

如何进行全文搜索忽略任何带注释的匹配?这样的功能将提高我作为程序员的生产力。

另外,我该如何做相反的事情:仅在评论中搜索?

(我目前正在使用 Text Mate,但很乐意进行更改。)

I want fulltext search for my JavaScript code, but I'm usually not interested in matches from the comments.

How can I have fulltext search ignoring any commented match? Such a feature would increase my productivity as a programmer.

Also, how can I do the opposite: search within the comments only?

(I'm currently using Text Mate, but happy to change.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

撩人痒 2024-12-10 04:59:10

请参阅我们的源代码搜索引擎 (SCSE)。该工具使用语言结构来指导索引,对您的代码库进行索引;它可以对包括 JavaScript 在内的许多语言执行此操作。然后,搜索查询以抽象语言标记的形式表示,例如,要查找涉及字符串“tax”乘以某个常量的标识符,您可以这样写:

  I=*tax* '*' N

这将仅在所有索引语言中搜索标识符(在每种语言中)后跟一个“*”标记,然后是某种数字。由于该工具理解语言结构,因此不会被空格、格式或插入注释所混淆。因为它理解注释,所以您可以仅在注释中进行搜索(例如,针对作者):

   C=*Author* 

给定一个查询,SCSE 会找到整个代码库(可能有数百万行)中的所有命中,并提供这些作为选择集;单击选择会拉出文件,中间会显示匹配发生的位置。

如果您坚持只搜索原始文本,SCSE 提供 grep 式搜索。如果您只有一小部分文件,这仍然相当快。如果您有大量文件,这比基于语言结构的搜索要慢得多。在这两种情况下,类似 grep 的搜索都会让您获得更多点击,但通常会出现误报(例如,在注释中查找“tax”,或查找名为“Authorization_code”的变量)。但至少你有选择的权利。

虽然这不能在编辑器内部操作,但一旦找到所需的命中,您就可以在文件上启动编辑器(对于大多数编辑器)。

See our Source Code Search Engine (SCSE). This tool indexes your code base using the langauge structure to guide the indexing; it can do so for many languages including JavaScript. Search queries are then stated in terms of abstract language tokens, e.g., to find identifiers involving the string "tax" multiplied by some constant, you'd write:

  I=*tax* '*' N

This will search all indexed languages only for identifiers (in each language) following by a '*' token, followed by some kind of number. Because the tool understands language structure, it isn't confused by whitespace, formatting or interverning comments. Because it understands comments, you can search inside just comments (say, for authors):

   C=*Author* 

Given a query, the SCSE finds all the hits across the code base (possibly millions of lines), and offers these as set of choices; clicking on choice pulls up the file with the hit in the middle outlined where the match occurs.

If you insist on searching just raw text, the SCSE provides grep-style searches. If you have only a small set of files, this is still pretty fast. If you have a big set of files, this is a lot slower than language-structure based searches. In both cases, grep like searches get you more hits, usually at the cost of false positives (e.g., finding "tax" in a comment, or finding a variable named "Authorization_code"). But at least you have the choice.

While this doesn't operate from inside an editor, you can launch your editor (for most editors) on a file once you've found the hit you want.

醉梦枕江山 2024-12-10 04:59:10

使用 ultraedit ,它完全支持全文搜索忽略评论或也支持评论内搜索

Use ultraedit , It fully supports full text search ignoring comment or also within the comment search

滥情哥ㄟ 2024-12-10 04:59:10

NetBeans 方式怎么样(在导航菜单中查找符号),
它搜索所有变量、函数、对象等。

或者您可以自定义 JSLint 并自定义它(如果您想集成它)在网络应用程序或类似的东西中。

How about NetBeans way (Find Symbol in the Navigate Menu),
It searches all variables,functions,objects etc.

Or you could customize JSLint and customize it if you want to integrate it in a web application or something like that.

山川志 2024-12-10 04:59:10

我个人使用 Notepad++ 这是一个很棒的免费代码编辑器。看来您需要一个支持正则表达式搜索(在一个或多个文件中)的编辑器。如果您了解 Reg,您可以使用强大的搜索,例如输入/输出 JavaScript 注释...工作将是构建正确的表达式并使用具有所有不同情况的一个文件对其进行测试,以确保它在实际搜索过程中不会错过任何内容,或者也许你可以谷歌搜索“javascript注释正则表达式”或类似的东西......
然后必须看看 Notepad++ 插件,其中一个是“RegEx Helper”,它有助于构建正则表达式。

I personnaly use Notepad++ wich is a great free code editor. It seems you need an editor supporting regular expression search (in one or many files). If you know Reg you can use powerfull search like in/out javascript comments...the work will be to build the right expression and test it with one file with all differents cases to be sure it will not miss things during real search, or maybe you can google for 'javascript comments regular expression' or something like...
Then must have a look at Notepad++ plugins, one is 'RegEx Helper' wich helps for building regular expressions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文