From bb5f08f90fc36fa6f4e7b6f161f3dd342d921c7d Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 11 Oct 2021 10:25:50 +0200 Subject: [PATCH] Also add plugin to drift --- drift/tools/analyzer_plugin/bin/plugin.dart | 43 +++++++++++++++++++ drift/tools/analyzer_plugin/pubspec.yaml | 18 ++++++++ drift_dev/lib/src/backends/plugin/plugin.dart | 4 +- drift_dev/pubspec.yaml | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 drift/tools/analyzer_plugin/bin/plugin.dart create mode 100644 drift/tools/analyzer_plugin/pubspec.yaml diff --git a/drift/tools/analyzer_plugin/bin/plugin.dart b/drift/tools/analyzer_plugin/bin/plugin.dart new file mode 100644 index 00000000..68e45a70 --- /dev/null +++ b/drift/tools/analyzer_plugin/bin/plugin.dart @@ -0,0 +1,43 @@ +//@dart=2.6 + +import 'dart:convert'; +import 'dart:isolate'; + +import 'package:drift_dev/plugin.dart' as plugin; +import 'package:web_socket_channel/io.dart'; + +const useDebuggingVariant = false; + +void main(List args, SendPort sendPort) { + if (useDebuggingVariant) { + _PluginProxy(sendPort).start(); + } else { + plugin.start(args, sendPort); + } +} + +// Used during development. See CONTRIBUTING.md in the moor repo on how to debug +// the plugin. +class _PluginProxy { + final SendPort sendToAnalysisServer; + + ReceivePort _receive; + IOWebSocketChannel _channel; + + _PluginProxy(this.sendToAnalysisServer); + + Future start() async { + _channel = IOWebSocketChannel.connect('ws://localhost:9999'); + _receive = ReceivePort(); + sendToAnalysisServer.send(_receive.sendPort); + + _receive.listen((data) { + // the server will send messages as maps, convert to json + _channel.sink.add(json.encode(data)); + }); + + _channel.stream.listen((data) { + sendToAnalysisServer.send(json.decode(data as String)); + }); + } +} diff --git a/drift/tools/analyzer_plugin/pubspec.yaml b/drift/tools/analyzer_plugin/pubspec.yaml new file mode 100644 index 00000000..d4e056a4 --- /dev/null +++ b/drift/tools/analyzer_plugin/pubspec.yaml @@ -0,0 +1,18 @@ +name: analyzer_load_moor_plugin +version: 1.0.0 +description: This pubspec is a part of Drift and determines the version of the analyzer plugin to load + +environment: + sdk: '>=2.9.0 <3.0.0' + +dependencies: + drift_dev: ^1.0.0 + web_socket_channel: ^1.0.15 + +# These overrides are only needed when working on the plugin with useDebuggingVariant = false (not recommended) + +#dependency_overrides: +# drift_dev: +# path: /path/to/drift/drift_dev +# sqlparser: +# path: /path/to/drift/sqlparser diff --git a/drift_dev/lib/src/backends/plugin/plugin.dart b/drift_dev/lib/src/backends/plugin/plugin.dart index ef36cd39..05bab08e 100644 --- a/drift_dev/lib/src/backends/plugin/plugin.dart +++ b/drift_dev/lib/src/backends/plugin/plugin.dart @@ -41,9 +41,9 @@ class MoorPlugin extends ServerPlugin } @override - List get fileGlobsToAnalyze => const ['*.moor']; + List get fileGlobsToAnalyze => const ['*.moor', '*.drift']; @override - String get name => 'Moor plugin'; + 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 diff --git a/drift_dev/pubspec.yaml b/drift_dev/pubspec.yaml index 3339c293..8a2b27ab 100644 --- a/drift_dev/pubspec.yaml +++ b/drift_dev/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: io: ^1.0.3 # Moor-specific analysis and apis - drift: ^4.6.0 + drift: ^1.0.0 sqlite3: '>=0.1.6 <2.0.0' sqlparser: ^0.17.0