[analysis_server] Sort types in LSP Unions consistently

This simplifies an upcoming change switching from parsing LSP TypeScript definitions to using a new JSON definition (where items are not all in the same order).

Change-Id: I773ce9ab174288ef5226b5f82f8ad7b8fb5f3693
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244245
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny
2022-05-11 15:36:34 +00:00
committed by Commit Bot
parent 80fb1a56db
commit cd71694342
15 changed files with 313 additions and 315 deletions
@@ -6788,12 +6788,12 @@ class CompletionItem implements ToJsonable {
final documentationJson = json['documentation'];
final documentation = documentationJson == null
? null
: (documentationJson is String
? Either2<String, MarkupContent>.t1(documentationJson)
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (throw '''$documentationJson was not one of (String, MarkupContent)''')));
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (documentationJson is String
? Either2<MarkupContent, String>.t2(documentationJson)
: (throw '''$documentationJson was not one of (MarkupContent, String)''')));
final deprecatedJson = json['deprecated'];
final deprecated = deprecatedJson as bool?;
final preselectJson = json['preselect'];
@@ -6815,14 +6815,14 @@ class CompletionItem implements ToJsonable {
final textEditJson = json['textEdit'];
final textEdit = textEditJson == null
? null
: (TextEdit.canParse(textEditJson, nullLspJsonReporter)
? Either2<TextEdit, InsertReplaceEdit>.t1(
TextEdit.fromJson(textEditJson as Map<String, Object?>))
: (InsertReplaceEdit.canParse(textEditJson, nullLspJsonReporter)
? Either2<TextEdit, InsertReplaceEdit>.t2(
InsertReplaceEdit.fromJson(
textEditJson as Map<String, Object?>))
: (throw '''$textEditJson was not one of (TextEdit, InsertReplaceEdit)''')));
: (InsertReplaceEdit.canParse(textEditJson, nullLspJsonReporter)
? Either2<InsertReplaceEdit, TextEdit>.t1(
InsertReplaceEdit.fromJson(
textEditJson as Map<String, Object?>))
: (TextEdit.canParse(textEditJson, nullLspJsonReporter)
? Either2<InsertReplaceEdit, TextEdit>.t2(
TextEdit.fromJson(textEditJson as Map<String, Object?>))
: (throw '''$textEditJson was not one of (InsertReplaceEdit, TextEdit)''')));
final textEditTextJson = json['textEditText'];
final textEditText = textEditTextJson as String?;
final additionalTextEditsJson = json['additionalTextEdits'];
@@ -6898,7 +6898,7 @@ class CompletionItem implements ToJsonable {
final String? detail;
/// A human-readable string that represents a doc-comment.
final Either2<String, MarkupContent>? documentation;
final Either2<MarkupContent, String>? documentation;
/// A string that should be used when filtering a set of completion items.
/// When `falsy` the label is used as the filter text for this item.
@@ -6985,7 +6985,7 @@ class CompletionItem implements ToJsonable {
/// must be a prefix of the edit's replace range, that means it must be
/// contained and starting at the same position.
/// @since 3.16.0 additional type `InsertReplaceEdit`
final Either2<TextEdit, InsertReplaceEdit>? textEdit;
final Either2<InsertReplaceEdit, TextEdit>? textEdit;
/// The edit text used if the completion item is part of a CompletionList and
/// CompletionList defines an item default for the text edit range.
@@ -7127,10 +7127,10 @@ class CompletionItem implements ToJsonable {
try {
final documentation = obj['documentation'];
if (documentation != null &&
!((documentation is String ||
MarkupContent.canParse(documentation, reporter)))) {
!((MarkupContent.canParse(documentation, reporter) ||
documentation is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -7212,10 +7212,10 @@ class CompletionItem implements ToJsonable {
try {
final textEdit = obj['textEdit'];
if (textEdit != null &&
!((TextEdit.canParse(textEdit, reporter) ||
InsertReplaceEdit.canParse(textEdit, reporter)))) {
!((InsertReplaceEdit.canParse(textEdit, reporter) ||
TextEdit.canParse(textEdit, reporter)))) {
reporter.reportError(
'must be of type Either2<TextEdit, InsertReplaceEdit>');
'must be of type Either2<InsertReplaceEdit, TextEdit>');
return false;
}
} finally {
@@ -7769,15 +7769,14 @@ class CompletionListItemDefaults implements ToJsonable {
final editRangeJson = json['editRange'];
final editRange = editRangeJson == null
? null
: (Range.canParse(editRangeJson, nullLspJsonReporter)
? Either2<Range, CompletionListEditRange>.t1(
Range.fromJson(editRangeJson as Map<String, Object?>))
: (CompletionListEditRange.canParse(
editRangeJson, nullLspJsonReporter)
? Either2<Range, CompletionListEditRange>.t2(
CompletionListEditRange.fromJson(
editRangeJson as Map<String, Object?>))
: (throw '''$editRangeJson was not one of (Range, CompletionListEditRange)''')));
: (CompletionListEditRange.canParse(editRangeJson, nullLspJsonReporter)
? Either2<CompletionListEditRange, Range>.t1(
CompletionListEditRange.fromJson(
editRangeJson as Map<String, Object?>))
: (Range.canParse(editRangeJson, nullLspJsonReporter)
? Either2<CompletionListEditRange, Range>.t2(
Range.fromJson(editRangeJson as Map<String, Object?>))
: (throw '''$editRangeJson was not one of (CompletionListEditRange, Range)''')));
final insertTextFormatJson = json['insertTextFormat'];
final insertTextFormat = insertTextFormatJson != null
? InsertTextFormat.fromJson(insertTextFormatJson as int)
@@ -7800,7 +7799,7 @@ class CompletionListItemDefaults implements ToJsonable {
/// A default edit range
/// @since 3.17.0
final Either2<Range, CompletionListEditRange>? editRange;
final Either2<CompletionListEditRange, Range>? editRange;
/// A default insert text format
/// @since 3.17.0
@@ -7845,10 +7844,10 @@ class CompletionListItemDefaults implements ToJsonable {
try {
final editRange = obj['editRange'];
if (editRange != null &&
!((Range.canParse(editRange, reporter) ||
CompletionListEditRange.canParse(editRange, reporter)))) {
!((CompletionListEditRange.canParse(editRange, reporter) ||
Range.canParse(editRange, reporter)))) {
reporter.reportError(
'must be of type Either2<Range, CompletionListEditRange>');
'must be of type Either2<CompletionListEditRange, Range>');
return false;
}
} finally {
@@ -19269,12 +19268,12 @@ class Hover implements ToJsonable {
});
static Hover fromJson(Map<String, Object?> json) {
final contentsJson = json['contents'];
final contents = contentsJson is String
? Either2<String, MarkupContent>.t1(contentsJson)
: (MarkupContent.canParse(contentsJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(
MarkupContent.fromJson(contentsJson as Map<String, Object?>))
: (throw '''$contentsJson was not one of (String, MarkupContent)'''));
final contents = MarkupContent.canParse(contentsJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(
MarkupContent.fromJson(contentsJson as Map<String, Object?>))
: (contentsJson is String
? Either2<MarkupContent, String>.t2(contentsJson)
: (throw '''$contentsJson was not one of (MarkupContent, String)'''));
final rangeJson = json['range'];
final range = rangeJson != null
? Range.fromJson(rangeJson as Map<String, Object?>)
@@ -19286,7 +19285,7 @@ class Hover implements ToJsonable {
}
/// The hover's content
final Either2<String, MarkupContent> contents;
final Either2<MarkupContent, String> contents;
/// An optional range is a range inside a text document that is used to
/// visualize a hover, e.g. by changing the background color.
@@ -19314,10 +19313,10 @@ class Hover implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!((contents is String ||
MarkupContent.canParse(contents, reporter)))) {
if (!((MarkupContent.canParse(contents, reporter) ||
contents is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -21019,16 +21018,16 @@ class InlayHint implements ToJsonable {
final positionJson = json['position'];
final position = Position.fromJson(positionJson as Map<String, Object?>);
final labelJson = json['label'];
final label = labelJson is String
? Either2<String, List<InlayHintLabelPart>>.t1(labelJson)
: ((labelJson is List<Object?> &&
(labelJson.every((item) =>
InlayHintLabelPart.canParse(item, nullLspJsonReporter))))
? Either2<String, List<InlayHintLabelPart>>.t2((labelJson)
.map((item) =>
InlayHintLabelPart.fromJson(item as Map<String, Object?>))
.toList())
: (throw '''$labelJson was not one of (String, List<InlayHintLabelPart>)'''));
final label = (labelJson is List<Object?> &&
(labelJson.every((item) =>
InlayHintLabelPart.canParse(item, nullLspJsonReporter))))
? Either2<List<InlayHintLabelPart>, String>.t1((labelJson)
.map((item) =>
InlayHintLabelPart.fromJson(item as Map<String, Object?>))
.toList())
: (labelJson is String
? Either2<List<InlayHintLabelPart>, String>.t2(labelJson)
: (throw '''$labelJson was not one of (List<InlayHintLabelPart>, String)'''));
final kindJson = json['kind'];
final kind =
kindJson != null ? InlayHintKind.fromJson(kindJson as int) : null;
@@ -21039,12 +21038,12 @@ class InlayHint implements ToJsonable {
final tooltipJson = json['tooltip'];
final tooltip = tooltipJson == null
? null
: (tooltipJson is String
? Either2<String, MarkupContent>.t1(tooltipJson)
: (MarkupContent.canParse(tooltipJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(
MarkupContent.fromJson(tooltipJson as Map<String, Object?>))
: (throw '''$tooltipJson was not one of (String, MarkupContent)''')));
: (MarkupContent.canParse(tooltipJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(
MarkupContent.fromJson(tooltipJson as Map<String, Object?>))
: (tooltipJson is String
? Either2<MarkupContent, String>.t2(tooltipJson)
: (throw '''$tooltipJson was not one of (MarkupContent, String)''')));
final paddingLeftJson = json['paddingLeft'];
final paddingLeft = paddingLeftJson as bool?;
final paddingRightJson = json['paddingRight'];
@@ -21075,7 +21074,7 @@ class InlayHint implements ToJsonable {
/// InlayHintLabelPart label parts.
///
/// *Note* that neither the string nor the label part can be empty.
final Either2<String, List<InlayHintLabelPart>> label;
final Either2<List<InlayHintLabelPart>, String> label;
/// Render padding before the hint.
///
@@ -21108,7 +21107,7 @@ class InlayHint implements ToJsonable {
///
/// Depending on the client capability `inlayHint.resolveSupport` clients
/// might resolve this property late using the resolve request.
final Either2<String, MarkupContent>? tooltip;
final Either2<MarkupContent, String>? tooltip;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
@@ -21166,12 +21165,12 @@ class InlayHint implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!((label is String ||
(label is List<Object?> &&
(label.every((item) =>
InlayHintLabelPart.canParse(item, reporter))))))) {
if (!(((label is List<Object?> &&
(label.every(
(item) => InlayHintLabelPart.canParse(item, reporter)))) ||
label is String))) {
reporter.reportError(
'must be of type Either2<String, List<InlayHintLabelPart>>');
'must be of type Either2<List<InlayHintLabelPart>, String>');
return false;
}
} finally {
@@ -21204,10 +21203,10 @@ class InlayHint implements ToJsonable {
try {
final tooltip = obj['tooltip'];
if (tooltip != null &&
!((tooltip is String ||
MarkupContent.canParse(tooltip, reporter)))) {
!((MarkupContent.canParse(tooltip, reporter) ||
tooltip is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -21495,12 +21494,12 @@ class InlayHintLabelPart implements ToJsonable {
final tooltipJson = json['tooltip'];
final tooltip = tooltipJson == null
? null
: (tooltipJson is String
? Either2<String, MarkupContent>.t1(tooltipJson)
: (MarkupContent.canParse(tooltipJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(
MarkupContent.fromJson(tooltipJson as Map<String, Object?>))
: (throw '''$tooltipJson was not one of (String, MarkupContent)''')));
: (MarkupContent.canParse(tooltipJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(
MarkupContent.fromJson(tooltipJson as Map<String, Object?>))
: (tooltipJson is String
? Either2<MarkupContent, String>.t2(tooltipJson)
: (throw '''$tooltipJson was not one of (MarkupContent, String)''')));
final locationJson = json['location'];
final location = locationJson != null
? Location.fromJson(locationJson as Map<String, Object?>)
@@ -21538,7 +21537,7 @@ class InlayHintLabelPart implements ToJsonable {
/// The tooltip text when you hover over this label part. Depending on the
/// client capability `inlayHint.resolveSupport` clients might resolve this
/// property late using the resolve request.
final Either2<String, MarkupContent>? tooltip;
final Either2<MarkupContent, String>? tooltip;
/// The value of this label part.
final String value;
@@ -21582,10 +21581,10 @@ class InlayHintLabelPart implements ToJsonable {
try {
final tooltip = obj['tooltip'];
if (tooltip != null &&
!((tooltip is String ||
MarkupContent.canParse(tooltip, reporter)))) {
!((MarkupContent.canParse(tooltip, reporter) ||
tooltip is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -25808,24 +25807,21 @@ class NotebookCellTextDocumentFilter implements ToJsonable {
});
static NotebookCellTextDocumentFilter fromJson(Map<String, Object?> json) {
final notebookJson = json['notebook'];
final notebook = notebookJson is String
? Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>.t1(
notebookJson)
: ((NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) ||
NotebookDocumentFilter2.canParse(
notebookJson, nullLspJsonReporter) ||
NotebookDocumentFilter3.canParse(
notebookJson, nullLspJsonReporter))
? Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>.t2(
NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
NotebookDocumentFilter1.fromJson(
notebookJson as Map<String, Object?>))
: (NotebookDocumentFilter2.canParse(notebookJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(
NotebookDocumentFilter2.fromJson(notebookJson as Map<String, Object?>))
: (NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookJson as Map<String, Object?>)) : (throw '''$notebookJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
: (throw '''$notebookJson was not one of (String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>)'''));
final notebook = (NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) ||
NotebookDocumentFilter2.canParse(
notebookJson, nullLspJsonReporter) ||
NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter))
? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t1(
NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(NotebookDocumentFilter1.fromJson(
notebookJson as Map<String, Object?>))
: (NotebookDocumentFilter2.canParse(notebookJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(NotebookDocumentFilter2.fromJson(
notebookJson as Map<String, Object?>))
: (NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookJson as Map<String, Object?>))
: (throw '''$notebookJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
: (notebookJson is String ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t2(notebookJson) : (throw '''$notebookJson was not one of (Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String)'''));
final languageJson = json['language'];
final language = languageJson as String?;
return NotebookCellTextDocumentFilter(
@@ -25844,9 +25840,9 @@ class NotebookCellTextDocumentFilter implements ToJsonable {
/// If a string value is provided it matches against the notebook type. '*'
/// matches every notebook.
final Either2<
String,
Either3<NotebookDocumentFilter1, NotebookDocumentFilter2,
NotebookDocumentFilter3>> notebook;
NotebookDocumentFilter3>,
String> notebook;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
@@ -25870,12 +25866,12 @@ class NotebookCellTextDocumentFilter implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!((notebook is String ||
(NotebookDocumentFilter1.canParse(notebook, reporter) ||
if (!(((NotebookDocumentFilter1.canParse(notebook, reporter) ||
NotebookDocumentFilter2.canParse(notebook, reporter) ||
NotebookDocumentFilter3.canParse(notebook, reporter))))) {
NotebookDocumentFilter3.canParse(notebook, reporter)) ||
notebook is String))) {
reporter.reportError(
'must be of type Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>');
'must be of type Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>');
return false;
}
} finally {
@@ -27340,24 +27336,21 @@ class NotebookDocumentSyncOptionsNotebookSelector implements ToJsonable {
final notebookDocumentJson = json['notebookDocument'];
final notebookDocument = notebookDocumentJson == null
? null
: (notebookDocumentJson is String
? Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>.t1(
notebookDocumentJson)
: ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) ||
NotebookDocumentFilter2.canParse(
notebookDocumentJson, nullLspJsonReporter) ||
NotebookDocumentFilter3.canParse(
notebookDocumentJson, nullLspJsonReporter))
? Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>.t2(
NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
NotebookDocumentFilter1.fromJson(
notebookDocumentJson as Map<String, Object?>))
: (NotebookDocumentFilter2.canParse(
notebookDocumentJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map<String, Object?>))
: (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map<String, Object?>)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
: (throw '''$notebookDocumentJson was not one of (String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>)''')));
: ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) ||
NotebookDocumentFilter2.canParse(
notebookDocumentJson, nullLspJsonReporter) ||
NotebookDocumentFilter3.canParse(
notebookDocumentJson, nullLspJsonReporter))
? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t1(
NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
NotebookDocumentFilter1.fromJson(
notebookDocumentJson as Map<String, Object?>))
: (NotebookDocumentFilter2.canParse(notebookDocumentJson, nullLspJsonReporter)
? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(
NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map<String, Object?>))
: (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map<String, Object?>)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
: (notebookDocumentJson is String ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t2(notebookDocumentJson) : (throw '''$notebookDocumentJson was not one of (Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String)''')));
final cellsJson = json['cells'];
final cells = (cellsJson as List<Object?>)
.map((item) => NotebookDocumentSyncOptionsCells.fromJson(
@@ -27375,9 +27368,9 @@ class NotebookDocumentSyncOptionsNotebookSelector implements ToJsonable {
/// The notebook to be synced If a string value is provided it matches against
/// the notebook type. '*' matches every notebook.
final Either2<
String,
Either3<NotebookDocumentFilter1, NotebookDocumentFilter2,
NotebookDocumentFilter3>>? notebookDocument;
NotebookDocumentFilter3>,
String>? notebookDocument;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
@@ -27394,14 +27387,14 @@ class NotebookDocumentSyncOptionsNotebookSelector implements ToJsonable {
try {
final notebookDocument = obj['notebookDocument'];
if (notebookDocument != null &&
!((notebookDocument is String ||
(NotebookDocumentFilter1.canParse(notebookDocument, reporter) ||
!(((NotebookDocumentFilter1.canParse(notebookDocument, reporter) ||
NotebookDocumentFilter2.canParse(
notebookDocument, reporter) ||
NotebookDocumentFilter3.canParse(
notebookDocument, reporter))))) {
notebookDocument, reporter)) ||
notebookDocument is String))) {
reporter.reportError(
'must be of type Either2<String, Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>>');
'must be of type Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>');
return false;
}
} finally {
@@ -27855,12 +27848,12 @@ class ParameterInformation implements ToJsonable {
final documentationJson = json['documentation'];
final documentation = documentationJson == null
? null
: (documentationJson is String
? Either2<String, MarkupContent>.t1(documentationJson)
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (throw '''$documentationJson was not one of (String, MarkupContent)''')));
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (documentationJson is String
? Either2<MarkupContent, String>.t2(documentationJson)
: (throw '''$documentationJson was not one of (MarkupContent, String)''')));
return ParameterInformation(
label: label,
documentation: documentation,
@@ -27869,7 +27862,7 @@ class ParameterInformation implements ToJsonable {
/// The human-readable doc-comment of this parameter. Will be shown in the UI
/// but can be omitted.
final Either2<String, MarkupContent>? documentation;
final Either2<MarkupContent, String>? documentation;
/// The label of this parameter information.
///
@@ -27916,10 +27909,10 @@ class ParameterInformation implements ToJsonable {
try {
final documentation = obj['documentation'];
if (documentation != null &&
!((documentation is String ||
MarkupContent.canParse(documentation, reporter)))) {
!((MarkupContent.canParse(documentation, reporter) ||
documentation is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -30268,12 +30261,12 @@ class RelativePattern implements ToJsonable {
});
static RelativePattern fromJson(Map<String, Object?> json) {
final baseUriJson = json['baseUri'];
final baseUri = WorkspaceFolder.canParse(baseUriJson, nullLspJsonReporter)
? Either2<WorkspaceFolder, String>.t1(
WorkspaceFolder.fromJson(baseUriJson as Map<String, Object?>))
: (baseUriJson is String
? Either2<WorkspaceFolder, String>.t2(baseUriJson)
: (throw '''$baseUriJson was not one of (WorkspaceFolder, String)'''));
final baseUri = baseUriJson is String
? Either2<String, WorkspaceFolder>.t1(baseUriJson)
: (WorkspaceFolder.canParse(baseUriJson, nullLspJsonReporter)
? Either2<String, WorkspaceFolder>.t2(
WorkspaceFolder.fromJson(baseUriJson as Map<String, Object?>))
: (throw '''$baseUriJson was not one of (String, WorkspaceFolder)'''));
final patternJson = json['pattern'];
final pattern = patternJson as String;
return RelativePattern(
@@ -30284,7 +30277,7 @@ class RelativePattern implements ToJsonable {
/// A workspace folder or a base URI to which this pattern will be matched
/// against relatively.
final Either2<WorkspaceFolder, String> baseUri;
final Either2<String, WorkspaceFolder> baseUri;
/// The actual glob pattern;
final String pattern;
@@ -30309,10 +30302,10 @@ class RelativePattern implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!((WorkspaceFolder.canParse(baseUri, reporter) ||
baseUri is String))) {
if (!((baseUri is String ||
WorkspaceFolder.canParse(baseUri, reporter)))) {
reporter
.reportError('must be of type Either2<WorkspaceFolder, String>');
.reportError('must be of type Either2<String, WorkspaceFolder>');
return false;
}
} finally {
@@ -34519,16 +34512,16 @@ class ServerCapabilities implements ToJsonable {
final textDocumentSyncJson = json['textDocumentSync'];
final textDocumentSync = textDocumentSyncJson == null
? null
: (TextDocumentSyncOptions.canParse(
: (TextDocumentSyncKind.canParse(
textDocumentSyncJson, nullLspJsonReporter)
? Either2<TextDocumentSyncOptions, TextDocumentSyncKind>.t1(
TextDocumentSyncOptions.fromJson(
textDocumentSyncJson as Map<String, Object?>))
: (TextDocumentSyncKind.canParse(
? Either2<TextDocumentSyncKind, TextDocumentSyncOptions>.t1(
TextDocumentSyncKind.fromJson(textDocumentSyncJson as int))
: (TextDocumentSyncOptions.canParse(
textDocumentSyncJson, nullLspJsonReporter)
? Either2<TextDocumentSyncOptions, TextDocumentSyncKind>.t2(
TextDocumentSyncKind.fromJson(textDocumentSyncJson as int))
: (throw '''$textDocumentSyncJson was not one of (TextDocumentSyncOptions, TextDocumentSyncKind)''')));
? Either2<TextDocumentSyncKind, TextDocumentSyncOptions>.t2(
TextDocumentSyncOptions.fromJson(
textDocumentSyncJson as Map<String, Object?>))
: (throw '''$textDocumentSyncJson was not one of (TextDocumentSyncKind, TextDocumentSyncOptions)''')));
final notebookDocumentSyncJson = json['notebookDocumentSync'];
final notebookDocumentSync = notebookDocumentSyncJson == null
? null
@@ -35096,7 +35089,7 @@ class ServerCapabilities implements ToJsonable {
/// defining each notification or for backwards compatibility the
/// TextDocumentSyncKind number. If omitted it defaults to
/// `TextDocumentSyncKind.None`.
final Either2<TextDocumentSyncOptions, TextDocumentSyncKind>?
final Either2<TextDocumentSyncKind, TextDocumentSyncOptions>?
textDocumentSync;
/// The server provides goto type definition support.
@@ -35244,10 +35237,11 @@ class ServerCapabilities implements ToJsonable {
try {
final textDocumentSync = obj['textDocumentSync'];
if (textDocumentSync != null &&
!((TextDocumentSyncOptions.canParse(textDocumentSync, reporter) ||
TextDocumentSyncKind.canParse(textDocumentSync, reporter)))) {
!((TextDocumentSyncKind.canParse(textDocumentSync, reporter) ||
TextDocumentSyncOptions.canParse(
textDocumentSync, reporter)))) {
reporter.reportError(
'must be of type Either2<TextDocumentSyncOptions, TextDocumentSyncKind>');
'must be of type Either2<TextDocumentSyncKind, TextDocumentSyncOptions>');
return false;
}
} finally {
@@ -37953,12 +37947,12 @@ class SignatureInformation implements ToJsonable {
final documentationJson = json['documentation'];
final documentation = documentationJson == null
? null
: (documentationJson is String
? Either2<String, MarkupContent>.t1(documentationJson)
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<String, MarkupContent>.t2(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (throw '''$documentationJson was not one of (String, MarkupContent)''')));
: (MarkupContent.canParse(documentationJson, nullLspJsonReporter)
? Either2<MarkupContent, String>.t1(MarkupContent.fromJson(
documentationJson as Map<String, Object?>))
: (documentationJson is String
? Either2<MarkupContent, String>.t2(documentationJson)
: (throw '''$documentationJson was not one of (MarkupContent, String)''')));
final parametersJson = json['parameters'];
final parameters = (parametersJson as List<Object?>?)
?.map((item) =>
@@ -37982,7 +37976,7 @@ class SignatureInformation implements ToJsonable {
/// The human-readable doc-comment of this signature. Will be shown in the UI
/// but can be omitted.
final Either2<String, MarkupContent>? documentation;
final Either2<MarkupContent, String>? documentation;
/// The label of this signature. Will be shown in the UI.
final String label;
@@ -38030,10 +38024,10 @@ class SignatureInformation implements ToJsonable {
try {
final documentation = obj['documentation'];
if (documentation != null &&
!((documentation is String ||
MarkupContent.canParse(documentation, reporter)))) {
!((MarkupContent.canParse(documentation, reporter) ||
documentation is String))) {
reporter
.reportError('must be of type Either2<String, MarkupContent>');
.reportError('must be of type Either2<MarkupContent, String>');
return false;
}
} finally {
@@ -39683,16 +39677,16 @@ class TextDocumentEdit implements ToJsonable {
textDocumentJson as Map<String, Object?>);
final editsJson = json['edits'];
final edits = (editsJson as List<Object?>)
.map((item) => SnippetTextEdit.canParse(item, nullLspJsonReporter)
? Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>.t1(
SnippetTextEdit.fromJson(item as Map<String, Object?>))
: (AnnotatedTextEdit.canParse(item, nullLspJsonReporter)
? Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>.t2(
AnnotatedTextEdit.fromJson(item as Map<String, Object?>))
.map((item) => AnnotatedTextEdit.canParse(item, nullLspJsonReporter)
? Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>.t1(
AnnotatedTextEdit.fromJson(item as Map<String, Object?>))
: (SnippetTextEdit.canParse(item, nullLspJsonReporter)
? Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>.t2(
SnippetTextEdit.fromJson(item as Map<String, Object?>))
: (TextEdit.canParse(item, nullLspJsonReporter)
? Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>.t3(
? Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>.t3(
TextEdit.fromJson(item as Map<String, Object?>))
: (throw '''$item was not one of (SnippetTextEdit, AnnotatedTextEdit, TextEdit)'''))))
: (throw '''$item was not one of (AnnotatedTextEdit, SnippetTextEdit, TextEdit)'''))))
.toList();
return TextDocumentEdit(
textDocument: textDocument,
@@ -39703,7 +39697,7 @@ class TextDocumentEdit implements ToJsonable {
/// The edits to be applied.
/// @since 3.16.0 - support for AnnotatedTextEdit. This is guarded by the
/// client capability `workspace.workspaceEdit.changeAnnotationSupport`
final List<Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>> edits;
final List<Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>> edits;
/// The text document to change.
final OptionalVersionedTextDocumentIdentifier textDocument;
@@ -39749,11 +39743,12 @@ class TextDocumentEdit implements ToJsonable {
return false;
}
if (!((edits is List<Object?> &&
(edits.every((item) => (SnippetTextEdit.canParse(item, reporter) ||
AnnotatedTextEdit.canParse(item, reporter) ||
TextEdit.canParse(item, reporter))))))) {
(edits.every((item) =>
(AnnotatedTextEdit.canParse(item, reporter) ||
SnippetTextEdit.canParse(item, reporter) ||
TextEdit.canParse(item, reporter))))))) {
reporter.reportError(
'must be of type List<Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>>');
'must be of type List<Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>>');
return false;
}
} finally {
@@ -39773,8 +39768,8 @@ class TextDocumentEdit implements ToJsonable {
listEqual(
edits,
other.edits,
(Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit> a,
Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>
(Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit> a,
Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>
b) =>
a == b) &&
true;
@@ -44246,20 +44241,22 @@ class WorkspaceEdit implements ToJsonable {
? null
: ((documentChangesJson is List<Object?> &&
(documentChangesJson.every((item) =>
TextDocumentEdit.canParse(item, nullLspJsonReporter))))
? Either2<List<TextDocumentEdit>, List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>.t1((documentChangesJson)
.map((item) =>
TextDocumentEdit.fromJson(item as Map<String, Object?>))
(CreateFile.canParse(item, nullLspJsonReporter) ||
DeleteFile.canParse(item, nullLspJsonReporter) ||
RenameFile.canParse(item, nullLspJsonReporter) ||
TextDocumentEdit.canParse(item, nullLspJsonReporter)))))
? Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>, List<TextDocumentEdit>>.t1((documentChangesJson)
.map((item) => CreateFile.canParse(item, nullLspJsonReporter)
? Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t1(
CreateFile.fromJson(item as Map<String, Object?>))
: (DeleteFile.canParse(item, nullLspJsonReporter)
? Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t2(
DeleteFile.fromJson(item as Map<String, Object?>))
: (RenameFile.canParse(item, nullLspJsonReporter)
? Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t3(RenameFile.fromJson(item as Map<String, Object?>))
: (TextDocumentEdit.canParse(item, nullLspJsonReporter) ? Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t4(TextDocumentEdit.fromJson(item as Map<String, Object?>)) : (throw '''$item was not one of (CreateFile, DeleteFile, RenameFile, TextDocumentEdit)''')))))
.toList())
: ((documentChangesJson is List<Object?> &&
(documentChangesJson.every((item) =>
(TextDocumentEdit.canParse(item, nullLspJsonReporter) ||
CreateFile.canParse(item, nullLspJsonReporter) ||
RenameFile.canParse(item, nullLspJsonReporter) ||
DeleteFile.canParse(item, nullLspJsonReporter)))))
? Either2<List<TextDocumentEdit>, List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>.t2(
(documentChangesJson).map((item) => TextDocumentEdit.canParse(item, nullLspJsonReporter) ? Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t1(TextDocumentEdit.fromJson(item as Map<String, Object?>)) : (CreateFile.canParse(item, nullLspJsonReporter) ? Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t2(CreateFile.fromJson(item as Map<String, Object?>)) : (RenameFile.canParse(item, nullLspJsonReporter) ? Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t3(RenameFile.fromJson(item as Map<String, Object?>)) : (DeleteFile.canParse(item, nullLspJsonReporter) ? Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t4(DeleteFile.fromJson(item as Map<String, Object?>)) : (throw '''$item was not one of (TextDocumentEdit, CreateFile, RenameFile, DeleteFile)'''))))).toList())
: (throw '''$documentChangesJson was not one of (List<TextDocumentEdit>, List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>)''')));
: ((documentChangesJson is List<Object?> && (documentChangesJson.every((item) => TextDocumentEdit.canParse(item, nullLspJsonReporter)))) ? Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>, List<TextDocumentEdit>>.t2((documentChangesJson).map((item) => TextDocumentEdit.fromJson(item as Map<String, Object?>)).toList()) : (throw '''$documentChangesJson was not one of (List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>, List<TextDocumentEdit>)''')));
final changeAnnotationsJson = json['changeAnnotations'];
final changeAnnotations = (changeAnnotationsJson as Map<Object, Object?>?)
?.map((key, value) => MapEntry(key as String,
@@ -44295,9 +44292,9 @@ class WorkspaceEdit implements ToJsonable {
/// If a client neither supports `documentChanges` nor
/// `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s
/// using the `changes` property are supported.
final Either2<List<TextDocumentEdit>,
List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>?
documentChanges;
final Either2<
List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>,
List<TextDocumentEdit>>? documentChanges;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
@@ -44337,15 +44334,15 @@ class WorkspaceEdit implements ToJsonable {
if (documentChanges != null &&
!(((documentChanges is List<Object?> &&
(documentChanges.every((item) =>
TextDocumentEdit.canParse(item, reporter)))) ||
(CreateFile.canParse(item, reporter) ||
DeleteFile.canParse(item, reporter) ||
RenameFile.canParse(item, reporter) ||
TextDocumentEdit.canParse(item, reporter))))) ||
(documentChanges is List<Object?> &&
(documentChanges.every((item) =>
(TextDocumentEdit.canParse(item, reporter) ||
CreateFile.canParse(item, reporter) ||
RenameFile.canParse(item, reporter) ||
DeleteFile.canParse(item, reporter)))))))) {
TextDocumentEdit.canParse(item, reporter))))))) {
reporter.reportError(
'must be of type Either2<List<TextDocumentEdit>, List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>');
'must be of type Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>, List<TextDocumentEdit>>');
return false;
}
} finally {
@@ -44875,11 +44872,11 @@ class WorkspaceFoldersServerCapabilities implements ToJsonable {
final changeNotificationsJson = json['changeNotifications'];
final changeNotifications = changeNotificationsJson == null
? null
: (changeNotificationsJson is String
? Either2<String, bool>.t1(changeNotificationsJson)
: (changeNotificationsJson is bool
? Either2<String, bool>.t2(changeNotificationsJson)
: (throw '''$changeNotificationsJson was not one of (String, bool)''')));
: (changeNotificationsJson is bool
? Either2<bool, String>.t1(changeNotificationsJson)
: (changeNotificationsJson is String
? Either2<bool, String>.t2(changeNotificationsJson)
: (throw '''$changeNotificationsJson was not one of (bool, String)''')));
return WorkspaceFoldersServerCapabilities(
supported: supported,
changeNotifications: changeNotifications,
@@ -44892,7 +44889,7 @@ class WorkspaceFoldersServerCapabilities implements ToJsonable {
/// notification is registered on the client side. The ID can be used to
/// unregister for these events using the `client/unregisterCapability`
/// request.
final Either2<String, bool>? changeNotifications;
final Either2<bool, String>? changeNotifications;
/// The server has support for workspace folders
final bool? supported;
@@ -44924,8 +44921,8 @@ class WorkspaceFoldersServerCapabilities implements ToJsonable {
try {
final changeNotifications = obj['changeNotifications'];
if (changeNotifications != null &&
!((changeNotifications is String || changeNotifications is bool))) {
reporter.reportError('must be of type Either2<String, bool>');
!((changeNotifications is bool || changeNotifications is String))) {
reporter.reportError('must be of type Either2<bool, String>');
return false;
}
} finally {
@@ -98,7 +98,7 @@ class DartTypeArgumentsSignatureComputer {
lsp.SignatureInformation(
label: label,
documentation: documentation != null
? asStringOrMarkupContent(preferredFormats, documentation)
? asMarkupContentOrString(preferredFormats, documentation)
: null,
parameters: parameters,
),
@@ -120,7 +120,7 @@ class CompletionResolveHandler
final dartDoc =
analyzer.getDartDocPlainText(element.documentationComment);
final documentation =
dartDoc != null ? asStringOrMarkupContent(formats, dartDoc) : null;
dartDoc != null ? asMarkupContentOrString(formats, dartDoc) : null;
final supportsInsertReplace =
clientCapabilities.insertReplaceCompletionRanges;
@@ -152,14 +152,14 @@ class CompletionResolveHandler
insertText: newInsertText,
insertTextFormat: item.insertTextFormat,
textEdit: supportsInsertReplace && insertionRange != replacementRange
? Either2<TextEdit, InsertReplaceEdit>.t2(
? Either2<InsertReplaceEdit, TextEdit>.t1(
InsertReplaceEdit(
insert: insertionRange,
replace: replacementRange,
newText: newInsertText,
),
)
: Either2<TextEdit, InsertReplaceEdit>.t1(
: Either2<InsertReplaceEdit, TextEdit>.t2(
TextEdit(
range: replacementRange,
newText: newInsertText,
@@ -253,7 +253,7 @@ class CompletionResolveHandler
tags: item.tags,
detail: item.detail,
documentation: description != null
? Either2<String, MarkupContent>.t1(description)
? Either2<MarkupContent, String>.t2(description)
: null,
deprecated: item.deprecated,
preselect: item.preselect,
@@ -84,7 +84,7 @@ class HoverHandler extends MessageHandler<TextDocumentPositionParams, Hover?> {
final formats = server.clientCapabilities?.hoverContentFormats;
return Hover(
contents:
asStringOrMarkupContent(formats, content.toString().trimRight()),
asMarkupContentOrString(formats, content.toString().trimRight()),
range: toRange(lineInfo, hover.offset, hover.length),
);
}
+39 -43
View File
@@ -57,12 +57,12 @@ final diagnosticTagsForErrorCode = <String, List<lsp.DiagnosticTag>>{
/// field.
final _upgradableDocCompletePattern = RegExp(r'^_([\w ]{0,20})_$');
lsp.Either2<String, lsp.MarkupContent> asStringOrMarkupContent(
lsp.Either2<lsp.MarkupContent, String> asMarkupContentOrString(
Set<lsp.MarkupKind>? preferredFormats, String content) {
return preferredFormats == null
? lsp.Either2<String, lsp.MarkupContent>.t1(content)
: lsp.Either2<String, lsp.MarkupContent>.t2(
_asMarkup(preferredFormats, content));
return preferredFormats != null
? lsp.Either2<lsp.MarkupContent, String>.t1(
_asMarkup(preferredFormats, content))
: lsp.Either2<lsp.MarkupContent, String>.t2(content);
}
/// Creates a [lsp.WorkspaceEdit] from simple [server.SourceFileEdit]s.
@@ -93,7 +93,7 @@ lsp.WorkspaceEdit createPlainWorkspaceEdit(
/// Create a [WorkspaceEdit] that renames [oldPath] to [newPath].
WorkspaceEdit createRenameEdit(String oldPath, String newPath) {
final changes =
<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>[];
<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>[];
final rename = RenameFile(
oldUri: Uri.file(oldPath).toString(),
@@ -101,16 +101,14 @@ WorkspaceEdit createRenameEdit(String oldPath, String newPath) {
);
final renameUnion =
Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t3(rename);
Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t3(rename);
changes.add(renameUnion);
final edit = WorkspaceEdit(
documentChanges: Either2<
List<TextDocumentEdit>,
List<
Either4<TextDocumentEdit, CreateFile, RenameFile,
DeleteFile>>>.t2(changes));
List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>,
List<TextDocumentEdit>>.t1(changes));
return edit;
}
@@ -164,21 +162,21 @@ lsp.WorkspaceEdit createWorkspaceEdit(
final textDocumentEdit = lsp.TextDocumentEdit(
textDocument: server.getVersionedDocumentIdentifier(fileEdit.file),
edits: snippetEdits
.map((e) => Either3<lsp.SnippetTextEdit, lsp.AnnotatedTextEdit,
lsp.TextEdit>.t1(e))
.map((e) => Either3<lsp.AnnotatedTextEdit, lsp.SnippetTextEdit,
lsp.TextEdit>.t2(e))
.toList(),
);
// Convert to the union that documentChanges require.
final textDocumentEditsAsUnion = Either4<lsp.TextDocumentEdit, lsp.CreateFile,
lsp.RenameFile, lsp.DeleteFile>.t1(textDocumentEdit);
final textDocumentEditsAsUnion = Either4<lsp.CreateFile, lsp.DeleteFile,
lsp.RenameFile, lsp.TextDocumentEdit>.t4(textDocumentEdit);
// Convert to the union that documentChanges is.
final documentChanges = Either2<
List<lsp.TextDocumentEdit>,
List<
Either4<lsp.TextDocumentEdit, lsp.CreateFile, lsp.RenameFile,
lsp.DeleteFile>>>.t2([textDocumentEditsAsUnion]);
Either4<lsp.CreateFile, lsp.DeleteFile, lsp.RenameFile,
lsp.TextDocumentEdit>>,
List<lsp.TextDocumentEdit>>.t1([textDocumentEditsAsUnion]);
/// Add the textDocumentEdit to a WorkspaceEdit.
return lsp.WorkspaceEdit(documentChanges: documentChanges);
@@ -695,24 +693,22 @@ WorkspaceEdit mergeWorkspaceEdits(List<WorkspaceEdit> edits) {
// TODO(dantup): This method (and much other code here) should be
// significantly tidied up when nonfunction-type-aliases is available here.
final changes =
<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>[];
<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>[];
for (final edit in edits) {
// Flatten the Either into just the Union side to get a flat list.
final flatResourceChanges = edit.documentChanges!.map(
(edits) => edits.map((e) =>
Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>.t1(e)),
(resources) => resources,
(edits) => edits.map((e) =>
Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>.t4(e)),
);
changes.addAll(flatResourceChanges);
}
return WorkspaceEdit(
documentChanges: Either2<
List<TextDocumentEdit>,
List<
Either4<TextDocumentEdit, CreateFile, RenameFile,
DeleteFile>>>.t2(changes));
List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>,
List<TextDocumentEdit>>.t1(changes));
}
lsp.Location navigationTargetToLocation(
@@ -1022,7 +1018,7 @@ lsp.CompletionItem snippetToCompletionItem(
kind: lsp.CompletionItemKind.Snippet,
command: command,
documentation: documentation != null
? asStringOrMarkupContent(formats, documentation)
? asMarkupContentOrString(formats, documentation)
: null,
// Force snippets to be sorted at the bottom of the list.
// TODO(dantup): Consider if we can rank these better. Client-side
@@ -1031,7 +1027,7 @@ lsp.CompletionItem snippetToCompletionItem(
sortText: 'zzz${snippet.prefix}',
insertTextFormat: lsp.InsertTextFormat.Snippet,
insertTextMode: supportsAsIsInsertMode ? InsertTextMode.asIs : null,
textEdit: Either2<TextEdit, InsertReplaceEdit>.t1(mainEdit),
textEdit: Either2<InsertReplaceEdit, TextEdit>.t2(mainEdit),
additionalTextEdits: nonMainEdits,
);
}
@@ -1222,7 +1218,7 @@ lsp.CompletionItem toCompletionItem(
data: resolutionData,
detail: detail,
documentation: cleanedDoc != null
? asStringOrMarkupContent(formats, cleanedDoc)
? asMarkupContentOrString(formats, cleanedDoc)
: null,
deprecated: supportsCompletionDeprecatedFlag && suggestion.isDeprecated
? true
@@ -1243,14 +1239,14 @@ lsp.CompletionItem toCompletionItem(
textEdit: (insertionRange == null || replacementRange == null)
? null
: supportsInsertReplace && insertionRange != replacementRange
? Either2<TextEdit, InsertReplaceEdit>.t2(
? Either2<InsertReplaceEdit, TextEdit>.t1(
InsertReplaceEdit(
insert: insertionRange,
replace: replacementRange,
newText: insertText,
),
)
: Either2<TextEdit, InsertReplaceEdit>.t1(
: Either2<InsertReplaceEdit, TextEdit>.t2(
TextEdit(
range: replacementRange,
newText: insertText,
@@ -1476,7 +1472,7 @@ lsp.SignatureHelp toSignatureHelp(Set<lsp.MarkupKind>? preferredFormats,
lsp.SignatureInformation(
label: getSignatureLabel(signature),
documentation: cleanedDoc != null
? asStringOrMarkupContent(preferredFormats, cleanedDoc)
? asMarkupContentOrString(preferredFormats, cleanedDoc)
: null,
parameters: signature.parameters.map(toParameterInfo).toList(),
),
@@ -1562,7 +1558,7 @@ lsp.TextDocumentEdit toTextDocumentEdit(
.toList());
}
Either3<lsp.SnippetTextEdit, lsp.AnnotatedTextEdit, lsp.TextEdit>
Either3<lsp.AnnotatedTextEdit, lsp.SnippetTextEdit, lsp.TextEdit>
toTextDocumentEditEdit(
LspClientCapabilities capabilities,
server.LineInfo lineInfo,
@@ -1572,10 +1568,10 @@ Either3<lsp.SnippetTextEdit, lsp.AnnotatedTextEdit, lsp.TextEdit>
}) {
if (!capabilities.experimentalSnippetTextEdit ||
selectionOffsetRelative == null) {
return Either3<lsp.SnippetTextEdit, lsp.AnnotatedTextEdit, lsp.TextEdit>.t3(
return Either3<lsp.AnnotatedTextEdit, lsp.SnippetTextEdit, lsp.TextEdit>.t3(
toTextEdit(lineInfo, edit));
}
return Either3<lsp.SnippetTextEdit, lsp.AnnotatedTextEdit, lsp.TextEdit>.t1(
return Either3<lsp.AnnotatedTextEdit, lsp.SnippetTextEdit, lsp.TextEdit>.t2(
snippetTextEditWithSelection(lineInfo, edit,
selectionOffsetRelative: selectionOffsetRelative,
selectionLength: selectionLength));
@@ -1596,8 +1592,8 @@ lsp.WorkspaceEdit toWorkspaceEdit(
if (supportsDocumentChanges) {
final supportsCreate = capabilities.createResourceOperations;
final changes = <
Either4<lsp.TextDocumentEdit, lsp.CreateFile, lsp.RenameFile,
lsp.DeleteFile>>[];
Either4<lsp.CreateFile, lsp.DeleteFile, lsp.RenameFile,
lsp.TextDocumentEdit>>[];
// Convert each SourceEdit to either a TextDocumentEdit or a
// CreateFile + a TextDocumentEdit depending on whether it's a new
@@ -1605,23 +1601,23 @@ lsp.WorkspaceEdit toWorkspaceEdit(
for (final edit in edits) {
if (supportsCreate && edit.newFile) {
final create = lsp.CreateFile(uri: edit.doc.uri);
final createUnion = Either4<lsp.TextDocumentEdit, lsp.CreateFile,
lsp.RenameFile, lsp.DeleteFile>.t2(create);
final createUnion = Either4<lsp.CreateFile, lsp.DeleteFile,
lsp.RenameFile, lsp.TextDocumentEdit>.t1(create);
changes.add(createUnion);
}
final textDocEdit = toTextDocumentEdit(capabilities, edit);
final textDocEditUnion = Either4<lsp.TextDocumentEdit, lsp.CreateFile,
lsp.RenameFile, lsp.DeleteFile>.t1(textDocEdit);
final textDocEditUnion = Either4<lsp.CreateFile, lsp.DeleteFile,
lsp.RenameFile, lsp.TextDocumentEdit>.t4(textDocEdit);
changes.add(textDocEditUnion);
}
return lsp.WorkspaceEdit(
documentChanges: Either2<
List<lsp.TextDocumentEdit>,
List<
Either4<lsp.TextDocumentEdit, lsp.CreateFile, lsp.RenameFile,
lsp.DeleteFile>>>.t2(changes));
Either4<lsp.CreateFile, lsp.DeleteFile, lsp.RenameFile,
lsp.TextDocumentEdit>>,
List<lsp.TextDocumentEdit>>.t1(changes));
} else {
return lsp.WorkspaceEdit(changes: toWorkspaceEditChanges(edits));
}
@@ -167,7 +167,7 @@ class ServerCapabilitiesComputer {
return ServerCapabilities(
textDocumentSync: dynamicRegistrations.textSync
? null
: Either2<TextDocumentSyncOptions, TextDocumentSyncKind>.t1(
: Either2<TextDocumentSyncKind, TextDocumentSyncOptions>.t2(
TextDocumentSyncOptions(
// The open/close and sync kind flags are registered dynamically if the
// client supports them, so these static registrations are based on whether
@@ -279,7 +279,7 @@ class ServerCapabilitiesComputer {
workspace: ServerCapabilitiesWorkspace(
workspaceFolders: WorkspaceFoldersServerCapabilities(
supported: true,
changeNotifications: Either2<String, bool>.t2(true),
changeNotifications: Either2<bool, String>.t1(true),
),
fileOperations: dynamicRegistrations.fileOperations
? null
@@ -390,8 +390,8 @@ class AssistsCodeActionsTest extends AbstractCodeActionsTest {
final textEdits = _extractTextDocumentEdits(edit.documentChanges!)
.expand((tde) => tde.edits)
.map((edit) => edit.map(
(e) => e,
(e) => throw 'Expected SnippetTextEdit, got AnnotatedTextEdit',
(e) => e,
(e) => throw 'Expected SnippetTextEdit, got TextEdit',
))
.toList();
@@ -535,8 +535,8 @@ void f() {
final textEdits = _extractTextDocumentEdits(edit.documentChanges!)
.expand((tde) => tde.edits)
.map((edit) => edit.map(
(e) => e,
(e) => throw 'Expected SnippetTextEdit, got AnnotatedTextEdit',
(e) => e,
(e) => throw 'Expected SnippetTextEdit, got TextEdit',
))
.toList();
@@ -546,26 +546,26 @@ void f() {
List<TextDocumentEdit> _extractTextDocumentEdits(
Either2<
List<TextDocumentEdit>,
List<
Either4<TextDocumentEdit, CreateFile, RenameFile,
DeleteFile>>>
Either4<CreateFile, DeleteFile, RenameFile,
TextDocumentEdit>>,
List<TextDocumentEdit>>
documentChanges) =>
documentChanges.map(
// Already TextDocumentEdits
(edits) => edits,
// Extract TextDocumentEdits from union of resource changes
(changes) => changes
.map(
(change) => change.map(
(textDocEdit) => textDocEdit,
(create) => null,
(rename) => null,
(delete) => null,
(rename) => null,
(textDocEdit) => textDocEdit,
),
)
.whereNotNull()
.toList(),
// Already TextDocumentEdits
(edits) => edits,
);
}
+4 -4
View File
@@ -350,15 +350,15 @@ Type: `String`
MarkupContent _getMarkupContents(Hover hover) {
return hover.contents.map(
(t1) => throw 'Hover contents were String, not MarkupContent',
(t2) => t2,
(t1) => t1,
(t2) => throw 'Hover contents were String, not MarkupContent',
);
}
String _getStringContents(Hover hover) {
return hover.contents.map(
(t1) => t1,
(t2) => throw 'Hover contents were MarkupContent, not String',
(t1) => throw 'Hover contents were MarkupContent, not String',
(t2) => t2,
);
}
}
@@ -320,12 +320,12 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
// request text document open/close and incremental updates.
expect(initResult.capabilities.textDocumentSync, isNotNull);
initResult.capabilities.textDocumentSync!.map(
(_) =>
throw 'Expected textDocumentSync capabilities to be a TextDocumentSyncOptions',
(options) {
expect(options.openClose, isTrue);
expect(options.change, equals(TextDocumentSyncKind.Incremental));
},
(_) =>
throw 'Expected textDocumentSync capabilities to be a $TextDocumentSyncOptions',
);
expect(initResult.capabilities.completionProvider, isNotNull);
expect(initResult.capabilities.hoverProvider, isNotNull);
@@ -696,13 +696,13 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
// Check some basic capabilities that are unlikely to change.
expect(result.capabilities.textDocumentSync, isNotNull);
result.capabilities.textDocumentSync!.map(
(_) =>
throw 'Expected textDocumentSync capabilities to be a TextDocumentSyncOptions',
(options) {
// We'll always request open/closed notifications and incremental updates.
expect(options.openClose, isTrue);
expect(options.change, equals(TextDocumentSyncKind.Incremental));
},
(_) =>
throw 'Expected textDocumentSync capabilities to be a $TextDocumentSyncOptions',
);
}
@@ -684,8 +684,8 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
void applyDocumentChanges(
Map<String, String> fileContents,
Either2<List<TextDocumentEdit>,
List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>
Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>,
List<TextDocumentEdit>>
documentChanges, {
Map<String, int>? expectedVersions,
}) {
@@ -695,21 +695,21 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
expectDocumentVersions(documentChanges, expectedVersions);
}
documentChanges.map(
(edits) => applyTextDocumentEdits(fileContents, edits),
(changes) => applyResourceChanges(fileContents, changes),
(edits) => applyTextDocumentEdits(fileContents, edits),
);
}
void applyResourceChanges(
Map<String, String> oldFileContent,
List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>> changes,
List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>> changes,
) {
for (final change in changes) {
change.map(
(textDocEdit) => applyTextDocumentEdits(oldFileContent, [textDocEdit]),
(create) => applyResourceCreate(oldFileContent, create),
(rename) => applyResourceRename(oldFileContent, rename),
(delete) => throw 'applyResourceChanges:Delete not currently supported',
(rename) => applyResourceRename(oldFileContent, rename),
(textDocEdit) => applyTextDocumentEdits(oldFileContent, [textDocEdit]),
);
}
}
@@ -751,7 +751,7 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
}
String applyTextEdit(String content,
Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit> change) {
Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit> change) {
// Both sites of the union can cast to TextEdit.
final edit = change.map((e) => e, (e) => e, (e) => e);
final startPos = edit.range.start;
@@ -815,7 +815,7 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
for (final change in sortedChanges) {
newContent = applyTextEdit(newContent,
Either3<SnippetTextEdit, AnnotatedTextEdit, TextEdit>.t3(change));
Either3<AnnotatedTextEdit, SnippetTextEdit, TextEdit>.t3(change));
}
return newContent;
@@ -904,30 +904,30 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
/// Validates the document versions for a set of edits match the versions in
/// the supplied map.
void expectDocumentVersions(
Either2<List<TextDocumentEdit>,
List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>
Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>,
List<TextDocumentEdit>>
documentChanges,
Map<String, int> expectedVersions,
) {
documentChanges.map(
// Validate versions on simple doc edits
(edits) {
for (var edit in edits) {
expectDocumentVersion(edit, expectedVersions);
}
},
// For resource changes, we only need to validate changes since
// creates/renames/deletes do not supply versions.
(changes) {
for (var change in changes) {
change.map(
(edit) => expectDocumentVersion(edit, expectedVersions),
(create) => {},
(rename) {},
(delete) {},
(rename) {},
(edit) => expectDocumentVersion(edit, expectedVersions),
);
}
},
// Validate versions on simple doc edits
(edits) {
for (var edit in edits) {
expectDocumentVersion(edit, expectedVersions);
}
},
);
}
@@ -1783,22 +1783,22 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
}
/// Creates a [TextEdit] using the `insert` range of a [InsertReplaceEdit].
TextEdit textEditForInsert(Either2<TextEdit, InsertReplaceEdit> edit) =>
TextEdit textEditForInsert(Either2<InsertReplaceEdit, TextEdit> edit) =>
edit.map(
(_) => throw 'Expected InsertReplaceEdit, got TextEdit',
(e) => TextEdit(range: e.insert, newText: e.newText),
(_) => throw 'Expected InsertReplaceEdit, got TextEdit',
);
/// Creates a [TextEdit] using the `replace` range of a [InsertReplaceEdit].
TextEdit textEditForReplace(Either2<TextEdit, InsertReplaceEdit> edit) =>
TextEdit textEditForReplace(Either2<InsertReplaceEdit, TextEdit> edit) =>
edit.map(
(_) => throw 'Expected InsertReplaceEdit, got TextEdit',
(e) => TextEdit(range: e.replace, newText: e.newText),
(_) => throw 'Expected InsertReplaceEdit, got TextEdit',
);
TextEdit toTextEdit(Either2<TextEdit, InsertReplaceEdit> edit) => edit.map(
(e) => e,
TextEdit toTextEdit(Either2<InsertReplaceEdit, TextEdit> edit) => edit.map(
(_) => throw 'Expected TextEdit, got InsertReplaceEdit',
(e) => e,
);
WorkspaceFolder toWorkspaceFolder(Uri uri) {
@@ -19,7 +19,7 @@ void main() {
test('handles union types', () {
expect(_union(['string', 'int']).dartTypeWithTypeArgs,
equals('Either2<String, int>'));
equals('Either2<int, String>'));
});
test('handles arrays', () {
@@ -72,11 +72,11 @@ void main() {
test('with union fields can be checked for equality', () {
final a = SignatureInformation(
label: 'a',
documentation: Either2<String, MarkupContent>.t1('a'),
documentation: Either2<MarkupContent, String>.t2('a'),
parameters: []);
final b = SignatureInformation(
label: 'a',
documentation: Either2<String, MarkupContent>.t1('a'),
documentation: Either2<MarkupContent, String>.t2('a'),
parameters: []);
expect(a, equals(b));
@@ -298,7 +298,7 @@ void main() {
expect(
reporter.errors.first,
equals(
'params.documentChanges must be of type Either2<List<TextDocumentEdit>, List<Either4<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>>'));
'params.documentChanges must be of type Either2<List<Either4<CreateFile, DeleteFile, RenameFile, TextDocumentEdit>>, List<TextDocumentEdit>>'));
});
test('ResponseMessage can include a null result', () {
@@ -356,8 +356,8 @@ interface SomeInformation {
expect(field.type, const TypeMatcher<UnionType>());
final union = field.type as UnionType;
expect(union.types, hasLength(2));
expect(union.types[0], isSimpleType('string'));
expect(union.types[1], isArrayOf(isSimpleType('number')));
expect(union.types[0], isArrayOf(isSimpleType('number')));
expect(union.types[1], isSimpleType('string'));
});
test('parses an union including Object into a single type', () {
@@ -5,6 +5,7 @@
import 'dart:math';
import 'package:analysis_server/src/utilities/strings.dart' show capitalize;
import 'package:collection/collection.dart';
import 'codegen_dart.dart';
import 'typescript.dart';
@@ -1011,7 +1012,11 @@ abstract class TypeBase {
class UnionType extends TypeBase {
final List<TypeBase> types;
UnionType(this.types);
UnionType(this.types) {
// Ensure types are always sorted alphabetically to simplify sharing code
// because `Either2<A, B>` and `Either2<B, A>` are not the same.
types.sortBy((type) => type.dartTypeWithTypeArgs.toLowerCase());
}
@override
String get dartType {