Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Allow hinting `DebugProtocol.Source` to prefer `path` over `sourceReference`

未关闭
#224 5 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, nodejs, typescript
领域
api

调研方向

从 DebugProtocol.Source 定义以及当前“正数 sourceReference 优先于 path”的规则开始。明确优先级、校验和验证及回退语义,然后更新协议定义和示例,使客户端能够一致地在可编辑路径与 sourceReference 快照之间进行选择。

由索引模型根据 Issue 内容生成。

描述

clarification feature-request

It'd be nice if a new field (e.g. preference) gets added to DebugProtocol.Source to tell clients (IDEs) that if the Source can be mapped to a file, it should open that file instead of using sourceReference. Perhaps it's even worth making this the default, especially when combined with my item of checknotes below.

Details

  • It's not uncommon to end up debugging a program for which the input source has changed.
    • As in, the debugger still knows the original input source that the program is currently running.
    • A good example is NodeJS with JavaScript, and even TypeScript if the (loaded) source maps also contain the source.
  • Currently the protocol states that a sourceReference bigger than 0 means that should be used, regardless of path.
    • This would either be a "breaking" change (although it won't break anything, IDEs just wouldn't show "modern" behavior).
    • We can specify to only prefer path if checksums is present to validate whether it results in the correct file (contents).
  • It is more user friendly in IDEs if a Source can be mapped to the actual source file, instead of a snapshot in the debugger.
    • The user might already have the file open, and focusing it instead of opening a cached file is preferred.
    • The user can now also directly edit the file, without having to first look for the correct file based on the read-only snapshot.
  • The IDE might find the right file, but maybe its contents have changed:
    • We can use checksums to validate whether it is (the correct version of) the correct file. If not, revert to sourceReference.
  • We have the sources field but this isn't (meant as) a 1-on-1 mapping of the source itself.
  • Having the debug adapter only provide path is not enough:
    • If the file isn't found, the IDE has nothing to show.
    • If the file changed (and checksums isn't present), the IDE might display an outdated (or completely wrong) file.
    • If checksums is present, the IDE can validate whether the file (content) is correct, but not fallback to anything if it isn't.

This is mostly a big quality-of-life improvement towards IDE users, as these would now prefer the actual source files over cached versions provided by the debug adapter, assuming they're the same (using checksums). While the file content will be the exact same, mapping to an editable source file or mapping to a read-only "debug content file" is quite a large difference.

Hotreload example

Since this would still allow different Sources with the same path but a different sourceReference/checksums (and the IDE automatically picking between showing the path file or the read-only sourceReference viewer), we can also easily allow debug adapters to differentiate different versions of the same (path-specified) file, e.g. because of hotreloading:

  • Program loads a.js with AAA as checksum.
  • Debugger attaches, adapter tells the IDE about { path: 'a.js', sourceReference: 1, checksum: ['AAA'] }.
    • IDE finds the properly mapped a.js, validates the checksum and opens it.
  • User edits file and saves it, causing the program/debugger to hotreload it one way or another.
    • Let's say the new content results in BBB as checksum.
  • Debug adapter tells the IDE about { path: 'a.js', sourceReference: 2, checksum: ['BBB'] }.
    • IDE finds the file again (which might still be open), sees the checksum matches the (new) content, so opens it.
  • Debug adapter might tell IDE again about the previous file (ref 1, checksum AAA).
    • IDE finds the file but notices the different checksum. Falls back to using the sourceReference with value 1.
  • Debug adapter might tell IDE again about the current file (ref 2, checksum BBB) after it was saved, but before the hotreload.
    • IDE finds the file but notices the different checksum. Falls back to using the sourceReference with value 2.

Of course, this hotreload example is an advanced use case this change would allow. Just the QoL improvement to open the true (editable) source file instead of a snapshot if possible is already a very nice use case this allows.

主要语言
HTML
星标
1.8k
派生
173
平均合并
7 天 7 小时
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/debug-adapter-protocol 的其他 Issue

查看 microsoft/debug-adapter-protocol 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。