mirror of https://github.com/AMT-Cheif/drift.git
Avoid analyzer_plugin imports outside of plugin
This commit is contained in:
parent
c473779fba
commit
2945381213
|
@ -10,7 +10,7 @@ dependencies:
|
|||
|
||||
dev_dependencies:
|
||||
moor_generator:
|
||||
build_runner: ^1.10.1
|
||||
build_runner: ^2.0.0
|
||||
test: ^1.15.4
|
||||
|
||||
dependency_overrides:
|
||||
|
|
|
@ -11,14 +11,11 @@ import 'package:moor/src/utils/synchronized.dart';
|
|||
import 'package:moor_generator/src/analyzer/options.dart';
|
||||
import 'package:moor_generator/src/analyzer/runner/file_graph.dart';
|
||||
import 'package:moor_generator/src/analyzer/session.dart';
|
||||
import 'package:moor_generator/src/services/ide/moor_ide.dart';
|
||||
import 'package:moor_generator/src/utils/options_reader.dart' as options;
|
||||
|
||||
import '../standalone.dart';
|
||||
|
||||
class MoorDriver {
|
||||
MoorIde ide;
|
||||
|
||||
final ResourceProvider _resourceProvider;
|
||||
final Lock lock = Lock();
|
||||
|
||||
|
@ -43,7 +40,6 @@ class MoorDriver {
|
|||
|
||||
// Options will be loaded later.
|
||||
session = MoorSession(backend, options: options);
|
||||
ide = MoorIde(session, _DriverBasedFileManagement(this));
|
||||
}
|
||||
|
||||
bool _ownsFile(String path) =>
|
||||
|
@ -129,19 +125,3 @@ class MoorDriver {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _DriverBasedFileManagement implements IdeFileManagement {
|
||||
final MoorDriver driver;
|
||||
|
||||
_DriverBasedFileManagement(this.driver);
|
||||
|
||||
@override
|
||||
Uri fsPathToUri(String path) {
|
||||
return driver._resourceProvider.pathContext.toUri(path);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> waitUntilParsed(String path) {
|
||||
return driver.waitFileParsed(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import 'package:moor_generator/src/backends/plugin/services/folding.dart';
|
|||
import 'package:moor_generator/src/backends/plugin/services/navigation.dart';
|
||||
import 'package:moor_generator/src/backends/plugin/services/outline.dart';
|
||||
import 'package:moor_generator/src/backends/plugin/services/requests.dart';
|
||||
import 'package:moor_generator/src/services/ide/moor_ide.dart';
|
||||
|
||||
import 'logger.dart';
|
||||
|
||||
|
@ -164,7 +165,7 @@ class MoorPlugin extends ServerPlugin
|
|||
return;
|
||||
}
|
||||
|
||||
final highlights = await driver.ide.highlight(path);
|
||||
final highlights = await driver.ideServices.highlight(path);
|
||||
|
||||
channel.sendNotification(
|
||||
plugin.AnalysisHighlightsParams(path, highlights).toNotification());
|
||||
|
@ -199,7 +200,7 @@ class MoorPlugin extends ServerPlugin
|
|||
Future<plugin.EditGetAssistsResult> handleEditGetAssists(
|
||||
plugin.EditGetAssistsParams parameters) async {
|
||||
final driver = _moorDriverOrFail(parameters.file);
|
||||
final results = await driver.ide
|
||||
final results = await driver.ideServices
|
||||
.assists(parameters.file, parameters.offset, parameters.length);
|
||||
|
||||
return plugin.EditGetAssistsResult(results);
|
||||
|
@ -221,3 +222,28 @@ class MoorPlugin extends ServerPlugin
|
|||
file, parameters.length, parameters.offset, resourceProvider);
|
||||
}
|
||||
}
|
||||
|
||||
final _ideExpando = Expando<MoorIde>();
|
||||
|
||||
extension on MoorDriver {
|
||||
MoorIde get ideServices {
|
||||
return _ideExpando[this] ??=
|
||||
MoorIde(session, _DriverBasedFileManagement(this));
|
||||
}
|
||||
}
|
||||
|
||||
class _DriverBasedFileManagement implements IdeFileManagement {
|
||||
final MoorDriver driver;
|
||||
|
||||
_DriverBasedFileManagement(this.driver);
|
||||
|
||||
@override
|
||||
Uri fsPathToUri(String path) {
|
||||
return driver.backend.provider.pathContext.toUri(path);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> waitUntilParsed(String path) {
|
||||
return driver.waitFileParsed(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:moor_generator/src/backends/common/driver.dart';
|
|||
import 'package:moor_generator/src/cli/project.dart';
|
||||
|
||||
import 'commands/analyze.dart';
|
||||
import 'commands/debug_plugin.dart';
|
||||
import 'commands/identify_databases.dart';
|
||||
import 'commands/schema.dart';
|
||||
import 'logging.dart';
|
||||
|
@ -38,7 +37,6 @@ class MoorCli {
|
|||
)
|
||||
..addCommand(AnalyzeCommand(this))
|
||||
..addCommand(IdentifyDatabases(this))
|
||||
..addCommand(DebugPluginCommand(this))
|
||||
..addCommand(SchemaCommand(this));
|
||||
|
||||
_runner.argParser
|
||||
|
|
|
@ -1,44 +1,31 @@
|
|||
//@dart=2.9
|
||||
// @dart=2.9
|
||||
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:moor_generator/src/backends/plugin/plugin.dart';
|
||||
|
||||
import '../cli.dart';
|
||||
|
||||
class DebugPluginCommand extends MoorCommand {
|
||||
DebugPluginCommand(MoorCli cli) : super(cli) {
|
||||
argParser.addOption(
|
||||
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;
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => 'debug-plugin';
|
||||
|
||||
@override
|
||||
String get description => 'Start the analyzer plugin on a websocket server';
|
||||
|
||||
@override
|
||||
bool get hidden => true;
|
||||
|
||||
@override
|
||||
void run() {
|
||||
final port = int.tryParse(argResults['port'] as String);
|
||||
if (port == null) {
|
||||
print('Port must be an int');
|
||||
printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
MoorPlugin.forProduction().start(_WebSocketPluginServer(port: port));
|
||||
}
|
||||
MoorPlugin.forProduction().start(_WebSocketPluginServer(port: port));
|
||||
}
|
||||
|
||||
class _WebSocketPluginServer implements PluginCommunicationChannel {
|
Loading…
Reference in New Issue