forked from qt-creator/qt-creator
LSP: reduce error handling complexity
Instead of checking recursively every possible object just check the required keys for an object and validate it on construction or assignment from json. This will reduce the implementation effort for protocol extensions and also reduce the false positives we might get if the protocol gets updated. Change-Id: I3df24e62430d2c7575d26c1581e6a9606e7da4c1 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -74,12 +74,6 @@ DidChangeTextDocumentParams::DidChangeTextDocumentParams(
|
||||
setContentChanges({TextDocumentContentChangeEvent(text)});
|
||||
}
|
||||
|
||||
bool DidChangeTextDocumentParams::isValid(ErrorHierarchy *error) const
|
||||
{
|
||||
return check<VersionedTextDocumentIdentifier>(error, textDocumentKey)
|
||||
&& checkArray<TextDocumentContentChangeEvent>(error, contentChangesKey);
|
||||
}
|
||||
|
||||
DidOpenTextDocumentParams::DidOpenTextDocumentParams(const TextDocumentItem &document)
|
||||
{
|
||||
setTextDocument(document);
|
||||
@@ -96,24 +90,11 @@ DidChangeTextDocumentParams::TextDocumentContentChangeEvent::TextDocumentContent
|
||||
setText(text);
|
||||
}
|
||||
|
||||
bool DidChangeTextDocumentParams::TextDocumentContentChangeEvent::isValid(ErrorHierarchy *error) const
|
||||
{
|
||||
return checkOptional<Range>(error, rangeKey)
|
||||
&& checkOptional<int>(error, rangeLengthKey)
|
||||
&& check<QString>(error, textKey);
|
||||
}
|
||||
|
||||
DidSaveTextDocumentParams::DidSaveTextDocumentParams(const TextDocumentIdentifier &document)
|
||||
{
|
||||
setTextDocument(document);
|
||||
}
|
||||
|
||||
bool DidSaveTextDocumentParams::isValid(ErrorHierarchy *error) const
|
||||
{
|
||||
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
||||
&& checkOptional<QString>(error, textKey);
|
||||
}
|
||||
|
||||
WillSaveTextDocumentParams::WillSaveTextDocumentParams(
|
||||
const TextDocumentIdentifier &document,
|
||||
const WillSaveTextDocumentParams::TextDocumentSaveReason &reason)
|
||||
@@ -122,16 +103,4 @@ WillSaveTextDocumentParams::WillSaveTextDocumentParams(
|
||||
setReason(reason);
|
||||
}
|
||||
|
||||
bool WillSaveTextDocumentParams::isValid(ErrorHierarchy *error) const
|
||||
{
|
||||
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
||||
&& check<int>(error, reasonKey);
|
||||
}
|
||||
|
||||
bool TextDocumentSaveRegistrationOptions::isValid(ErrorHierarchy *error) const
|
||||
{
|
||||
return TextDocumentRegistrationOptions::isValid(error)
|
||||
&& checkOptional<bool>(error, includeTextKey);
|
||||
}
|
||||
|
||||
} // namespace LanguageServerProtocol
|
||||
|
||||
Reference in New Issue
Block a user