microsoft / microsoft/TypeScript
TSServer navtree — Way to differentiate function declarations from function expressions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 3.3.0-dev.20181214
Search Terms:
- tsserver
- navtree
Problem
For https://github.com/Microsoft/vscode/issues/22981, we'd like a way to differentiate function delcarations from function expressions. Consider a file:
function foo(f) { }
foo(function bar() { })
const car = function dar(f) { }
VS Code uses the navtree to get possible code lens locations. We would only like to show references code lenses on function foo and perhaps on const car =, not on the expression foo(function bar() {}).
Using the navtree request against the TS Server, we cannot tell function declarations like foo from function expressions like bar :
{
"text": "bar",
"kind": "function",
"kindModifiers": "",
"spans": [
{
"start": {
"line": 3,
"offset": 5
},
"end": {
"line": 3,
"offset": 23
}
}
],
"nameSpan": {
"start": {
"line": 3,
"offset": 14
},
"end": {
"line": 3,
"offset": 17
}
}
},
{
"text": "dar",
"kind": "function",
"kindModifiers": "",
"spans": [
{
"start": {
"line": 5,
"offset": 13
},
"end": {
"line": 5,
"offset": 32
}
}
],
"nameSpan": {
"start": {
"line": 5,
"offset": 22
},
"end": {
"line": 5,
"offset": 25
}
}
},
{
"text": "foo",
"kind": "function",
"kindModifiers": "",
"spans": [
{
"start": {
"line": 1,
"offset": 1
},
"end": {
"line": 1,
"offset": 20
}
}
],
"nameSpan": {
"start": {
"line": 1,
"offset": 10
},
"end": {
"line": 1,
"offset": 13
}
}
}
]
Proposal
Differentiate:
function foo(f) { }
by using a kindModifier of "definition" or a similar name (or do the inverse and mark function bar() { } with a kindModifier of "expression")
Also, we correctly differentiate car using "kind": "const" in the case of:
const car = function(f) { }
However only dar is returned for for:
const car = function dar(f) { }
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia tracciando la richiesta navtree di tsserver e la costruzione della relativa risposta, usando come comportamento atteso gli esempi riportati di dichiarazione di funzione ed espressione di funzione. Determina dove vengono assegnati kind e kindModifiers, quindi verifica che la risposta distingua le dichiarazioni dalle espressioni, comprese le funzioni denominate assegnate a variabili const.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100