Giter Site home page Giter Site logo

devoncarew / analysis_server_lib Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 5.0 315 KB

A library to access Dart's analysis server API.

Home Page: https://pub.dev/packages/analysis_server_lib

License: BSD 3-Clause "New" or "Revised" License

Dart 49.11% HTML 50.89%

analysis_server_lib's People

Contributors

dependabot[bot] avatar devoncarew avatar domesticmouse avatar parlough avatar xvrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

analysis_server_lib's Issues

Extension reference not found in search.findElementReferences

Hi,

The method search.findElementReferences doesn't find Extension's references, even though a member of that Extension is actually referenced. The extension's member reference is correctly found, but the extension itself is not.
The same thing doesn't happen with normal classes (maybe because the class constructor is explicitly called?).

Is this expected behaviour?

Code to reproduce the issue:

import 'dart:async';
import 'dart:io';

import 'package:analysis_server_lib/analysis_server_lib.dart';
import 'package:path/path.dart' as path;

class ServerHelper {
  static Future<ServerHelper> create() async {
    return ServerHelper(await AnalysisServer.create());
  }

  final AnalysisServer server;
  Directory tempDir;
  Map<String, List<AnalysisError>> errors = {};

  ServerHelper(this.server) : tempDir = Directory.systemTemp.createTempSync('tests');

  Future init() {
    server.analysis.onErrors.listen((AnalysisErrors e) {
      if (e.errors.isEmpty) {
        errors.remove(e.file);
      } else {
        errors[e.file] = e.errors;
      }
    });

    server.server.setSubscriptions(['STATUS']);
    return server.analysis.setAnalysisRoots([tempDir.path], []);
  }

  Stream get onAnalysisFinished {
    return server.server.onStatus.where((ServerStatus status) {
      return status.analysis != null && status.analysis!.isAnalyzing == false;
    });
  }

  Future<String> createFile(String filePath, String text) {
    String fullPath = path.join(tempDir.path, filePath);
    return server.analysis.updateContent(
      {fullPath: new AddContentOverlay(text)},
    ).then((_) => fullPath);
  }

  void dispose() {
    server.dispose();
    tempDir.deleteSync(recursive: true);
  }
}

Future<void> main() async {
  final helper = await ServerHelper.create();
  await helper.init();
  String main = await helper.createFile(
    'int_ext.dart',
    '''
extension FooExt on FooClass {
  bool get fooMemberExt => true;
}

class FooClass {
  bool get fooMember => true;
}

void fooBar() {
  FooClass().fooMember;
  FooClass().fooMemberExt;
}

void main(List<String> args) {
  fooBar();
}
''',
  );

  final member = await helper.server.search.getElementDeclarations(file: main);
  for (final res in member.declarations) {
    final id = await helper.server.search.findElementReferences(
      main,
      res.offset,
      true,
    );

    print('id: ${id.id} - ${id.element}');

    final sub = await helper.server.search.onResults.first;

    if (sub.results.isEmpty) {
      print('Not found: ${res.name}'); // FooExt not found, but I think it should be found
    }
  }

  helper.dispose();
}

Thanks,

Simone

Move file refactoring throwing exception

Hi,

The function edit.getRefactoring with kind 'MOVE_FILE' always throws a TypeError exception because the returned feedback is null but the RefactoringFeedback.parse function expect a Map<dynamic, dynamic>.
The exception thrown is: '_TypeError (type 'Null' is not a subtype of type 'Map<dynamic, dynamic>')', and it's thrown at line 1855 of file analysis_server_lib.dart.

Code that reproduces the issue (partially copied from your tests):

import 'dart:async';
import 'dart:io';

import 'package:analysis_server_lib/analysis_server_lib.dart';
import 'package:path/path.dart' as path;

class ServerHelper {
  static Future<ServerHelper> create() async {
    return ServerHelper(await AnalysisServer.create());
  }

  final AnalysisServer server;
  Directory tempDir;
  Map<String, List<AnalysisError>> errors = {};

  ServerHelper(this.server) : tempDir = Directory.systemTemp.createTempSync('tests');

  Future init() {
    server.analysis.onErrors.listen((AnalysisErrors e) {
      if (e.errors.isEmpty) {
        errors.remove(e.file);
      } else {
        errors[e.file] = e.errors;
      }
    });

    server.server.setSubscriptions(['STATUS']);
    return server.analysis.setAnalysisRoots([tempDir.path], []);
  }

  Stream get onAnalysisFinished {
    return server.server.onStatus.where((ServerStatus status) {
      return status.analysis != null && status.analysis!.isAnalyzing == false;
    });
  }

  Future<String> createFile(String filePath, String text) {
    String fullPath = path.join(tempDir.path, filePath);
    return server.analysis.updateContent(
      {fullPath: new AddContentOverlay(text)},
    ).then((_) => fullPath);
  }

  void dispose() {
    server.dispose();
    tempDir.deleteSync(recursive: true);
  }
}

Future<void> main() async {
  final helper = await ServerHelper.create();
  await helper.init();
  String main = await helper.createFile('old_main.dart', "foo() { }");
  RefactoringResult? result = await helper.server.edit.getRefactoring(
    Refactorings.MOVE_FILE,
    main,
    0,
    0,
    false,
    options: MoveFileRefactoringOptions(
      newFile: 'new_main.dart',
    ),
  );
  print(result);
}

Thanks,

Simone

test issue

seeing if the triage bot will pick this up

Found 23 files excluded from sound null safety

Found 23 files excluded from sound null safety (see dart-lang/sdk#49169 for context):

test/rules/null_closures_test.dart:23:// @dart=2.9
test/rules/null_closures_test.dart:31:// @dart=2.9
test/rules/null_closures_test.dart:41:// @dart=2.9
test/rules/null_closures_test.dart:51:// @dart=2.9
test/rules/prefer_collection_literals_test.dart:23:// @dart=2.9    
test/rules/prefer_collection_literals_test.dart:32:// @dart=2.9    
test/rules/prefer_collection_literals_test.dart:41:// @dart=2.9    
test_data/integration/always_require_non_null_named_parameters/lib.dart:5:// @dart=2.9
test_data/integration/avoid_private_typedef_functions/lib.dart:5:// @dart=2.9
test_data/integration/avoid_private_typedef_functions/part.dart:5:// @dart=2.9
test_data/integration/cancel_subscriptions/cancel_subscriptions.dart:5:// @dart=2.9
test_data/integration/close_sinks/src/a.dart:5:// @dart=2.9
test_data/integration/only_throw_errors/only_throw_errors.dart:5:// @dart=2.9
test_data/integration/overridden_fields/src/a.dart:5:// @dart=2.9
test_data/integration/overridden_fields/src/b.dart:5:// @dart=2.9
test_data/integration/public_member_api_docs/test/b.dart:5:// @dart=2.9
test_data/integration/use_build_context_synchronously/lib/unmigrated.dart:5:// @dart=2.9
test_data/rules/always_require_non_null_named_parameters.dart:7:// @dart=2.9
test_data/rules/avoid_init_to_null.dart:5:// @dart=2.9
test_data/rules/avoid_returning_null.dart:7:// @dart=2.9
test_data/rules/avoid_returning_null_for_future.dart:7:// @dart=2.8
test_data/rules/prefer_bool_in_asserts.dart:5:// @dart=2.9
test_data/rules/void_checks.dart:7:// @dart=2.9

Document code generation approach

The lib/analysis_server_lib.dart file contains the warning that this file is code generated. However, I can't see how to regenerate the code nor the template used to generate this file from.

The reason I ask is that I'd like to add error handling to the create method. Currently this code dies silently if run from a Flutter app, presumably on a failure to find the Dart SDK.

Found files excluded from sound null safety

Found files excluded from sound null safety (see
also dart-lang/sdk#49169):

test/rules/null_closures_test.dart:23:// @dart=2.9
test/rules/null_closures_test.dart:31:// @dart=2.9
test/rules/null_closures_test.dart:41:// @dart=2.9
test/rules/null_closures_test.dart:51:// @dart=2.9
test/rules/prefer_collection_literals_test.dart:23:// @dart=2.9    
test/rules/prefer_collection_literals_test.dart:32:// @dart=2.9    
test/rules/prefer_collection_literals_test.dart:41:// @dart=2.9    
test_data/integration/always_require_non_null_named_parameters/lib.dart:5:// @dart=2.9
test_data/integration/avoid_private_typedef_functions/lib.dart:5:// @dart=2.9
test_data/integration/avoid_private_typedef_functions/part.dart:5:// @dart=2.9
test_data/integration/cancel_subscriptions/cancel_subscriptions.dart:5:// @dart=2.9
test_data/integration/close_sinks/src/a.dart:5:// @dart=2.9
test_data/integration/only_throw_errors/only_throw_errors.dart:5:// @dart=2.9
test_data/integration/overridden_fields/src/a.dart:5:// @dart=2.9
test_data/integration/overridden_fields/src/b.dart:5:// @dart=2.9
test_data/integration/public_member_api_docs/test/b.dart:5:// @dart=2.9
test_data/integration/use_build_context_synchronously/lib/unmigrated.dart:5:// @dart=2.9
test_data/rules/always_require_non_null_named_parameters.dart:7:// @dart=2.9
test_data/rules/avoid_init_to_null.dart:5:// @dart=2.9
test_data/rules/avoid_returning_null.dart:7:// @dart=2.9
test_data/rules/avoid_returning_null_for_future.dart:7:// @dart=2.8
test_data/rules/prefer_bool_in_asserts.dart:5:// @dart=2.9
test_data/rules/void_checks.dart:7:// @dart=2.9

Extension has kind CLASS in search.getElementDeclarations

Hi,

The method search.getElementDeclarations returns kind CLASS for Extensions, but I think it should return kind EXTENSION.
Code to reproduce the issue:

import 'dart:async';
import 'dart:io';

import 'package:analysis_server_lib/analysis_server_lib.dart';
import 'package:path/path.dart' as path;

class ServerHelper {
  static Future<ServerHelper> create() async {
    return ServerHelper(await AnalysisServer.create());
  }

  final AnalysisServer server;
  Directory tempDir;
  Map<String, List<AnalysisError>> errors = {};

  ServerHelper(this.server) : tempDir = Directory.systemTemp.createTempSync('tests');

  Future init() {
    server.analysis.onErrors.listen((AnalysisErrors e) {
      if (e.errors.isEmpty) {
        errors.remove(e.file);
      } else {
        errors[e.file] = e.errors;
      }
    });

    server.server.setSubscriptions(['STATUS']);
    return server.analysis.setAnalysisRoots([tempDir.path], []);
  }

  Stream get onAnalysisFinished {
    return server.server.onStatus.where((ServerStatus status) {
      return status.analysis != null && status.analysis!.isAnalyzing == false;
    });
  }

  Future<String> createFile(String filePath, String text) {
    String fullPath = path.join(tempDir.path, filePath);
    return server.analysis.updateContent(
      {fullPath: new AddContentOverlay(text)},
    ).then((_) => fullPath);
  }

  void dispose() {
    server.dispose();
    tempDir.deleteSync(recursive: true);
  }
}

Future<void> main() async {
  final helper = await ServerHelper.create();
  await helper.init();
  String main = await helper.createFile('int_ext.dart', 'extension IntExt on int {}');

  final member = await helper.server.search.getElementDeclarations(file: main);
  for (final res in member.declarations) {
    print('${res.name} - ${res.kind}'); // prints IntExt - CLASS, but it should print IntExt - EXTENSION
  }

  helper.dispose();
}

Thanks,

Simone

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.