TS7 LSP: documentHighlight returns nothing when the file path contains '@'
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- go
调研方向
从 tsc/internal/ls/documenthighlights.go:30 开始,issue 在此指出了原始 URI 字符串比较;再检查 tsc/internal/ls/lsconv/converters.go:315,了解 URI 编码。使用提供的 TypeScript 文件,在包含 @ 的路径下复现,并比较编码和未编码 URI 的结果。完成标准是:对于两种 URI 形式,文档高亮都返回全部三个匹配项;issue 没有指定测试文件。
由索引模型根据 Issue 内容生成。
描述
🔎 Search Terms
documentHighlight, document highlight, URI encoding, percent-encoding, %40, @ in path, Neovim, LSP
🕗 Version & Regression Information
- I was unable to test this on prior versions because this code is in the TS7 language server only. The old tsserver (through vtsls) does not have this problem.
I reproduced it with tsc --lsp 7.0.2. The same code is on main at ba1819f.
⏯ Playground Link
Not applicable. The problem is in the language server.
💻 Code
Put this file in a directory whose path contains @, for example /tmp/a@b/proj/x.ts, with an empty tsconfig.json next to it:
const foo = 1;
console.log(foo);
console.log(foo);
🙁 Actual behavior
textDocument/documentHighlight on foo (line 0, character 7) returns an empty array if the client sends the path with @ not encoded:
| URI that the client sends | Highlights |
|---|---|
file:///tmp/a@b/proj/x.ts |
0 |
file:///tmp/a%40b/proj/x.ts |
3 |
file:///tmp/plain/proj/x.ts |
3 |
Neovim sends the first form (vim.uri_from_fname("/tmp/a@b/x.ts") gives file:///tmp/a@b/x.ts). Thus, in Neovim, document highlights and features that use them (for example, jump to next reference) do not work in projects whose path contains @. Other requests, such as textDocument/references, work correctly on the same file.
🙂 Expected behavior
The server returns 3 highlights for all three URIs. The two a@b URIs identify the same file, and the server opens that file correctly from both forms.
Additional information about the issue
Cause. tsc/internal/ls/documenthighlights.go:30 filters the results with a raw string compare:
if mh.Uri == documentUri {
mh.Uricomes fromlsconv.FileNameToDocumentURI, which encodes@as%40(tsc/internal/ls/lsconv/converters.go:315).documentUriis the string that the client sent, without changes.
When the client does not encode @, the strings are different, and the filter removes all highlights. VS Code does not see this problem because vscode-uri also encodes @ as %40 (URI.file('/tmp/a@b/x.ts').toString() gives file:///tmp/a%40b/x.ts). Thus the two sides always agree.
Why this is a server problem. RFC 3986 permits @ in a path segment without encoding, so the client URI is valid. Also, the LSP specification (URI section) says:
Clients and servers should not assume that each other are encoding the same way (for example a client encoding colons in drive letters cannot assume server responses will have encoded colons).
Possible fix. Compare file names, not URI strings:
if mh.Uri.FileName() == documentUri.FileName() {
Another possible fix is to normalize documentUri one time before the loop. Other characters in extraEscapeReplacer (', (, ), *, +, ,, ;, =, !, $, &, and so on) probably cause the same problem with clients that do not encode them.
Related: #43261 had the same type of cause (a path-case mismatch caused document highlights to fail) in tsserver.
Environment
- Neovim v0.12.0-dev, Linux (WSL2)
tsc --lsp7.0.2
- 主要语言
- Go
- 星标
- 111k
- 派生
- 16.4k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 148
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#64742 ·
维护者通常 1 天内回复
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings可能已有人在做 @dmety 于 5 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/TypeScript#64661 ·
维护者通常 1 天内回复
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmed可能已有人在做 @RyanCavanaugh 于 6 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/TypeScript#64618 · 已指派 1 人 ·
维护者通常 1 天内回复
-
TypeScript 7 VS Code extension: a workspace "typescript" 7.x package is not detected, only "@typescript/native-preview", which is no longer published可能已有人在做 @jakebailey 于 6 天前认领。 未关闭Needs Investigation
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/TypeScript#64565 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
`EFNoLeadingComments` suppresses synthesized leading comments in tsgo; Strada only suppresses source comments可能已有人在做 @weswigham 于 13 天前认领。 未关闭Needs Investigation
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/TypeScript#64453 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
automation models
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
SocialGouv/iterion#2369 ·
维护者通常 1 天内回复
-
daemon/cluster: imageWithDigestString returns the mirror error even when upstream resolves the tag未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
area/ci bug priority/p3
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
cmd/mdatagen
难度 2/5 1-3 小时 新手友好度 75/100
open-telemetry/opentelemetry-collector#16150 · 1 条评论 ·
维护者通常 1 天内回复