microsoft / microsoft/TypeScript
TSServer navtree — Way to differentiate function declarations from function expressions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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) { }
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die tsserver-navtree-Anfrage und die Konstruktion ihrer Antwort nachzuverfolgen, wobei die gemeldeten Beispiele für Funktionsdeklarationen und Funktionsausdrücke als erwartetes Verhalten dienen. Ermittle, wo kind und kindModifiers zugewiesen werden, und überprüfe anschließend, dass die Antwort Deklarationen von Ausdrücken unterscheidet, einschließlich benannter Funktionen, die const-Variablen zugewiesen sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100