AI 代码编辑器cursor之codebase功能:让工具能够更好地理解整个代码库的上下文

AI 代码编辑器cursor之codebase功能:让工具能够更好地理解整个代码库的上下文

cursor

官网:https://www.cursor.com/cn
官方文档:https://docs.cursor.com/get-started/welcome

Code is fundamentally text, and our tools for writing it have evolved from simple text editors into increasingly intelligent development environments.
代码从根本上说是文本,我们编写代码的工具已经从简单的文本编辑器演变为越来越智能的开发环境。

Initially, we had features like syntax highlighting, to make code more readable. Then, we had features like autocomplete, to make code more efficient.
最初,我们有语法高亮等功能,以使代码更具可读性。然后,我们有了自动完成等功能,以提高代码效率。

These have been the standard for a long time, but with Cursor, we’re re-inventing how you work with code.
这些长期以来一直是标准,但借助 Cursor,我们正在重塑您处理代码的方式。

在这里插入图片描述
这幅图像展示了一个关于数据偏好的设置界面,主要用于用户在使用 Cursor 工具时选择数据收集和隐私设置。

“To make Cursor better, this option lets us collect usage data. This includes questions in chat, code snippets, edits, and editor actions.” 这段文字的意思是,通过允许收集使用数据,用户可以帮助改进 Cursor 工具,收集的数据包括聊天中的问题、代码片段、编辑操作和编辑器行为。

“If you enable Privacy Mode, none of your questions or code will ever be stored by us or any third-party.” 这表示如果用户启用隐私模式,他们的问题或代码将不会被存储,无论是由 Cursor 还是任何第三方。

用户可以在之后的设置中随时更改这些选项, 注意安全的情况下,我们选择隐私

codebese功能

官方文档:https://docs.cursor.com/context/codebase-indexing

官网功能介绍:
在这里插入图片描述

第一次安装界面:
在这里插入图片描述
Codebase-wide (代码库范围设置):
这个选项允许计算代码库范围内的问题的嵌入(embeddings)。启用此功能后,AI 可以更好地理解和处理与整个代码库相关的问题,提供更准确的建议和解决方案。

Codebase-wide 是一个与代码库(codebase)相关的功能,通常用于开发工具或 AI 辅助编程工具中。它的核心目的是让工具能够更好地理解整个代码库的上下文,从而提供更智能、更准确的建议或分析。

  1. 代码库范围的嵌入(Embeddings):
    嵌入(embeddings)是一种将代码或文本转换为向量表示的技术,便于机器理解和处理。
    启用 Codebase-wide 功能后,工具会计算整个代码库的嵌入,而不仅仅是单个文件或片段。这意味着工具可以更好地理解代码库的整体结构、依赖关系和上下文。
  2. 上下文感知:
    通过分析整个代码库,工具可以提供更准确的代码补全、错误检测、重构建议等功能。
    例如,AI 可以识别代码库中重复的模式、未使用的函数或潜在的优化点。
  3. 跨文件分析:
    在大型项目中,代码通常分布在多个文件中。Codebase-wide 功能允许工具跨文件分析代码,理解模块之间的关系,从而提供更全面的支持。
  4. 智能搜索和导航:
    工具可以根据代码库的嵌入,提供更智能的搜索功能。例如,用户可以搜索某个功能或概念,工具会返回相关的代码片段、文件或文档。
  5. AI 辅助开发:
    Codebase-wide 功能可以让 AI 更好地理解代码库的上下文,从而生成更符合项目需求的代码或建议。

官方文档介绍

官方原文链接:https://docs.cursor.com/context/codebase-indexing

Codebase Indexing
代码库索引

For better and more accurate codebase answers, you can index your codebase. Behind the scenes, Cursor computes embeddings for each file in your codebase, and will use these to improve the accuracy of your codebase answers.
为了获得更好,更准确的代码库答案,您可以索引您的代码库。后台,Cursor 计算代码库中每个文件的嵌入,并将使用它们来提高代码库答案的准确性

Cursor maintains separate codebase indexes for each user. After you complete the initial indexing setup, Cursor will automatically index any new files added to your workspace to keep your personal codebase context current.
Cursor为每个用户维护单独的代码库索引(codebase indexes)。完成初始索引设置后,Cursor 将自动索引添加到工作区中的任何新文件,以保持您个人代码库上下文的最新状态。

代码库索引的状态位于Cursor Settings > Features > Codebase Indexing。

在这里插入图片描述
在这里插入图片描述“Embeddings improve your codebase-wide answers. Embeddings and metadata are stored in the cloud, but all code is stored locally.” 这段文字的意思是,嵌入(embeddings)可以改善代码库范围内的回答,嵌入和元数据存储在云端,但所有代码都存储在本地。

高级设置

By default, Cursor will index all files in your codebase.
默认情况下,Cursor 会索引代码库中的所有文件。

You can also expand the Show Settings section to access more advanced options. Here, you can decide whether you want to enable automatic indexing for new repositories and configure the files that Cursor will ignore during repository indexing.
您还可以展开Show Settings部分以访问更多高级选项。在这里,您可以决定是否要为新存储库启用自动索引,并配置 Cursor 在存储库索引期间将忽略的文件。

If you have any large content files in your project that the AI definitely doesn’t need to read, ignoring those files could improve the accuracy of the answers.
如果您的项目中有一些大型内容文件,AI 绝对不需要读取,忽略这些文件可以提高答案的准确性。

使用大型单体仓库Working with large monorepos

When working with large monorepos containing hundreds of thousands of files, it’s important to be strategic about what gets indexed.
当使用包含数十万个文件的大型单体仓库时,务必对要索引的内容进行策略性规划。

Use .cursorignore to let each developer configure which folders and paths they work on in the monorepo
使用 .cursorignore 让每个开发者配置他们在单体仓库中工作的文件夹和路径
Add .cursorignore to your global .gitignore
将.cursorignore添加到您的全局.gitignore
This allows each developer to optimize indexing for their specific work areas within the monorepo.
这允许每个开发人员针对单体仓库中的特定工作区域优化索引。

FAQ
  1. ​Where can I see all codebases I have indexed?
    我在哪里可以查看我已索引的所有代码库?
    Currently, there is no way to see a list of all codebases you have indexed. You’ll need to manually check each project’s indexing status by opening the project in Cursor and checking the Codebase Indexing settings.
    目前,无法查看您已索引的所有代码库的列表。您需要手动检查每个项目的索引状态,方法是在 Cursor 中打开项目并检查“代码库索引”设置。


2. How do I delete all codebases?
如何删除所有代码库?
You can either delete your Cursor account from Settings to remove all indexed codebases, or manually delete individual codebases from the Codebase Indexing settings in each project. There’s currently no way to delete all codebases at once without deleting your account.
你可以从“设置”中删除你的 Cursor 帐户以移除所有已索引的代码库,或者从每个项目的“代码库索引”设置中手动删除各个代码库。目前,无法一次性删除所有代码库,除非删除你的帐户。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西京刀客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值