-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug where symbolKind was always undefined
- Loading branch information
1 parent
224c335
commit dd29c81
Showing
1 changed file
with
38 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,46 @@ | ||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:scip_dart/src/gen/scip.pbenum.dart'; | ||
|
||
SymbolInformation_Kind symbolKindFor(Element element) { | ||
SymbolInformation_Kind symbolKindFor(Element el) { | ||
// These mappings are declared in the same order as their symbol parsing | ||
// counterpart is declared within SymbolGenerator._getDescriptor. Ensure | ||
// this order stays consistent to ensure the correct kinds are included. | ||
final mappings = { | ||
ClassElement: SymbolInformation_Kind.Class, | ||
// MixinElement: SymbolInformation_Kind.Mixin, // Pending: https://github.com/sourcegraph/scip/pull/277 | ||
EnumElement: SymbolInformation_Kind.Enum, | ||
TypeAliasElement: SymbolInformation_Kind.TypeAlias, | ||
// ExtensionDeclaration: SymbolInformation_Kind.Extension, // Pending: https://github.com/sourcegraph/scip/pull/277 | ||
ConstructorElement: SymbolInformation_Kind.Constructor, | ||
MethodElement: SymbolInformation_Kind.Method, | ||
FunctionElement: SymbolInformation_Kind.Function, | ||
TopLevelVariableElement: SymbolInformation_Kind.Variable, | ||
PrefixElement: SymbolInformation_Kind.Namespace, | ||
TypeParameterElement: SymbolInformation_Kind.TypeParameter, | ||
ParameterElement: SymbolInformation_Kind.Parameter, | ||
PropertyAccessorElement: SymbolInformation_Kind.Property, | ||
FieldElement: SymbolInformation_Kind.Field, | ||
}; | ||
// | ||
// Note, we cannot declare this dynamically via a lookup map since the actual | ||
// type of [el], is the Impl counterpart (`ClassElementImpl`). runtimeType | ||
// type checking _does not_ take inheritance into account and `is` cannot | ||
// be used with variables. Hence the large list of if statements. | ||
if (el is ClassElement) { | ||
return SymbolInformation_Kind.Class; | ||
} else if (el is MixinElement) { | ||
// Pending: https://github.com/sourcegraph/scip/pull/277 | ||
// return SymbolInformation_Kind.Mixin; | ||
} else if (el is EnumElement) { | ||
return SymbolInformation_Kind.Enum; | ||
} else if (el is TypeAliasElement) { | ||
return SymbolInformation_Kind.TypeAlias; | ||
} else if (el is ExtensionElement) { | ||
// Pending: https://github.com/sourcegraph/scip/pull/277 | ||
// return SymbolInformation_Kind.Extension; | ||
} else if (el is ConstructorElement) { | ||
return SymbolInformation_Kind.Constructor; | ||
} else if (el is MethodElement) { | ||
return SymbolInformation_Kind.Method; | ||
} else if (el is FunctionElement) { | ||
return SymbolInformation_Kind.Function; | ||
} else if (el is TopLevelVariableElement) { | ||
return SymbolInformation_Kind.Variable; | ||
} else if (el is PrefixElement) { | ||
return SymbolInformation_Kind.Namespace; | ||
} else if (el is TypeParameterElement) { | ||
return SymbolInformation_Kind.TypeParameter; | ||
} else if (el is ParameterElement) { | ||
return SymbolInformation_Kind.Parameter; | ||
} else if (el is PropertyAccessorElement) { | ||
return SymbolInformation_Kind.Property; | ||
} else if (el is FieldElement) { | ||
return SymbolInformation_Kind.Field; | ||
} | ||
|
||
return mappings[element.runtimeType] ?? | ||
SymbolInformation_Kind.UnspecifiedKind; | ||
return SymbolInformation_Kind.UnspecifiedKind; | ||
} |