From 527b9d731d180241ce899828984c438f7cccc82c Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sat, 22 Aug 2020 19:07:51 +0200 Subject: [PATCH] Plugin: Send request error for non-moor requests (#779) --- moor_generator/lib/src/backends/plugin/plugin.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/moor_generator/lib/src/backends/plugin/plugin.dart b/moor_generator/lib/src/backends/plugin/plugin.dart index 868fbb55..b19773c2 100644 --- a/moor_generator/lib/src/backends/plugin/plugin.dart +++ b/moor_generator/lib/src/backends/plugin/plugin.dart @@ -70,8 +70,18 @@ class MoorPlugin extends BaseMoorPlugin return file; } + void _checkIsMoorFile(FoundFile file) { + if (file.type != FileType.moor) { + throw RequestFailure( + plugin.RequestError(plugin.RequestErrorCode.INVALID_PARAMETER, + 'Not a moor file: ${file.uri}'), + ); + } + } + Future _createMoorRequest(String path) async { final file = await _waitParsed(path); + _checkIsMoorFile(file); return MoorRequest(file, resourceProvider); } @@ -114,6 +124,7 @@ class MoorPlugin extends BaseMoorPlugin plugin.CompletionGetSuggestionsParams parameters) async { final path = parameters.file; final file = await _waitParsed(path); + _checkIsMoorFile(file); return MoorCompletionRequest(parameters.offset, resourceProvider, file); } @@ -138,6 +149,7 @@ class MoorPlugin extends BaseMoorPlugin plugin.AnalysisGetNavigationParams parameters) async { final path = parameters.file; final file = await _waitParsed(path); + _checkIsMoorFile(file); return MoorRequestAtPosition( file, parameters.length, parameters.offset, resourceProvider);