Skip to content

Commit

Permalink
Merge pull request #146 from Workiva/symbol_kind
Browse files Browse the repository at this point in the history
FEDX-1648: Added symbol kind support
  • Loading branch information
rmconsole7-wk authored Sep 23, 2024
2 parents b68d95c + dd29c81 commit b24c212
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
46 changes: 46 additions & 0 deletions lib/src/kind_generator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:scip_dart/src/gen/scip.pbenum.dart';

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.
//
// 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 SymbolInformation_Kind.UnspecifiedKind;
}
10 changes: 6 additions & 4 deletions lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:package_config/package_config.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:scip_dart/src/kind_generator.dart';
import 'package:scip_dart/src/metadata.dart';
import 'package:scip_dart/src/gen/scip.pb.dart';
import 'package:scip_dart/src/relationship_generator.dart';
Expand Down Expand Up @@ -142,10 +143,10 @@ class ScipVisitor extends GeneralizingAstVisitor {
)) {
final meta = getSymbolMetadata(element, offset, _analysisErrors);
globalExternalSymbols.add(SymbolInformation(
symbol: symbol,
documentation: meta.documentation,
signatureDocumentation: meta.signatureDocumentation,
));
symbol: symbol,
documentation: meta.documentation,
signatureDocumentation: meta.signatureDocumentation,
kind: symbolKindFor(element)));
}
}
}
Expand All @@ -170,6 +171,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
documentation: meta.documentation,
relationships: relationships,
signatureDocumentation: meta.signatureDocumentation,
kind: symbolKindFor(element),
));

occurrences.add(Occurrence(
Expand Down

0 comments on commit b24c212

Please sign in to comment.