Skip to content

Commit dd29c81

Browse files
fixed bug where symbolKind was always undefined
1 parent 224c335 commit dd29c81

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

lib/src/kind_generator.dart

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
import 'package:analyzer/dart/element/element.dart';
22
import 'package:scip_dart/src/gen/scip.pbenum.dart';
33

4-
SymbolInformation_Kind symbolKindFor(Element element) {
4+
SymbolInformation_Kind symbolKindFor(Element el) {
55
// These mappings are declared in the same order as their symbol parsing
66
// counterpart is declared within SymbolGenerator._getDescriptor. Ensure
77
// this order stays consistent to ensure the correct kinds are included.
8-
final mappings = {
9-
ClassElement: SymbolInformation_Kind.Class,
10-
// MixinElement: SymbolInformation_Kind.Mixin, // Pending: https://github.com/sourcegraph/scip/pull/277
11-
EnumElement: SymbolInformation_Kind.Enum,
12-
TypeAliasElement: SymbolInformation_Kind.TypeAlias,
13-
// ExtensionDeclaration: SymbolInformation_Kind.Extension, // Pending: https://github.com/sourcegraph/scip/pull/277
14-
ConstructorElement: SymbolInformation_Kind.Constructor,
15-
MethodElement: SymbolInformation_Kind.Method,
16-
FunctionElement: SymbolInformation_Kind.Function,
17-
TopLevelVariableElement: SymbolInformation_Kind.Variable,
18-
PrefixElement: SymbolInformation_Kind.Namespace,
19-
TypeParameterElement: SymbolInformation_Kind.TypeParameter,
20-
ParameterElement: SymbolInformation_Kind.Parameter,
21-
PropertyAccessorElement: SymbolInformation_Kind.Property,
22-
FieldElement: SymbolInformation_Kind.Field,
23-
};
8+
//
9+
// Note, we cannot declare this dynamically via a lookup map since the actual
10+
// type of [el], is the Impl counterpart (`ClassElementImpl`). runtimeType
11+
// type checking _does not_ take inheritance into account and `is` cannot
12+
// be used with variables. Hence the large list of if statements.
13+
if (el is ClassElement) {
14+
return SymbolInformation_Kind.Class;
15+
} else if (el is MixinElement) {
16+
// Pending: https://github.com/sourcegraph/scip/pull/277
17+
// return SymbolInformation_Kind.Mixin;
18+
} else if (el is EnumElement) {
19+
return SymbolInformation_Kind.Enum;
20+
} else if (el is TypeAliasElement) {
21+
return SymbolInformation_Kind.TypeAlias;
22+
} else if (el is ExtensionElement) {
23+
// Pending: https://github.com/sourcegraph/scip/pull/277
24+
// return SymbolInformation_Kind.Extension;
25+
} else if (el is ConstructorElement) {
26+
return SymbolInformation_Kind.Constructor;
27+
} else if (el is MethodElement) {
28+
return SymbolInformation_Kind.Method;
29+
} else if (el is FunctionElement) {
30+
return SymbolInformation_Kind.Function;
31+
} else if (el is TopLevelVariableElement) {
32+
return SymbolInformation_Kind.Variable;
33+
} else if (el is PrefixElement) {
34+
return SymbolInformation_Kind.Namespace;
35+
} else if (el is TypeParameterElement) {
36+
return SymbolInformation_Kind.TypeParameter;
37+
} else if (el is ParameterElement) {
38+
return SymbolInformation_Kind.Parameter;
39+
} else if (el is PropertyAccessorElement) {
40+
return SymbolInformation_Kind.Property;
41+
} else if (el is FieldElement) {
42+
return SymbolInformation_Kind.Field;
43+
}
2444

25-
return mappings[element.runtimeType] ??
26-
SymbolInformation_Kind.UnspecifiedKind;
45+
return SymbolInformation_Kind.UnspecifiedKind;
2746
}

0 commit comments

Comments
 (0)