From c5769f66042d1a630d5845ef6fa6eef96cad767a Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 7 Apr 2021 07:08:17 +0000 Subject: [PATCH] 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 Reviewed-by: Brian Wilkerson --- pkg/analysis_server/lib/src/lsp/mapping.dart | 2 + .../lib/src/search/workspace_symbols.dart | 38 +++++++++++-------- .../test/lsp/workspace_symbols_test.dart | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/pkg/analysis_server/lib/src/lsp/mapping.dart b/pkg/analysis_server/lib/src/lsp/mapping.dart index 1a75652a157..388fbdc742a 100644 --- a/pkg/analysis_server/lib/src/lsp/mapping.dart +++ b/pkg/analysis_server/lib/src/lsp/mapping.dart @@ -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: diff --git a/pkg/analysis_server/lib/src/search/workspace_symbols.dart b/pkg/analysis_server/lib/src/search/workspace_symbols.dart index a256782010a..ec02b7e9bca 100644 --- a/pkg/analysis_server/lib/src/search/workspace_symbols.dart +++ b/pkg/analysis_server/lib/src/search/workspace_symbols.dart @@ -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 declarations( - RegExp regExp, int maxResults, LinkedHashSet files, - {String onlyForFile}) { + RegExp? regExp, int? maxResults, LinkedHashSet files, + {String? onlyForFile}) { _doTrackerWork(); var declarations = []; @@ -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: diff --git a/pkg/analysis_server/test/lsp/workspace_symbols_test.dart b/pkg/analysis_server/test/lsp/workspace_symbols_test.dart index d20b42e7b62..915a8a348a3 100644 --- a/pkg/analysis_server/test/lsp/workspace_symbols_test.dart +++ b/pkg/analysis_server/test/lsp/workspace_symbols_test.dart @@ -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.