devoncarew / analysis_server_lib Goto Github PK
View Code? Open in Web Editor NEWA 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
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
another test issue
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
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
seeing if the triage bot will pick this up
It's easier to avoid typos if we have enums or static class fields representing things like the analysis error severities, types, etc.
I'm making a plugin base on analyzer_plugin, but it seems that analyzer_plugin can't receive info completion.getSuggestions2.
dart-lang/sdk#50449, this is an issue to dart team.
could analysis_server_lib support to receive and send info to analysis server? thanks
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
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 (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
--preview-dart-2
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.