Plugin: Send request error for non-moor requests (#779)

This commit is contained in:
Simon Binder 2020-08-22 19:07:51 +02:00
parent 00bce95e97
commit 527b9d731d
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 12 additions and 0 deletions

View File

@ -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<MoorRequest> _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);