mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 07:55:10 -05:00
Unify nodeKind implementations for navigationBar and navigateTo
This commit is contained in:
@@ -506,7 +506,7 @@ namespace ts.NavigationBar {
|
||||
function convertToTopLevelItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: map(n.children, convertToChildItem) || emptyChildItemArray,
|
||||
@@ -518,7 +518,7 @@ namespace ts.NavigationBar {
|
||||
function convertToChildItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: emptyChildItemArray,
|
||||
@@ -539,57 +539,6 @@ namespace ts.NavigationBar {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: GH#9145: We should just use getNodeKind. No reason why navigationBar and navigateTo should have different behaviors.
|
||||
function nodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
return ScriptElementKind.moduleElement;
|
||||
|
||||
case SyntaxKind.EnumMember:
|
||||
return ScriptElementKind.memberVariableElement;
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
let variableDeclarationNode: Node;
|
||||
let name: Node;
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
name = (<BindingElement>node).name;
|
||||
variableDeclarationNode = node;
|
||||
// binding elements are added only for variable declarations
|
||||
// bubble up to the containing variable declaration
|
||||
while (variableDeclarationNode && variableDeclarationNode.kind !== SyntaxKind.VariableDeclaration) {
|
||||
variableDeclarationNode = variableDeclarationNode.parent;
|
||||
}
|
||||
Debug.assert(!!variableDeclarationNode);
|
||||
}
|
||||
else {
|
||||
Debug.assert(!isBindingPattern((<VariableDeclaration>node).name));
|
||||
variableDeclarationNode = node;
|
||||
name = (<VariableDeclaration>node).name;
|
||||
}
|
||||
|
||||
if (isConst(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.constElement;
|
||||
}
|
||||
else if (isLet(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.letElement;
|
||||
}
|
||||
else {
|
||||
return ts.ScriptElementKind.variableElement;
|
||||
}
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return ts.ScriptElementKind.functionElement;
|
||||
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
|
||||
default:
|
||||
return getNodeKind(node);
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
|
||||
// We want to maintain quotation marks.
|
||||
if (isAmbientModule(moduleDeclaration)) {
|
||||
|
||||
@@ -1690,6 +1690,8 @@ namespace ts {
|
||||
|
||||
/** enum E */
|
||||
export const enumElement = "enum";
|
||||
// TODO: GH#9983
|
||||
export const enumMemberElement = "const";
|
||||
|
||||
/**
|
||||
* Inside module and script only
|
||||
@@ -2947,7 +2949,10 @@ namespace ts {
|
||||
|
||||
/* @internal */ export function getNodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.SourceFile:
|
||||
return isExternalModule(<SourceFile> node) ? ScriptElementKind.moduleElement : ScriptElementKind.scriptElement;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
return ScriptElementKind.classElement;
|
||||
@@ -2955,11 +2960,10 @@ namespace ts {
|
||||
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return isConst(node)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(node)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
return variableDeclarationKind(<VariableDeclaration> node);
|
||||
case SyntaxKind.BindingElement:
|
||||
return variableDeclarationKind(<VariableDeclaration> getRootDeclaration(node));
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return ScriptElementKind.functionElement;
|
||||
@@ -2976,7 +2980,7 @@ namespace ts {
|
||||
case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement;
|
||||
case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement;
|
||||
case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement;
|
||||
case SyntaxKind.Parameter: return (node.flags & NodeFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
@@ -2984,8 +2988,18 @@ namespace ts {
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return ScriptElementKind.alias;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
}
|
||||
return ScriptElementKind.unknown;
|
||||
|
||||
function variableDeclarationKind(v: VariableDeclaration): string {
|
||||
return isConst(v)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(v)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
}
|
||||
}
|
||||
|
||||
class CancellationTokenObject implements CancellationToken {
|
||||
|
||||
@@ -8,7 +8,7 @@ edit.deleteAtCaret('class Bar { }'.length);
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "Foo",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "C",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "c",
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "ABC",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "c",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "<function>",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "A",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "X",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "a",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "A",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "Test",
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "baz",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "f",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "<function>",
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "Class",
|
||||
@@ -73,7 +73,7 @@ verify.navigationBar([
|
||||
"childItems": [
|
||||
{
|
||||
"text": "LocalEnumMemberInConstructor",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
}
|
||||
],
|
||||
"indent": 3
|
||||
@@ -113,7 +113,7 @@ verify.navigationBar([
|
||||
"childItems": [
|
||||
{
|
||||
"text": "LocalEnumMemberInMethod",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
}
|
||||
],
|
||||
"indent": 3
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "dist",
|
||||
@@ -155,15 +155,15 @@ verify.navigationBar([
|
||||
"childItems": [
|
||||
{
|
||||
"text": "value1",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "value2",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "value3",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
}
|
||||
],
|
||||
"indent": 2
|
||||
|
||||
@@ -23,7 +23,7 @@ goTo.marker("file1");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "Module1",
|
||||
@@ -49,7 +49,7 @@ goTo.marker("file2");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "Module1.SubModule",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "<class>",
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "'X2.Y2.Z2'",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "\"Multiline\\\nMadness\"",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "List",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "C",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "I",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "E",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "T",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "NumberLike",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "a",
|
||||
@@ -63,7 +63,7 @@ goTo.file("file2.ts");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "a",
|
||||
@@ -104,7 +104,7 @@ goTo.file("file3.ts");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "a",
|
||||
@@ -150,7 +150,7 @@ goTo.file("file4.ts");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "A",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "x",
|
||||
@@ -34,7 +34,7 @@ goTo.file("file2.ts");
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "a",
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "numberLike",
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "dist",
|
||||
@@ -154,15 +154,15 @@ verify.navigationBar([
|
||||
"childItems": [
|
||||
{
|
||||
"text": "value1",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "value2",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "value3",
|
||||
"kind": "property"
|
||||
"kind": "const"
|
||||
}
|
||||
],
|
||||
"indent": 2
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "c",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
verify.navigationBar([
|
||||
{
|
||||
"text": "<global>",
|
||||
"kind": "module",
|
||||
"kind": "script",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "c",
|
||||
|
||||
Reference in New Issue
Block a user