microsoft / microsoft/TypeScript

TSServer responses requesting further files to be opened

Aperta
#45,315 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: LS: TSServer In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Background

Back in https://github.com/microsoft/TypeScript/issues/37713, I suggested that TSServer could produce several look-up locations in go-to-definition in the absence of a full project; part of the concern was that in an environment where the TypeScript server is on the same machine as the file system, it's way cheaper to perform that operation. We never went that route, though @sheetalkamat did try to create miniature projects in partial semantic mode in https://github.com/microsoft/TypeScript/pull/39476, and backed that out in https://github.com/microsoft/TypeScript/pull/40026.

Since then, partial semantic mode has been generalized to work in web settings where neither the client nor the server have all the files available at once, but the client may be in a better position to see whether a given file exists. The most we do to leverage this is in @andrewbranch's pull request at https://github.com/microsoft/TypeScript/pull/42539 which tries to construct paths from relative imports, but doesn't really work if your import needs to resolve to a .ts/.tsx file.

Idea

Coming back to the idea in https://github.com/microsoft/TypeScript/issues/37713, we could produce a result that signals to the editor that TypeScript doesn't have enough files open to produce an answer - but if the editor opens some set of files on its behalf, then it might be able to.

In other words, some sort of response type for go-to-definition that has

  • A list of entities TypeScript would like to resolve, each containing
    • the specific file paths that TypeScript needs to try to resolve to load those paths

When this information is given to the editor, the editor can try to open the set of files and send fileOpen requests to TSServer with the appropriate file content. Once that's done, TypeScript can re-request go-to-definition to produce further results.

Beyond the file transfer, adding a single file to a small program is likely not to have considerable overhead for most users.

Risks/Drawbacks

  • If opening files actually means opening editor tabs. That might not be desirable, especially if these requests have a noticeable delay. If a user closes this tab (or the tab is "ambient" and navigating away ends up closing the tab), then a user might end up with a "thrashing" editor experience where TSServer keeps trying to reload content.
  • If a re-request results in another "open more files" response, then this can result in a cascading effect that might be very slow.

This mechanism

Related work

Relative References in Partial Mode

In https://github.com/microsoft/TypeScript/pull/39476, @sheetalkamat had partial semantic mode try to construct a program out of only relative references. This was backed out in https://github.com/microsoft/TypeScript/pull/40026.

unverified Go-to-Definition Results

In https://github.com/microsoft/TypeScript/pull/42539, @andrewbranch had go-to-definition jump to files that might not actually exist. Editors had the option of handling these requests and occasionally suggesting creating a file if they didn't exist.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con i flussi delle richieste TSServer go-to-definition e fileOpen, quindi leggi le discussioni correlate nelle issues 37713 e 45315 e nelle pull requests 39476, 40026 e 42539. Chiarisci la struttura della risposta, il comportamento dell’editor e le protezioni contro le richieste ripetute di file. Il lavoro è completato solo quando sono disponibili un design del protocollo concordato e un piano di implementazione circoscritto, non soltanto un’altra proposta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.