Skip to content

Commit b24c212

Browse files
Merge pull request #146 from Workiva/symbol_kind
FEDX-1648: Added symbol kind support
2 parents b68d95c + dd29c81 commit b24c212

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

lib/src/kind_generator.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'package:analyzer/dart/element/element.dart';
2+
import 'package:scip_dart/src/gen/scip.pbenum.dart';
3+
4+
SymbolInformation_Kind symbolKindFor(Element el) {
5+
// These mappings are declared in the same order as their symbol parsing
6+
// counterpart is declared within SymbolGenerator._getDescriptor. Ensure
7+
// this order stays consistent to ensure the correct kinds are included.
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+
}
44+
45+
return SymbolInformation_Kind.UnspecifiedKind;
46+
}

lib/src/scip_visitor.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:analyzer/error/error.dart';
55
import 'package:analyzer/source/line_info.dart';
66
import 'package:package_config/package_config.dart';
77
import 'package:pubspec_parse/pubspec_parse.dart';
8+
import 'package:scip_dart/src/kind_generator.dart';
89
import 'package:scip_dart/src/metadata.dart';
910
import 'package:scip_dart/src/gen/scip.pb.dart';
1011
import 'package:scip_dart/src/relationship_generator.dart';
@@ -142,10 +143,10 @@ class ScipVisitor extends GeneralizingAstVisitor {
142143
)) {
143144
final meta = getSymbolMetadata(element, offset, _analysisErrors);
144145
globalExternalSymbols.add(SymbolInformation(
145-
symbol: symbol,
146-
documentation: meta.documentation,
147-
signatureDocumentation: meta.signatureDocumentation,
148-
));
146+
symbol: symbol,
147+
documentation: meta.documentation,
148+
signatureDocumentation: meta.signatureDocumentation,
149+
kind: symbolKindFor(element)));
149150
}
150151
}
151152
}
@@ -170,6 +171,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
170171
documentation: meta.documentation,
171172
relationships: relationships,
172173
signatureDocumentation: meta.signatureDocumentation,
174+
kind: symbolKindFor(element),
173175
));
174176

175177
occurrences.add(Occurrence(

0 commit comments

Comments
 (0)