AI 划词解答
在 Visual Studio 里选中一段代码,右键,让 AI 给你讲明白。
不用切浏览器、不用复制粘贴、不用重新解释背景——它知道你在看哪个文件、哪一行、哪个方法,
回答直接出现在 VS 的工具窗口里。
- 作者:HillinBrook
- 版本:1.3.0
- 支持:Visual Studio 2022 / 2026(API 版本 17.0 及以上),仅 64 位
- 接口:任何 OpenAI 兼容的对话接口。DeepSeek、OpenAI、通义千问、Kimi、智谱、Ollama、Azure OpenAI 都能直接用
- 界面语言:完全跟随 Visual Studio。中文 VS 全是中文,英文 VS 全是英文,包括菜单、设置页和内置提示词
配置
这个扩展不附带 AI 额度,你需要自己准备一个 API Key,费用按用量付给服务商。
打开 工具 → AI 解答:设置…(也可以点答案面板右上角的「配置」),填显示名称、
API 地址(DeepSeek 是 https://api.deepseek.com/v1)、API 密钥、回答模型。
模型那一格右边有「选择」,点一下直接列出服务端提供了哪些模型,不用手打。
同一屏里还有温度、回答上限、超时和思考开关。每一项鼠标停上去都有一句说明,不用去翻文档。
多份配置,一键切换
配置页第一栏是 API 配置:一份配置一行,右边「编辑 / 删除」,右下角「添加」。
点行上任意位置就切到那一份,当前在用的那份标着「已启用」。
换服务商、或者同一个服务商想给「便宜快模型」和「最强模型」各留一份时,不用来回改地址和密钥 ——
每份配置的地址、密钥、模型、参数都是各存各的,切换不会覆盖任何一份。
内置提示词可以逐条调整
第二栏是 内置提示词:发给模型的规矩一条一行,每条可以单独启用 / 停用,
也可以自己「添加」。出厂那七条是锁定的(打不进字、也删不掉),
因为其中一条是「绝对不要编造不存在的 API 或行为」—— 改坏了不会有任何报错,
你只会觉得"这插件怎么变笨了"。想换个说法就把那条停用,再自己写一条。
配错了面板底部会给出提示。最常见的三个原因:API 地址末尾少了 /v1、
密钥前后多了空格、模型名拼写不对。
怎么用
在编辑器里选中代码,右键,选 AI 解答(划词提问)…。面板分三块:
- 快捷提问——你常问的问题,点一下就发出去。预置了几条,每行右边的
✕ 可以删,
右上角的 + 可以加。左边填按钮文字,右边填真正发给模型的问题;右边留空就用左边。
- 为您推荐——点「生成候选项」,模型看一眼你选中的代码,给出几个它猜你想问的问题。
候选项右边的
+ 可以收进快捷提问,下次不用再等生成。
- 答案区——回答流式逐字出现,代码块带语法高亮,配色用的是你编辑器里那套。
下面可以追问,回车发送,
Shift+回车 换行;回答之间会互相参考,可以一路问下去。
顶上是「停止 / 复制 / 清空」。复制出来的是 Markdown 源文本,粘到别处不丢格式。
上下文范围
这是这个工具最有用的一根旋钮——决定这次问题能看到多少代码:
| 范围 |
作用 |
| 自动 |
选了文字就只看选区,没选就看当前行 |
| 仅选中内容 / 当前行 |
只发选中的部分 / 光标所在行 |
| 当前方法 / 函数、当前类 / 类型 |
往外找到包住光标的那一层 |
| 整个文件 |
整个文件 |
| 整个项目 |
全部源码,自动跳过 bin、obj、node_modules、.git |
不够用就往上调一档。拿不准先用「自动」,必要时用「整个文件」补一次。
「整个项目」慎用:读的文件多,token 消耗和耗时都会明显上去。
更新日志
1.3.0 —— 新增「配置」窗口(工具菜单,或答案面板右上角「配置」),配置这件事从此集中在一处。
- 多份 API 配置并存,一键切换。 以前只有一个 Key 输入框,换服务商就得覆盖它 ——
而服务商的 Key 只显示一次,覆盖之后原来的就永久丢了。现在每份配置的地址、密钥、
模型、温度、超时都各存各的,切换不会动到任何一份。参数也从「每个插件一份」改成
「每份配置一份」—— 不同服务商的温度和超时本来就该分开设。
- 内置提示词逐条可调。 以前只有一个「使用内置提示词」总开关:要么全要,要么全不要。
可那几条里总有一两条不合用的(比如「不要复述代码」在讲解型提问下就不对),
为这个把整套关掉,等于连「不要编造不存在的 API」也一起扔了。现在一条一行,各自开关。
- 选项页瘦身。 「工具 → 选项」里不再有接口分类,只剩上下文捕捉和回答风格;
分类标题去掉了「1. / 2. / 3.」的序号。
- 思考开关拆成两项。 「要不要思考」(开 / 关)和「用哪个请求字段表达它」以前挤在一个
六项下拉里,看着像"有六个状态"。现在分开,字段名后面还标了谁家用它。
- 本地化补完。 内置提示词有中英两份;提示词里的固定文字(
回答要求: → Requirements:)、
上下文范围名、默认配置名都跟着界面语言走。界面是英文时不会再冒出一串中文。
- 界面细节:说明文字改成鼠标悬浮提示(不再每格压一段小字);编辑某份配置时整个窗口只剩表单;
新建改叫「添加」,保存时才落盘,点返回不留下任何东西;配置可以删(包括以前删不掉的「默认」)。
1.2.7 —— 修候选项生成。此前可能一个都不出、或者只出 1 个:生成候选项时的 token
上限太小,被模型的思考过程吃光,正文没生成出来。另外点击候选项时,
发给模型的问句是被截断过的(末尾带省略号)—— 现在发送完整原文,
按钮上显示短标签,鼠标悬停可以看全文。
1.2.6 —— 提高候选项生成时的 token 上限。
1.2.5 —— 菜单命令名跟随界面语言。至此插件里所有文字都跟随 VS,没有例外。
1.2.3 —— 设置页的分类、标签和说明跟随界面语言(此前一直是中文);
修「快捷提问」不跟随语言。
1.2.1 —— 修「回答语言」选项不生效(此前无论怎么选都以中文回答);
修「清空」清不掉思考过程。
1.2.0 —— 新增「工程概况」:自动读取工程的清单文件(.csproj / package.json /
go.mod / pom.xml 等),把目标框架、语言版本、依赖库告诉 AI,
减少它推荐你用不了的 API 和语法。
1.1.x —— 思考过程可折叠、可开关;适配多家服务商各不相同的「思考开关」字段。
1.1.0 —— 首个公开版本。
几点说明
- 不保存历史会话:关掉面板再打开,之前的问答就没了。
- 只回答问题,不改你的代码。
- 代码高亮是词法级的,个别地方会和编辑器里的着色略有出入。
许可
MIT
English
Select code in Visual Studio, right-click, and let AI explain it. No switching to a browser,
no copy-paste, no re-explaining the context — it knows which file, line and method you are
looking at, and the answer shows up in a Visual Studio tool window.
- Author: HillinBrook
- Version: 1.3.0
- Requires: Visual Studio 2022 / 2026 (API 17.0+), 64-bit
- Works with: any OpenAI-compatible chat API — DeepSeek, OpenAI, Qwen, Kimi, Zhipu, Ollama, Azure OpenAI
- UI language: follows Visual Studio. A Chinese VS is entirely Chinese, an English VS
entirely English — including the menus, the options page and the built-in prompt.
Setup
You need your own API key. The extension ships no AI credits; you pay the provider directly.
Open Tools → AI Explain: Settings… (or click Settings in the panel's top-right corner) and
fill in a name, the API base URL, the API key and the answer model.
The model field has a "Pick" button that lists what your endpoint actually offers.
Temperature, answer limit, timeout and the thinking switch are on the same screen, and
every field explains itself on hover.
Several settings side by side
The first section, API settings, holds one row per configuration — with Edit / Remove on
the right and Add at the bottom. Click a row to switch to it; the one in use is marked
Active. Each configuration keeps its own URL, key, model and parameters, so
switching never overwrites another one.
The built-in prompt, line by line
The second section, Built-in prompt, is the set of rules sent to the model — one per line,
each with its own on/off switch, and you can add your own. The seven that ship with the
extension are locked (read-only, no delete), because one of them is
"never invent APIs or behaviour that does not exist": break that one and there is
no error anywhere — you just slowly conclude the extension got worse. Want different
wording? Switch that line off and add your own.
A wrong setting shows a hint at the bottom of the panel. The three usual causes:
a base URL missing /v1, stray spaces around the key, a misspelled model name.
Using it
Select code, right-click, pick AI Explain (Ask About Selection)….
- Quick questions — one click to ask. Comes with a few presets; add your own with
+, remove with ✕.
- Suggestions — the model reads your selection and proposes what you might want to ask.
Save any of them into your quick questions with
+.
- Answers — streamed, with syntax highlighting and font taken from your own editor settings.
Ask follow-ups in the box below; later answers can refer back to earlier ones.
Context scope — selection / line / method / type / whole file / whole project.
If the answer is missing something, widen it one step. "Whole project" reads a lot of files
and costs noticeably more tokens.
Changelog
1.3.0 — A new Settings window (Tools menu, or the Settings button in the panel),
so configuration now lives in one place.
- Several API settings side by side, switched with one click. There used to be a single
key field, so changing provider meant overwriting it — and providers only show a key once,
so it was gone for good. Each setting now keeps its own URL, key, model, temperature and
timeout, and switching never touches another one. Those parameters also moved from
"one per extension" to one per setting — different providers deserve different values.
- The built-in prompt is now line by line. It used to be a single all-or-nothing switch,
but one or two of those rules never suit everybody (say "do not restate the code" when you
asked for an explanation) — and turning the whole set off also threw away
"never invent an API that does not exist". Now each line has its own switch.
- A slimmer options page. The endpoint category is gone from
Tools → Options; only
context capture and answer style remain, without the "1. / 2. / 3." prefixes.
- The thinking switch is split in two. "Whether to think" (on / off) and "which request
field expresses it" used to share one six-item drop-down, which read like six states.
Now they are separate, and each field name says which provider uses it.
- Localisation finished. The built-in prompt ships in both languages; the fixed wording
inside the prompt (
回答要求: → Requirements:), the context scope names and the default
setting name all follow the UI language. An English VS no longer shows stray Chinese.
- Interface details: explanations moved into hover tooltips instead of a paragraph under every
field; editing a setting shows only the form; "Add" saves nothing until you press Save;
and settings can be deleted — including the "Default" one that used to be undeletable.
1.2.7 — Fixed suggestion generation, which could return nothing at all or only a
single item: the token budget for that call was too small and got eaten by the model's
reasoning before any content was produced. Clicking a suggestion also used to send a
truncated question (ending in an ellipsis) to the model; it now sends the full text,
with a short label on the button and the full question shown on hover.
1.2.6 — Raised the token budget used for suggestion generation.
1.2.5 — Menu command names now follow the UI language. Every string in the extension
follows Visual Studio now, with no exceptions.
1.2.3 — Options page categories, labels and descriptions follow the UI language
(previously Chinese only); fixed quick questions not following it.
1.2.1 — Fixed the "answer language" option having no effect; fixed "Clear" not clearing
the reasoning area.
1.2.0 — Added the project profile: reads your project's manifest files
(.csproj / package.json / go.mod / pom.xml …) and tells the AI your target framework,
language version and dependencies, so it stops suggesting APIs you can't use.
1.1.x — Collapsible, switchable reasoning; support for the different "thinking switch"
request fields providers use.
1.1.0 — First public release.
Notes
- Answers are not saved; closing the panel clears the conversation.
- It explains code, it does not modify your files.
- Syntax highlighting is lexical, not compiler-accurate; a few tokens may differ from the editor.
License
MIT