Migrate lib/src/search/workspace_symbols.dart

R=brianwilkerson@google.com

Change-Id: I14e70698e91db02f3e49ced438668d0d903bf349
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194203
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov
2021-04-07 07:08:17 +00:00
committed by commit-bot@chromium.org
parent bc924667f4
commit c5769f6604
3 changed files with 26 additions and 16 deletions
@@ -229,6 +229,8 @@ lsp.SymbolKind declarationKindToSymbolKind(
return const [lsp.SymbolKind.Enum];
case server.DeclarationKind.ENUM_CONSTANT:
return const [lsp.SymbolKind.EnumMember, lsp.SymbolKind.Enum];
case server.DeclarationKind.EXTENSION:
return const [lsp.SymbolKind.Class];
case server.DeclarationKind.FIELD:
return const [lsp.SymbolKind.Field];
case server.DeclarationKind.FUNCTION:
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import 'dart:collection';
import 'package:analyzer/source/line_info.dart';
@@ -20,9 +18,9 @@ class Declaration {
final int column;
final int codeOffset;
final int codeLength;
final String className;
final String mixinName;
final String parameters;
final String? className;
final String? mixinName;
final String? parameters;
Declaration(
this.fileIndex,
@@ -46,6 +44,7 @@ enum DeclarationKind {
CONSTRUCTOR,
ENUM,
ENUM_CONSTANT,
EXTENSION,
FIELD,
FUNCTION,
FUNCTION_TYPE_ALIAS,
@@ -62,8 +61,8 @@ class WorkspaceSymbols {
WorkspaceSymbols(this.tracker);
List<Declaration> declarations(
RegExp regExp, int maxResults, LinkedHashSet<String> files,
{String onlyForFile}) {
RegExp? regExp, int? maxResults, LinkedHashSet<String> files,
{String? onlyForFile}) {
_doTrackerWork();
var declarations = <Declaration>[];
@@ -107,14 +106,21 @@ class WorkspaceSymbols {
return;
}
String className;
if (declaration.parent?.kind == ad.DeclarationKind.CLASS) {
className = declaration.parent.name;
var parent = declaration.parent;
String? className;
if (parent != null && parent.kind == ad.DeclarationKind.CLASS) {
className = parent.name;
}
String mixinName;
if (declaration.parent?.kind == ad.DeclarationKind.MIXIN) {
mixinName = declaration.parent.name;
String? mixinName;
if (parent != null && parent.kind == ad.DeclarationKind.MIXIN) {
mixinName = parent.name;
}
var topKind = _getTopKind(declaration.kind);
if (topKind == null) {
return;
}
declarations.add(
@@ -122,7 +128,7 @@ class WorkspaceSymbols {
getPathIndex(path),
declaration.lineInfo,
name,
_getTopKind(declaration.kind),
topKind,
declaration.locationOffset,
declaration.locationStartLine,
declaration.locationStartColumn,
@@ -154,7 +160,7 @@ class WorkspaceSymbols {
}
}
static DeclarationKind _getTopKind(ad.DeclarationKind kind) {
static DeclarationKind? _getTopKind(ad.DeclarationKind kind) {
switch (kind) {
case ad.DeclarationKind.CLASS:
return DeclarationKind.CLASS;
@@ -166,6 +172,8 @@ class WorkspaceSymbols {
return DeclarationKind.ENUM;
case ad.DeclarationKind.ENUM_CONSTANT:
return DeclarationKind.ENUM_CONSTANT;
case ad.DeclarationKind.EXTENSION:
return DeclarationKind.EXTENSION;
case ad.DeclarationKind.FIELD:
return DeclarationKind.FIELD;
case ad.DeclarationKind.FUNCTION_TYPE_ALIAS:
@@ -31,7 +31,7 @@ class WorkspaceSymbolsTest extends AbstractLspAnalysisServerTest {
final namedExtensions =
symbols.firstWhere((s) => s.name == 'StringExtensions');
expect(namedExtensions.kind, equals(SymbolKind.Obj));
expect(namedExtensions.kind, equals(SymbolKind.Class));
expect(namedExtensions.containerName, isNull);
// Unnamed extensions are not returned in Workspace Symbols.