diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart index 0eb4484bf51..cda14b219f6 100644 --- a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart @@ -6788,12 +6788,12 @@ class CompletionItem implements ToJsonable { final documentationJson = json['documentation']; final documentation = documentationJson == null ? null - : (documentationJson is String - ? Either2.t1(documentationJson) - : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) - ? Either2.t2(MarkupContent.fromJson( - documentationJson as Map)) - : (throw '''$documentationJson was not one of (String, MarkupContent)'''))); + : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) + ? Either2.t1(MarkupContent.fromJson( + documentationJson as Map)) + : (documentationJson is String + ? Either2.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.t1( - TextEdit.fromJson(textEditJson as Map)) - : (InsertReplaceEdit.canParse(textEditJson, nullLspJsonReporter) - ? Either2.t2( - InsertReplaceEdit.fromJson( - textEditJson as Map)) - : (throw '''$textEditJson was not one of (TextEdit, InsertReplaceEdit)'''))); + : (InsertReplaceEdit.canParse(textEditJson, nullLspJsonReporter) + ? Either2.t1( + InsertReplaceEdit.fromJson( + textEditJson as Map)) + : (TextEdit.canParse(textEditJson, nullLspJsonReporter) + ? Either2.t2( + TextEdit.fromJson(textEditJson as Map)) + : (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? documentation; + final Either2? 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; + final Either2? 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'); + .reportError('must be of type Either2'); 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'); + 'must be of type Either2'); 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.t1( - Range.fromJson(editRangeJson as Map)) - : (CompletionListEditRange.canParse( - editRangeJson, nullLspJsonReporter) - ? Either2.t2( - CompletionListEditRange.fromJson( - editRangeJson as Map)) - : (throw '''$editRangeJson was not one of (Range, CompletionListEditRange)'''))); + : (CompletionListEditRange.canParse(editRangeJson, nullLspJsonReporter) + ? Either2.t1( + CompletionListEditRange.fromJson( + editRangeJson as Map)) + : (Range.canParse(editRangeJson, nullLspJsonReporter) + ? Either2.t2( + Range.fromJson(editRangeJson as Map)) + : (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? editRange; + final Either2? 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'); + 'must be of type Either2'); return false; } } finally { @@ -19269,12 +19268,12 @@ class Hover implements ToJsonable { }); static Hover fromJson(Map json) { final contentsJson = json['contents']; - final contents = contentsJson is String - ? Either2.t1(contentsJson) - : (MarkupContent.canParse(contentsJson, nullLspJsonReporter) - ? Either2.t2( - MarkupContent.fromJson(contentsJson as Map)) - : (throw '''$contentsJson was not one of (String, MarkupContent)''')); + final contents = MarkupContent.canParse(contentsJson, nullLspJsonReporter) + ? Either2.t1( + MarkupContent.fromJson(contentsJson as Map)) + : (contentsJson is String + ? Either2.t2(contentsJson) + : (throw '''$contentsJson was not one of (MarkupContent, String)''')); final rangeJson = json['range']; final range = rangeJson != null ? Range.fromJson(rangeJson as Map) @@ -19286,7 +19285,7 @@ class Hover implements ToJsonable { } /// The hover's content - final Either2 contents; + final Either2 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'); + .reportError('must be of type Either2'); return false; } } finally { @@ -21019,16 +21018,16 @@ class InlayHint implements ToJsonable { final positionJson = json['position']; final position = Position.fromJson(positionJson as Map); final labelJson = json['label']; - final label = labelJson is String - ? Either2>.t1(labelJson) - : ((labelJson is List && - (labelJson.every((item) => - InlayHintLabelPart.canParse(item, nullLspJsonReporter)))) - ? Either2>.t2((labelJson) - .map((item) => - InlayHintLabelPart.fromJson(item as Map)) - .toList()) - : (throw '''$labelJson was not one of (String, List)''')); + final label = (labelJson is List && + (labelJson.every((item) => + InlayHintLabelPart.canParse(item, nullLspJsonReporter)))) + ? Either2, String>.t1((labelJson) + .map((item) => + InlayHintLabelPart.fromJson(item as Map)) + .toList()) + : (labelJson is String + ? Either2, String>.t2(labelJson) + : (throw '''$labelJson was not one of (List, 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.t1(tooltipJson) - : (MarkupContent.canParse(tooltipJson, nullLspJsonReporter) - ? Either2.t2( - MarkupContent.fromJson(tooltipJson as Map)) - : (throw '''$tooltipJson was not one of (String, MarkupContent)'''))); + : (MarkupContent.canParse(tooltipJson, nullLspJsonReporter) + ? Either2.t1( + MarkupContent.fromJson(tooltipJson as Map)) + : (tooltipJson is String + ? Either2.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> label; + final Either2, 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? tooltip; + final Either2? tooltip; Map toJson() { var __result = {}; @@ -21166,12 +21165,12 @@ class InlayHint implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((label is String || - (label is List && - (label.every((item) => - InlayHintLabelPart.canParse(item, reporter))))))) { + if (!(((label is List && + (label.every( + (item) => InlayHintLabelPart.canParse(item, reporter)))) || + label is String))) { reporter.reportError( - 'must be of type Either2>'); + 'must be of type Either2, 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'); + .reportError('must be of type Either2'); return false; } } finally { @@ -21495,12 +21494,12 @@ class InlayHintLabelPart implements ToJsonable { final tooltipJson = json['tooltip']; final tooltip = tooltipJson == null ? null - : (tooltipJson is String - ? Either2.t1(tooltipJson) - : (MarkupContent.canParse(tooltipJson, nullLspJsonReporter) - ? Either2.t2( - MarkupContent.fromJson(tooltipJson as Map)) - : (throw '''$tooltipJson was not one of (String, MarkupContent)'''))); + : (MarkupContent.canParse(tooltipJson, nullLspJsonReporter) + ? Either2.t1( + MarkupContent.fromJson(tooltipJson as Map)) + : (tooltipJson is String + ? Either2.t2(tooltipJson) + : (throw '''$tooltipJson was not one of (MarkupContent, String)'''))); final locationJson = json['location']; final location = locationJson != null ? Location.fromJson(locationJson as Map) @@ -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? tooltip; + final Either2? 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'); + .reportError('must be of type Either2'); return false; } } finally { @@ -25808,24 +25807,21 @@ class NotebookCellTextDocumentFilter implements ToJsonable { }); static NotebookCellTextDocumentFilter fromJson(Map json) { final notebookJson = json['notebook']; - final notebook = notebookJson is String - ? Either2>.t1( - notebookJson) - : ((NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) || - NotebookDocumentFilter2.canParse( - notebookJson, nullLspJsonReporter) || - NotebookDocumentFilter3.canParse( - notebookJson, nullLspJsonReporter)) - ? Either2>.t2( - NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) - ? Either3.t1( - NotebookDocumentFilter1.fromJson( - notebookJson as Map)) - : (NotebookDocumentFilter2.canParse(notebookJson, nullLspJsonReporter) - ? Either3.t2( - NotebookDocumentFilter2.fromJson(notebookJson as Map)) - : (NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter) ? Either3.t3(NotebookDocumentFilter3.fromJson(notebookJson as Map)) : (throw '''$notebookJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)''')))) - : (throw '''$notebookJson was not one of (String, Either3)''')); + final notebook = (NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) || + NotebookDocumentFilter2.canParse( + notebookJson, nullLspJsonReporter) || + NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter)) + ? Either2, String>.t1( + NotebookDocumentFilter1.canParse(notebookJson, nullLspJsonReporter) + ? Either3.t1(NotebookDocumentFilter1.fromJson( + notebookJson as Map)) + : (NotebookDocumentFilter2.canParse(notebookJson, nullLspJsonReporter) + ? Either3.t2(NotebookDocumentFilter2.fromJson( + notebookJson as Map)) + : (NotebookDocumentFilter3.canParse(notebookJson, nullLspJsonReporter) + ? Either3.t3(NotebookDocumentFilter3.fromJson(notebookJson as Map)) + : (throw '''$notebookJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)''')))) + : (notebookJson is String ? Either2, String>.t2(notebookJson) : (throw '''$notebookJson was not one of (Either3, 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> notebook; + NotebookDocumentFilter3>, + String> notebook; Map toJson() { var __result = {}; @@ -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>'); + 'must be of type Either2, 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>.t1( - notebookDocumentJson) - : ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) || - NotebookDocumentFilter2.canParse( - notebookDocumentJson, nullLspJsonReporter) || - NotebookDocumentFilter3.canParse( - notebookDocumentJson, nullLspJsonReporter)) - ? Either2>.t2( - NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) - ? Either3.t1( - NotebookDocumentFilter1.fromJson( - notebookDocumentJson as Map)) - : (NotebookDocumentFilter2.canParse( - notebookDocumentJson, nullLspJsonReporter) - ? Either3.t2(NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map)) - : (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)''')))) - : (throw '''$notebookDocumentJson was not one of (String, Either3)'''))); + : ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) || + NotebookDocumentFilter2.canParse( + notebookDocumentJson, nullLspJsonReporter) || + NotebookDocumentFilter3.canParse( + notebookDocumentJson, nullLspJsonReporter)) + ? Either2, String>.t1( + NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) + ? Either3.t1( + NotebookDocumentFilter1.fromJson( + notebookDocumentJson as Map)) + : (NotebookDocumentFilter2.canParse(notebookDocumentJson, nullLspJsonReporter) + ? Either3.t2( + NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map)) + : (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)''')))) + : (notebookDocumentJson is String ? Either2, String>.t2(notebookDocumentJson) : (throw '''$notebookDocumentJson was not one of (Either3, String)'''))); final cellsJson = json['cells']; final cells = (cellsJson as List) .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>? notebookDocument; + NotebookDocumentFilter3>, + String>? notebookDocument; Map toJson() { var __result = {}; @@ -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>'); + 'must be of type Either2, 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.t1(documentationJson) - : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) - ? Either2.t2(MarkupContent.fromJson( - documentationJson as Map)) - : (throw '''$documentationJson was not one of (String, MarkupContent)'''))); + : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) + ? Either2.t1(MarkupContent.fromJson( + documentationJson as Map)) + : (documentationJson is String + ? Either2.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? documentation; + final Either2? 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'); + .reportError('must be of type Either2'); return false; } } finally { @@ -30268,12 +30261,12 @@ class RelativePattern implements ToJsonable { }); static RelativePattern fromJson(Map json) { final baseUriJson = json['baseUri']; - final baseUri = WorkspaceFolder.canParse(baseUriJson, nullLspJsonReporter) - ? Either2.t1( - WorkspaceFolder.fromJson(baseUriJson as Map)) - : (baseUriJson is String - ? Either2.t2(baseUriJson) - : (throw '''$baseUriJson was not one of (WorkspaceFolder, String)''')); + final baseUri = baseUriJson is String + ? Either2.t1(baseUriJson) + : (WorkspaceFolder.canParse(baseUriJson, nullLspJsonReporter) + ? Either2.t2( + WorkspaceFolder.fromJson(baseUriJson as Map)) + : (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 baseUri; + final Either2 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'); + .reportError('must be of type Either2'); 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.t1( - TextDocumentSyncOptions.fromJson( - textDocumentSyncJson as Map)) - : (TextDocumentSyncKind.canParse( + ? Either2.t1( + TextDocumentSyncKind.fromJson(textDocumentSyncJson as int)) + : (TextDocumentSyncOptions.canParse( textDocumentSyncJson, nullLspJsonReporter) - ? Either2.t2( - TextDocumentSyncKind.fromJson(textDocumentSyncJson as int)) - : (throw '''$textDocumentSyncJson was not one of (TextDocumentSyncOptions, TextDocumentSyncKind)'''))); + ? Either2.t2( + TextDocumentSyncOptions.fromJson( + textDocumentSyncJson as Map)) + : (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? + final Either2? 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'); + 'must be of type Either2'); return false; } } finally { @@ -37953,12 +37947,12 @@ class SignatureInformation implements ToJsonable { final documentationJson = json['documentation']; final documentation = documentationJson == null ? null - : (documentationJson is String - ? Either2.t1(documentationJson) - : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) - ? Either2.t2(MarkupContent.fromJson( - documentationJson as Map)) - : (throw '''$documentationJson was not one of (String, MarkupContent)'''))); + : (MarkupContent.canParse(documentationJson, nullLspJsonReporter) + ? Either2.t1(MarkupContent.fromJson( + documentationJson as Map)) + : (documentationJson is String + ? Either2.t2(documentationJson) + : (throw '''$documentationJson was not one of (MarkupContent, String)'''))); final parametersJson = json['parameters']; final parameters = (parametersJson as List?) ?.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? documentation; + final Either2? 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'); + .reportError('must be of type Either2'); return false; } } finally { @@ -39683,16 +39677,16 @@ class TextDocumentEdit implements ToJsonable { textDocumentJson as Map); final editsJson = json['edits']; final edits = (editsJson as List) - .map((item) => SnippetTextEdit.canParse(item, nullLspJsonReporter) - ? Either3.t1( - SnippetTextEdit.fromJson(item as Map)) - : (AnnotatedTextEdit.canParse(item, nullLspJsonReporter) - ? Either3.t2( - AnnotatedTextEdit.fromJson(item as Map)) + .map((item) => AnnotatedTextEdit.canParse(item, nullLspJsonReporter) + ? Either3.t1( + AnnotatedTextEdit.fromJson(item as Map)) + : (SnippetTextEdit.canParse(item, nullLspJsonReporter) + ? Either3.t2( + SnippetTextEdit.fromJson(item as Map)) : (TextEdit.canParse(item, nullLspJsonReporter) - ? Either3.t3( + ? Either3.t3( TextEdit.fromJson(item as Map)) - : (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> edits; + final List> edits; /// The text document to change. final OptionalVersionedTextDocumentIdentifier textDocument; @@ -39749,11 +39743,12 @@ class TextDocumentEdit implements ToJsonable { return false; } if (!((edits is List && - (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>'); + 'must be of type List>'); return false; } } finally { @@ -39773,8 +39768,8 @@ class TextDocumentEdit implements ToJsonable { listEqual( edits, other.edits, - (Either3 a, - Either3 + (Either3 a, + Either3 b) => a == b) && true; @@ -44246,20 +44241,22 @@ class WorkspaceEdit implements ToJsonable { ? null : ((documentChangesJson is List && (documentChangesJson.every((item) => - TextDocumentEdit.canParse(item, nullLspJsonReporter)))) - ? Either2, List>>.t1((documentChangesJson) - .map((item) => - TextDocumentEdit.fromJson(item as Map)) + (CreateFile.canParse(item, nullLspJsonReporter) || + DeleteFile.canParse(item, nullLspJsonReporter) || + RenameFile.canParse(item, nullLspJsonReporter) || + TextDocumentEdit.canParse(item, nullLspJsonReporter))))) + ? Either2>, List>.t1((documentChangesJson) + .map((item) => CreateFile.canParse(item, nullLspJsonReporter) + ? Either4.t1( + CreateFile.fromJson(item as Map)) + : (DeleteFile.canParse(item, nullLspJsonReporter) + ? Either4.t2( + DeleteFile.fromJson(item as Map)) + : (RenameFile.canParse(item, nullLspJsonReporter) + ? Either4.t3(RenameFile.fromJson(item as Map)) + : (TextDocumentEdit.canParse(item, nullLspJsonReporter) ? Either4.t4(TextDocumentEdit.fromJson(item as Map)) : (throw '''$item was not one of (CreateFile, DeleteFile, RenameFile, TextDocumentEdit)'''))))) .toList()) - : ((documentChangesJson is List && - (documentChangesJson.every((item) => - (TextDocumentEdit.canParse(item, nullLspJsonReporter) || - CreateFile.canParse(item, nullLspJsonReporter) || - RenameFile.canParse(item, nullLspJsonReporter) || - DeleteFile.canParse(item, nullLspJsonReporter))))) - ? Either2, List>>.t2( - (documentChangesJson).map((item) => TextDocumentEdit.canParse(item, nullLspJsonReporter) ? Either4.t1(TextDocumentEdit.fromJson(item as Map)) : (CreateFile.canParse(item, nullLspJsonReporter) ? Either4.t2(CreateFile.fromJson(item as Map)) : (RenameFile.canParse(item, nullLspJsonReporter) ? Either4.t3(RenameFile.fromJson(item as Map)) : (DeleteFile.canParse(item, nullLspJsonReporter) ? Either4.t4(DeleteFile.fromJson(item as Map)) : (throw '''$item was not one of (TextDocumentEdit, CreateFile, RenameFile, DeleteFile)'''))))).toList()) - : (throw '''$documentChangesJson was not one of (List, List>)'''))); + : ((documentChangesJson is List && (documentChangesJson.every((item) => TextDocumentEdit.canParse(item, nullLspJsonReporter)))) ? Either2>, List>.t2((documentChangesJson).map((item) => TextDocumentEdit.fromJson(item as Map)).toList()) : (throw '''$documentChangesJson was not one of (List>, List)'''))); final changeAnnotationsJson = json['changeAnnotations']; final changeAnnotations = (changeAnnotationsJson as Map?) ?.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>>? - documentChanges; + final Either2< + List>, + List>? documentChanges; Map toJson() { var __result = {}; @@ -44337,15 +44334,15 @@ class WorkspaceEdit implements ToJsonable { if (documentChanges != null && !(((documentChanges is List && (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 && (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>>'); + 'must be of type Either2>, List>'); return false; } } finally { @@ -44875,11 +44872,11 @@ class WorkspaceFoldersServerCapabilities implements ToJsonable { final changeNotificationsJson = json['changeNotifications']; final changeNotifications = changeNotificationsJson == null ? null - : (changeNotificationsJson is String - ? Either2.t1(changeNotificationsJson) - : (changeNotificationsJson is bool - ? Either2.t2(changeNotificationsJson) - : (throw '''$changeNotificationsJson was not one of (String, bool)'''))); + : (changeNotificationsJson is bool + ? Either2.t1(changeNotificationsJson) + : (changeNotificationsJson is String + ? Either2.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? changeNotifications; + final Either2? 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'); + !((changeNotifications is bool || changeNotifications is String))) { + reporter.reportError('must be of type Either2'); return false; } } finally { diff --git a/pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart b/pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart index d38ba96177d..e6831bc86ae 100644 --- a/pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart +++ b/pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart @@ -98,7 +98,7 @@ class DartTypeArgumentsSignatureComputer { lsp.SignatureInformation( label: label, documentation: documentation != null - ? asStringOrMarkupContent(preferredFormats, documentation) + ? asMarkupContentOrString(preferredFormats, documentation) : null, parameters: parameters, ), diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_completion_resolve.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_completion_resolve.dart index f7c418cd1bc..195fe662cc4 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_completion_resolve.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_completion_resolve.dart @@ -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.t2( + ? Either2.t1( InsertReplaceEdit( insert: insertionRange, replace: replacementRange, newText: newInsertText, ), ) - : Either2.t1( + : Either2.t2( TextEdit( range: replacementRange, newText: newInsertText, @@ -253,7 +253,7 @@ class CompletionResolveHandler tags: item.tags, detail: item.detail, documentation: description != null - ? Either2.t1(description) + ? Either2.t2(description) : null, deprecated: item.deprecated, preselect: item.preselect, diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_hover.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_hover.dart index f7a512218d6..30ca65fc63e 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_hover.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_hover.dart @@ -84,7 +84,7 @@ class HoverHandler extends MessageHandler { 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), ); } diff --git a/pkg/analysis_server/lib/src/lsp/mapping.dart b/pkg/analysis_server/lib/src/lsp/mapping.dart index 31183f40e89..ff0fc5e5be2 100644 --- a/pkg/analysis_server/lib/src/lsp/mapping.dart +++ b/pkg/analysis_server/lib/src/lsp/mapping.dart @@ -57,12 +57,12 @@ final diagnosticTagsForErrorCode = >{ /// field. final _upgradableDocCompletePattern = RegExp(r'^_([\w ]{0,20})_$'); -lsp.Either2 asStringOrMarkupContent( +lsp.Either2 asMarkupContentOrString( Set? preferredFormats, String content) { - return preferredFormats == null - ? lsp.Either2.t1(content) - : lsp.Either2.t2( - _asMarkup(preferredFormats, content)); + return preferredFormats != null + ? lsp.Either2.t1( + _asMarkup(preferredFormats, content)) + : lsp.Either2.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 = - >[]; + >[]; final rename = RenameFile( oldUri: Uri.file(oldPath).toString(), @@ -101,16 +101,14 @@ WorkspaceEdit createRenameEdit(String oldPath, String newPath) { ); final renameUnion = - Either4.t3(rename); + Either4.t3(rename); changes.add(renameUnion); final edit = WorkspaceEdit( documentChanges: Either2< - List, - List< - Either4>>.t2(changes)); + List>, + List>.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.t1(e)) + .map((e) => Either3.t2(e)) .toList(), ); // Convert to the union that documentChanges require. - final textDocumentEditsAsUnion = Either4.t1(textDocumentEdit); + final textDocumentEditsAsUnion = Either4.t4(textDocumentEdit); // Convert to the union that documentChanges is. final documentChanges = Either2< - List, List< - Either4>>.t2([textDocumentEditsAsUnion]); + Either4>, + List>.t1([textDocumentEditsAsUnion]); /// Add the textDocumentEdit to a WorkspaceEdit. return lsp.WorkspaceEdit(documentChanges: documentChanges); @@ -695,24 +693,22 @@ WorkspaceEdit mergeWorkspaceEdits(List edits) { // TODO(dantup): This method (and much other code here) should be // significantly tidied up when nonfunction-type-aliases is available here. final changes = - >[]; + >[]; 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.t1(e)), (resources) => resources, + (edits) => edits.map((e) => + Either4.t4(e)), ); changes.addAll(flatResourceChanges); } return WorkspaceEdit( documentChanges: Either2< - List, - List< - Either4>>.t2(changes)); + List>, + List>.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.t1(mainEdit), + textEdit: Either2.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.t2( + ? Either2.t1( InsertReplaceEdit( insert: insertionRange, replace: replacementRange, newText: insertText, ), ) - : Either2.t1( + : Either2.t2( TextEdit( range: replacementRange, newText: insertText, @@ -1476,7 +1472,7 @@ lsp.SignatureHelp toSignatureHelp(Set? 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 +Either3 toTextDocumentEditEdit( LspClientCapabilities capabilities, server.LineInfo lineInfo, @@ -1572,10 +1568,10 @@ Either3 }) { if (!capabilities.experimentalSnippetTextEdit || selectionOffsetRelative == null) { - return Either3.t3( + return Either3.t3( toTextEdit(lineInfo, edit)); } - return Either3.t1( + return Either3.t2( snippetTextEditWithSelection(lineInfo, edit, selectionOffsetRelative: selectionOffsetRelative, selectionLength: selectionLength)); @@ -1596,8 +1592,8 @@ lsp.WorkspaceEdit toWorkspaceEdit( if (supportsDocumentChanges) { final supportsCreate = capabilities.createResourceOperations; final changes = < - Either4>[]; + Either4>[]; // 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.t2(create); + final createUnion = Either4.t1(create); changes.add(createUnion); } final textDocEdit = toTextDocumentEdit(capabilities, edit); - final textDocEditUnion = Either4.t1(textDocEdit); + final textDocEditUnion = Either4.t4(textDocEdit); changes.add(textDocEditUnion); } return lsp.WorkspaceEdit( documentChanges: Either2< - List, List< - Either4>>.t2(changes)); + Either4>, + List>.t1(changes)); } else { return lsp.WorkspaceEdit(changes: toWorkspaceEditChanges(edits)); } diff --git a/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart b/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart index d7123e51f5a..40c8cde6084 100644 --- a/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart +++ b/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart @@ -167,7 +167,7 @@ class ServerCapabilitiesComputer { return ServerCapabilities( textDocumentSync: dynamicRegistrations.textSync ? null - : Either2.t1( + : Either2.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.t2(true), + changeNotifications: Either2.t1(true), ), fileOperations: dynamicRegistrations.fileOperations ? null diff --git a/pkg/analysis_server/test/lsp/code_actions_assists_test.dart b/pkg/analysis_server/test/lsp/code_actions_assists_test.dart index 6ddcd8043db..019bcd37a73 100644 --- a/pkg/analysis_server/test/lsp/code_actions_assists_test.dart +++ b/pkg/analysis_server/test/lsp/code_actions_assists_test.dart @@ -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 _extractTextDocumentEdits( Either2< - List, List< - Either4>> + Either4>, + List> 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, ); } diff --git a/pkg/analysis_server/test/lsp/hover_test.dart b/pkg/analysis_server/test/lsp/hover_test.dart index 68e216e610a..a20f335efed 100644 --- a/pkg/analysis_server/test/lsp/hover_test.dart +++ b/pkg/analysis_server/test/lsp/hover_test.dart @@ -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, ); } } diff --git a/pkg/analysis_server/test/lsp/initialization_test.dart b/pkg/analysis_server/test/lsp/initialization_test.dart index d0c316fd4bf..aeb98605d23 100644 --- a/pkg/analysis_server/test/lsp/initialization_test.dart +++ b/pkg/analysis_server/test/lsp/initialization_test.dart @@ -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', ); } diff --git a/pkg/analysis_server/test/lsp/server_abstract.dart b/pkg/analysis_server/test/lsp/server_abstract.dart index 1a70f928a0f..43aa799948c 100644 --- a/pkg/analysis_server/test/lsp/server_abstract.dart +++ b/pkg/analysis_server/test/lsp/server_abstract.dart @@ -684,8 +684,8 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin { void applyDocumentChanges( Map fileContents, - Either2, - List>> + Either2>, + List> documentChanges, { Map? 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 oldFileContent, - List> changes, + List> 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 change) { + Either3 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.t3(change)); + Either3.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>> + Either2>, + List> documentChanges, Map 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 edit) => + TextEdit textEditForInsert(Either2 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 edit) => + TextEdit textEditForReplace(Either2 edit) => edit.map( - (_) => throw 'Expected InsertReplaceEdit, got TextEdit', (e) => TextEdit(range: e.replace, newText: e.newText), + (_) => throw 'Expected InsertReplaceEdit, got TextEdit', ); - TextEdit toTextEdit(Either2 edit) => edit.map( - (e) => e, + TextEdit toTextEdit(Either2 edit) => edit.map( (_) => throw 'Expected TextEdit, got InsertReplaceEdit', + (e) => e, ); WorkspaceFolder toWorkspaceFolder(Uri uri) { diff --git a/pkg/analysis_server/test/tool/lsp_spec/dart_test.dart b/pkg/analysis_server/test/tool/lsp_spec/dart_test.dart index 4e7b051adbc..0093cffa6b9 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/dart_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/dart_test.dart @@ -19,7 +19,7 @@ void main() { test('handles union types', () { expect(_union(['string', 'int']).dartTypeWithTypeArgs, - equals('Either2')); + equals('Either2')); }); test('handles arrays', () { diff --git a/pkg/analysis_server/test/tool/lsp_spec/generated_classes_test.dart b/pkg/analysis_server/test/tool/lsp_spec/generated_classes_test.dart index bba959ab0a2..831dc790814 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/generated_classes_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/generated_classes_test.dart @@ -72,11 +72,11 @@ void main() { test('with union fields can be checked for equality', () { final a = SignatureInformation( label: 'a', - documentation: Either2.t1('a'), + documentation: Either2.t2('a'), parameters: []); final b = SignatureInformation( label: 'a', - documentation: Either2.t1('a'), + documentation: Either2.t2('a'), parameters: []); expect(a, equals(b)); diff --git a/pkg/analysis_server/test/tool/lsp_spec/json_test.dart b/pkg/analysis_server/test/tool/lsp_spec/json_test.dart index c90a2a007ab..5f3951c32e6 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/json_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/json_test.dart @@ -298,7 +298,7 @@ void main() { expect( reporter.errors.first, equals( - 'params.documentChanges must be of type Either2, List>>')); + 'params.documentChanges must be of type Either2>, List>')); }); test('ResponseMessage can include a null result', () { diff --git a/pkg/analysis_server/test/tool/lsp_spec/typescript_test.dart b/pkg/analysis_server/test/tool/lsp_spec/typescript_test.dart index 990d95263eb..ebc92f992b7 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/typescript_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/typescript_test.dart @@ -356,8 +356,8 @@ interface SomeInformation { expect(field.type, const TypeMatcher()); 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', () { diff --git a/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart b/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart index 57c9bb36aac..e4415a8ef52 100644 --- a/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart +++ b/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart @@ -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 types; - UnionType(this.types); + UnionType(this.types) { + // Ensure types are always sorted alphabetically to simplify sharing code + // because `Either2` and `Either2` are not the same. + types.sortBy((type) => type.dartTypeWithTypeArgs.toLowerCase()); + } @override String get dartType {