TS7 LSP: documentHighlight returns nothing when the file path contains '@'
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- go
- Área
- backend-api-design
Línea de trabajo
Empieza por tsc/internal/ls/documenthighlights.go:30, donde la issue señala una comparación de cadenas URI sin procesar, e inspecciona tsc/internal/ls/lsconv/converters.go:315 para entender la codificación de URI. Reproduce el problema con el archivo TypeScript proporcionado en una ruta que contenga @ y compara los resultados de la URI codificada y sin codificar. Se considera terminado cuando las referencias del documento devuelven las tres coincidencias para ambas formas de URI; la issue no indica ningún archivo de prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🔎 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
- Lenguaje dominante
- Go
- Estrellas
- 112k
- Forks
- 17.1k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 173
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/TypeScript
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
microsoft/TypeScript#64742 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsPosiblemente ocupada @dmety la tomó hace 14 días. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/TypeScript#64661 ·
Los mantenedores suelen responder en 1 día
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmedPosiblemente ocupada @RyanCavanaugh la tomó hace 15 días. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/TypeScript#64618 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
TypeScript 7 VS Code extension: a workspace "typescript" 7.x package is not detected, only "@typescript/native-preview", which is no longer publishedPosiblemente ocupada @jakebailey la tomó hace 15 días. AbiertoNeeds Investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/TypeScript#64565 · 1 reacción · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
`EFNoLeadingComments` suppresses synthesized leading comments in tsgo; Strada only suppresses source commentsPosiblemente ocupada @weswigham la tomó hace 22 días. AbiertoNeeds Investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/TypeScript#64453 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/TypeScript
Issues similares
-
native
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
prime-radiant-inc/evener#4839 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
521xueweihan/HelloGitHub#4073 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
goharbor/terraform-provider-harbor#655 · 1 comentario ·
-
bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
syncthing/syncthing#10935 · 1 comentario ·
Los mantenedores suelen responder en 1 día