source insight的查找功能

本文深入探讨了SourceInsight这款强大的C语言程序编辑器的查找功能,包括全字匹配查找、区分大小写查找、项目内查找、包含子目录查找、跳过无效代码查找、跳过注释查找等特性。同时介绍了LoopupReferences、SearchFiles、SearchProject三种查找方式及其使用方法,详细解析了LookupReferences对话框中的各项参数设置,如查找引用、文件类型、搜索方法、上下文行数、查找单词变化等,并强调了在查找过程中如何高效利用这些功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sourceinsight是一款很好的c语言的程序编辑器,方便对project管理,方便程序的阅读和编辑。查找功能使用十分频繁,选项较多,与其它软件的查找功能也类似,下面对英文版的查找功能,做简单说明:

查找参数:
whole wordsonly                 全字匹配查找
casesensitive  :                  区分大小写
projectwide                         项目内查找
includesubdirectories          包含子目录查找
skip inactivecode               跳过无效代码查找
skipcomments                   跳过注释查找
search onlycomments       仅在注释在查找

 

3.2.1.1 Loopup References

我们最常用的一种查找方式是选择Search/Lookup References或按Ctrl+/组合键再或者鼠标点 R按钮,在弹出的Loopup References窗口进行查找操作。 在SearchMethod中有四种可选的查找方式:Simple String、Regular Expression、 KeywordExpression和Look Up Reference。其中SimpleString是最普通的查找方式,可以查找文件中出现的任意字符或字符,甚至可以查找 _upap || u这样的字符串,但是在工程较大时,查找过程会较慢。 RegularExpression查找方式将在后面讲述正则表达时会介绍到,这里暂时按下不表。 Keyword Expression和Look UpReference查找的结果基本相同,但是显示方式略有差异。这两种方式都是使用SI预先建立的数据库,查找起来速度相当快。但通常这种速度只对在查找标识符时有明显效果。对于像函数名,变量名等的查找,强烈建议使用这两种方式进行查找。

3.2.1.2 SearchFiles

选择Search/Search Files或按Ctrl+Shift+F组合键,在弹出的Search Files窗口进行查找操作。在File Name框中可以填入文件名或文件夹。注意当要查询的文件夹双包含子文件夹时,可以勾选Options中的IncludeSubdirectiories,实现对各层文件的递归搜索。

3.2.1.3 SearchProject

选择Search/Search Project,在弹出的Search Project窗口进行查找操作。操作与LoopupReferences几乎完全一致,它们各自保存上次搜索的配置。

 

Lookup References Dialog box

The Lookup References command is very similar to the Search Projectcommand. In fact, each dialog box is identical. However, eachdialog box has its own persistent state.

Find References To

Type the symbol name you want to locate. The word under the cursoris automatically loaded into this text box. Source Insight will usethe context of the cursor position to determine the exact symbolinstance you want. If you invoked Lookup References from a symboldialog box or window, then Source Insight keeps the exact symbolreferences along with this text box.

Typically, you would type the name of an identifier in yourprogram, however you can type any string here and a project-widesearch will be performed. The search is very fast if you type asingle word only.

Search In

This drop-down list contains a list of document types. You can usethis list to restrict the search to only a particular type of file,or just the current file. If the Project Window is visible, thenyou can also use this list to specify the files selected in theProject Window.

Search Method

You can pick the search method to use from this list. There arefour different searching methods available:

• Simple String

• RegularExpression interprets the pattern as a regularexpression.

• KeywordExpression similar to an Internet searchquery.

• LookupReference searches for symbol references.

Lines of Context

This only applies if you selected the Keyword Expression searchmethod. This specifies how closely, in number of lines, thekeywords must occur in order to qualify as amatch. Seealso “Keyword Expressions”.

Find word variations

If enabled, Source Insight will also find different ending forms ofthe keywords you specified. For example, if you specified thekeyword “open”, Source Insight will also find “opens”, or “opened”,or “opening”. This option is only available for the KeywordExpression search method.

Search Options

Case Sensitive

Specifies whether the search is case sensitive or not.

Whole Words Only

For the Lookup References mode, this option is always on. If youchoose a different search method, this will restrict matches toonly whole words.

Skip Inactive Code

If enabled, then only code that is active under conditionalcompilation is searched. You must first specify known conditions inthe Preferences: Languages dialog box, in order for Source Insightto know what conditions are active or not. Conditional compilationonly applies to some languages.

Skip Comments

If enabled, then comments will not be searched.

Search Only Comments

If enabled, then only comments will be searched. This is mutuallyexclusive with the Skip Comments option. The comment options slowthe search down a little.

Smart Reference Matching

This enables Source Insight’s smart reference matching feature.Source Insight will determine whether each reference found isactually referring to the symbol you are looking for.

The Smart Reference Matching option means that the search resultswill only contain references strictly to the exact symbol youspecified. For example, if you select a member of a struct and lookup its references, the search results will only contain referencesto that particular member of that particular struct – not just anystring that is equivalent. Note that this option slows the processdown because each same-string occurrence has to be qualified with asymbol lookup.

Touch files and cause recompile. Turn this on to cause each file’s“last modified” time stamp to be set to the current time. This isuseful if you have a compile time dependency on an identifierusage. Just turn this on and search for references with thiscommand. The places where the identifier is referenced will be“touched” and your make program or development system willrecompile those files the next time you build your program.

Source Insight 中进行代码查找搜索操作是日常开发和代码维护中非常常见的需求。它提供了多种方式来查找函数、变量或文件,支持局部查找和全局搜索,帮助开发者快速定位目标代码。 ### 查找函数或变量 1. **在当前文件中查找函数或变量** 可以使用快捷键 `Ctrl + F`,在当前文件中进行快速搜索。输入要查找的关键词,Source Insight 会高亮显示所有匹配项,并允许逐个跳转。 2. **在整个工程中查找函数或变量** 如果需要在整个项目中查找某个函数或变量,可以使用快捷键 `Ctrl + Shift + F`,这会打开全局搜索窗口。在搜索框中输入目标名称,并确保勾选“Project Wide”选项,这样搜索范围将覆盖整个工程。搜索结果会列出所有匹配项,并显示其所在的文件和行号,点击左侧的三角图标即可跳转到对应位置 [^3]。 3. **查找函数调用关系** Source Insight 提供了强大的函数调用分析功能。点击工具栏上的 **Relation Window** 按钮,打开调用关系窗口。在代码中点击某个函数,该窗口将展示其调用链。可以通过设置过滤器,排除函数声明,仅显示函数定义,从而更清晰地查看调用关系 [^5]。 4. **查找变量引用** 如果需要查找某个变量的引用位置,可以右键点击变量名,选择 **Smart Rename** 或 **Find References**(具体选项名称可能因版本不同而略有差异),Source Insight 会列出所有引用该变量的地方,并允许跳转查看 [^2]。 ### 查找文件 1. **通过文件名查找文件** Source Insight 提供了通过文件名快速查找文件的功能。可以使用快捷键 `Alt + F` 打开“Go to File”对话框,输入文件名的部分内容,系统会自动列出匹配的文件列表,选择后即可快速打开 [^1]。 2. **通过符号查找文件** 在“Symbol Window”中,可以查找函数、变量、宏等符号。打开“Symbol Window”后,输入符号名称,结果会显示该符号所在的文件和位置,点击即可跳转 [^5]。 ### 代码查找问题的解决方法 在使用过程中,有时可能会遇到变量、函数或宏定义显示为黑色,无法查看引用或调用关系的问题。此时可以尝试以下方法: 1. **同步代码与项目** 在菜单中选择 **Project -> Synchronize Files**,并勾选相关选项,确保 Source Insight 中的代码与本地文件保持一致 [^4]。 2. **重构项目** 如果同步无效,可以尝试重新构建项目索引。选择 **Project -> Rebuild Project -> Re-Create the whole project from scratch**,以重建整个项目 [^4]。 3. **重新导入项目** 如果上述方法无效,可以尝试将当前项目移除,然后重新创建项目并导入代码 [^4]。 --- ### 示例代码:使用 Relation Window 查看调用关系 ```cpp void hostapd_add_iface() { // 函数体 } int main() { hostapd_add_iface(); // 调用函数 return 0; } ``` 在上面的代码中,点击 `hostapd_add_iface` 函数,Relation Window 会显示 `main` 函数调用了它,帮助开发者快速理解代码结构 。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值