dart-lang/sdk

CompletionSuggestion not support auto import from library in vscode

zmtzawqlp opened this issue · 7 comments

This tracker is for issues related to:

  • Analyzer

I'm making a plugin base on analyzer_plugin and follow the doc https://github.com/dart-lang/sdk/blob/master/pkg/analyzer_plugin/doc/tutorial/completion.md

The problem is that libraryUri is set and isNotImported is set to true, but it still has not 'auto import from xxx' in completion. do i miss anything? or how can i do a completion with auto import library, thanks.

  /// This field is omitted if getSuggestions was used rather than
  /// getSuggestions2.
  ///
  /// This field is omitted if this suggestion corresponds to a locally
  /// declared element.
  ///
  /// If this suggestion corresponds to an already imported element, then this
  /// field is the URI of a library that provides this element, not the URI of
  /// the library where the element is declared.
  ///
  /// If this suggestion corresponds to an element from a not yet imported
  /// library, this field is the URI of a library that could be imported to
  /// make this suggestion accessible in the file where completion was
  /// requested, such as package:foo/bar.dart or
  /// file:///home/me/workspace/foo/test/bar_test.dart.
  String? libraryUri;

  /// True if the suggestion is for an element from a not yet imported library.
  /// This field is omitted if the element is declared locally, or is from
  /// library is already imported, so that the suggestion can be inserted as
  /// is, or if getSuggestions was used rather than getSuggestions2.
  bool? isNotImported;

maybe useNotImportedCompletions is not true at my side, but how can i set it?

class CompletionGetSuggestions2Result implements ResponseResult {

it seems that only analysis_server can use CompletionGetSuggestions2Result(completion.getSuggestions2).

in analyzer_plugin , it still CompletionGetSuggestionsResult.

/// Handle a 'completion.getSuggestions' request.
///
/// Throw a [RequestFailure] if the request could not be handled.
Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions(
    CompletionGetSuggestionsParams parameters) async {
  return CompletionGetSuggestionsResult(
      -1, -1, const <CompletionSuggestion>[]);
}

so libraryUri is omitted, right? in this case, then what time could we use this api? thanks for your time.

tl;dr Maybe never.

The analyzer_plugin package is an unsupported prototype of one possible way that we could support plugins for the analyzer. We actively discourage its use. And because it's not supported we don't have any plans to enhance its functionality. We do occasionally improve the code because the analysis server makes use of some of that code, but that only happens when doing so is the most convenient way for us to improve the analysis server.

I'm sad to heart that. analyzer_plugin is useful for who want to add custom lints or completions, it provides the possibility. Thank you all the same, please keep this issue open in case any update.

it seems that it support in android studio but fail in vscode, does vscode have limitation ?

This was fixed by 019fb7a (more info in Dart-Code/Dart-Code#4275 which was the same report).