Remove defunct analyzer plugin

This commit is contained in:
Simon Binder
2024-12-18 22:15:39 +01:00
parent 6a30ee9789
commit 530523abdd
6 changed files with 0 additions and 200 deletions
-20
View File
@@ -71,26 +71,6 @@ used to construct common queries.
## Workflows ## Workflows
### Debugging the analyzer plugin
We have an analyzer plugin to support IDE features like auto-complete, navigation, syntax
highlighting, outline and folding to users. Normally, analyzer plugins are discovered and
loaded by the analysis server, which makes them very annoying to debug.
However, we found a way to run the plugin in isolation, which makes debugging much easier.
Note: Port 9999 has to be free for this to work, but you can change the
port defined in the two files below.
To debug the plugin, do the following:
1. In `drift/tools/analyzer_plugin/bin/plugin.dart`, set `useDebuggingVariant` to true.
2. Run `drift_dev/tool/debug_plugin.dart` as a regular Dart VM app
(this can be debugged when started from an IDE).
3. (optional) Make sure the analysis server picks up the updated version of the analysis
plugin by deleting the `~/.dartServer/.plugin_manager` folder.
4. Open a project that uses the plugin, for instance via `code extras/plugin_example`.
More details are available under `extras/plugin_example/README.md`.
### Debugging the builder ### Debugging the builder
To debug the builder, run `pub run build_runner generate-build-script` in the `drift` To debug the builder, run `pub run build_runner generate-build-script` in the `drift`
-8
View File
@@ -1,8 +0,0 @@
import 'dart:isolate';
import 'package:analyzer_plugin/starter.dart';
import 'package:drift_dev/src/backends/plugin/plugin.dart';
void start(List<String> args, SendPort sendPort) {
ServerPluginStarter(DriftPlugin.forProduction()).start(sendPort);
}
@@ -1,36 +0,0 @@
import 'package:analyzer_plugin/protocol/protocol_generated.dart';
import 'package:logging/logging.dart';
import 'plugin.dart';
var _initialized = false;
/// Configures the [Logger.root] logger to work with the plugin. Sadly, we don't
/// really have a way to view [print] outputs from plugins, so we use the
/// diagnostics notification for that.
void setupLogger(DriftPlugin plugin) {
assert(!_initialized, 'Logger initialized multiple times');
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
if (rec.level >= Level.WARNING) {
// when we send analysis errors, some tooling prompts users to create an
// issue on the Dart SDK repo for that. We're responsible for the problem
// though, so tell the user to not annoy the Dart Team with this.
final message = 'PLEASE DO NOT REPORT THIS ON dart-lang/sdk! '
'This should be reported via https://github.com/simolus3/drift/issues/new '
'instead. Message was ${rec.message}, error ${rec.error}';
final error =
PluginErrorParams(false, message, rec.stackTrace.toString());
plugin.channel.sendNotification(error.toNotification());
}
print('${rec.level.name}: ${rec.message}');
if (rec.error != null) {
print('${rec.error}: \n${rec.stackTrace}');
}
});
_initialized = true;
}
@@ -1,32 +0,0 @@
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer_plugin/plugin/plugin.dart';
import 'logger.dart';
class DriftPlugin extends ServerPlugin {
DriftPlugin(ResourceProvider provider) : super(resourceProvider: provider) {
setupLogger(this);
}
factory DriftPlugin.forProduction() {
return DriftPlugin(PhysicalResourceProvider.INSTANCE);
}
@override
List<String> get fileGlobsToAnalyze => const ['*.moor', '*.drift', '*.dart'];
@override
String get name => 'Drift plugin';
@override
// docs say that this should a version of _this_ plugin, but they lie. this
// version will be used to determine compatibility with the analyzer
String get version => '4.4.1';
@override
String get contactInfo =>
'Create an issue at https://github.com/simolus3/drift/';
@override
Future<void> analyzeFile(
{required AnalysisContext analysisContext, required String path}) async {}
}
-1
View File
@@ -40,7 +40,6 @@ dependencies:
# Dart analysis # Dart analysis
analyzer: "^6.0.0" analyzer: "^6.0.0"
analyzer_plugin: ^0.11.0
source_span: ^1.5.5 source_span: ^1.5.5
package_config: ^2.0.0 package_config: ^2.0.0
pub_semver: ^2.0.0 pub_semver: ^2.0.0
-103
View File
@@ -1,103 +0,0 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:analyzer_plugin/channel/channel.dart';
import 'package:analyzer_plugin/protocol/protocol.dart';
import 'package:args/args.dart';
import 'package:drift_dev/src/backends/plugin/plugin.dart';
import 'package:stream_transform/stream_transform.dart';
void main(List<String> args) {
final parser = ArgParser()
..addOption(
'port',
abbr: 'p',
help: 'The port to use when starting the websocket server',
defaultsTo: '9999',
);
final results = parser.parse(args);
final port = int.tryParse(results['port'] as String);
if (port == null) {
print('Port must be an int');
print(parser.usage);
return;
}
DriftPlugin.forProduction().start(_WebSocketPluginServer(port: port));
}
class _WebSocketPluginServer implements PluginCommunicationChannel {
final dynamic address;
final int port;
late HttpServer server;
WebSocket? _currentClient;
final StreamController<WebSocket?> _clientStream =
StreamController.broadcast();
_WebSocketPluginServer({dynamic address, this.port = 9999})
: address = address ?? InternetAddress.loopbackIPv4 {
_init();
}
Future<void> _init() async {
server = await HttpServer.bind(address, port);
print('listening on $address at port $port');
server.transform(WebSocketTransformer()).listen(_handleClientAdded);
}
void _handleClientAdded(WebSocket socket) {
var client = _currentClient;
if (client != null) {
print('ignoring connection attempt because an active client already '
'exists');
socket.close();
} else {
print('client connected');
client = _currentClient = socket;
_clientStream.add(client);
client.done.then((_) {
print('client disconnected');
_currentClient = null;
_clientStream.add(null);
});
}
}
@override
void close() {
server.close(force: true);
}
@override
void listen(void Function(Request request) onRequest,
{Function? onError, void Function()? onDone}) {
final stream = _clientStream.stream;
// wait until we're connected
stream.whereType<WebSocket>().first.then((socket) {
socket.listen((data) {
print('I: $data');
onRequest(Request.fromJson(
json.decode(data as String) as Map<String, dynamic>));
});
});
stream.firstWhere((socket) => socket == null).then((_) => onDone?.call());
}
@override
void sendNotification(Notification notification) {
print('N: ${notification.toJson()}');
_currentClient?.add(json.encode(notification.toJson()));
}
@override
void sendResponse(Response response) {
print('O: ${response.toJson()}');
_currentClient?.add(json.encode(response.toJson()));
}
}