TS7 LSP: documentHighlight returns nothing when the file path contains '@'
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 78/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- go
- Domaine
- backend-api-design
Piste de recherche
Commence par tsc/internal/ls/documenthighlights.go:30, où l’issue signale une comparaison de chaînes URI brutes, puis examine tsc/internal/ls/lsconv/converters.go:315 pour comprendre l’encodage des URI. Reproduis le problème avec le fichier TypeScript fourni dans un chemin contenant @ et compare les résultats avec l’URI encodée et non encodée. Le travail est terminé lorsque les surbrillances du document renvoient les trois correspondances pour les deux formes d’URI ; l’issue ne nomme aucun fichier de test.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
🔎 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
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 16.4k
- Merge moyen
- 1 j 11 h
- PR mergées (30 j)
- 148
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#64742 ·
Les mainteneurs répondent en général sous 1 jour
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsPeut-être pris @dmety l’a pris il y a 5 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
microsoft/TypeScript#64661 ·
Les mainteneurs répondent en général sous 1 jour
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmedPeut-être pris @RyanCavanaugh l’a pris il y a 6 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
microsoft/TypeScript#64618 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
TypeScript 7 VS Code extension: a workspace "typescript" 7.x package is not detected, only "@typescript/native-preview", which is no longer publishedPeut-être pris @jakebailey l’a pris il y a 6 jours. OuverteNeeds Investigation
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
microsoft/TypeScript#64565 · 1 réaction · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
`EFNoLeadingComments` suppresses synthesized leading comments in tsgo; Strada only suppresses source commentsPeut-être pris @weswigham l’a pris il y a 13 jours. OuverteNeeds Investigation
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
microsoft/TypeScript#64453 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de microsoft/TypeScript
Issues similaires
-
automation models
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
SocialGouv/iterion#2369 ·
Les mainteneurs répondent en général sous 1 jour
-
daemon/cluster: imageWithDigestString returns the mirror error even when upstream resolves the tagOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
area/ci bug priority/p3
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
cmd/mdatagen
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
open-telemetry/opentelemetry-collector#16150 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour