From 2bd91e8e583b58514b6a2735953c97a3fefe008a Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Thu, 10 Oct 2024 15:08:41 +0000 Subject: [PATCH 1/7] [analysis_server] Rename some LSP types to match upcoming LSP 3.18 In the upcoming LSP 3.18 spec, many types that were previously inline literal types with no names (that resulted in us auto-generating names) have been made real types with names. In order to reduce the size of the change when LSP 3.18 arrives, this change renames some of our existing types to match the new names that they will get with LSP 3.18. There are no functional changes here, I simple added the names to the rename list (removing any redundant values that were previously being renamed differently), regenerated the code, and then updated any remaining references (in non-generated code) to those types to match. Change-Id: Ic556ce6e52ba94a8d42099371be18288230cd5ef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389160 Reviewed-by: Samuel Rawlins Reviewed-by: Brian Wilkerson Commit-Queue: Samuel Rawlins --- .../lib/src/lsp/constants.dart | 12 +- .../src/lsp/handlers/handler_completion.dart | 23 +- .../src/lsp/handlers/handler_initialize.dart | 2 +- .../lib/src/lsp/handlers/handler_rename.dart | 3 +- .../lsp/handlers/handler_semantic_tokens.dart | 6 +- .../handler_text_document_changes.dart | 2 +- .../lib/src/lsp/lsp_analysis_server.dart | 6 +- pkg/analysis_server/lib/src/lsp/mapping.dart | 2 +- .../registration/feature_registration.dart | 10 +- .../src/lsp/server_capabilities_computer.dart | 10 +- .../test/lsp/completion_dart_test.dart | 2 +- .../test/lsp/document_changes_test.dart | 8 +- .../test/lsp/file_modification_test.dart | 6 +- .../test/lsp/initialization_test.dart | 4 +- .../test/lsp/request_helpers_mixin.dart | 5 +- .../test/lsp/server_abstract.dart | 4 +- pkg/analysis_server/test/lsp/server_test.dart | 2 +- .../tool/lsp_spec/generated_classes_test.dart | 12 +- .../test/tool/lsp_spec/json_test.dart | 7 +- .../tool/lsp_spec/codegen_dart.dart | 6 +- .../tool/lsp_spec/generate_all.dart | 20 +- .../tool/lsp_spec/meta_model.dart | 17 +- .../tool/lsp_spec/meta_model_cleaner.dart | 70 +- .../tool/lsp_spec/meta_model_reader.dart | 4 +- .../lib/protocol_generated.dart | 2591 ++++++++--------- 25 files changed, 1442 insertions(+), 1392 deletions(-) diff --git a/pkg/analysis_server/lib/src/lsp/constants.dart b/pkg/analysis_server/lib/src/lsp/constants.dart index 399e8a4f0fc4..a4192cbf05dc 100644 --- a/pkg/analysis_server/lib/src/lsp/constants.dart +++ b/pkg/analysis_server/lib/src/lsp/constants.dart @@ -45,8 +45,8 @@ const dartSignatureHelpTriggerCharacters = ['(']; /// Characters to trigger formatting when format-on-type is enabled. const dartTypeFormattingCharacters = ['}', ';']; -/// A [TextDocumentFilterWithScheme] for Analysis Options files. -final analysisOptionsFile = TextDocumentFilterWithScheme( +/// A [TextDocumentFilterScheme] for Analysis Options files. +final analysisOptionsFile = TextDocumentFilterScheme( language: 'yaml', scheme: 'file', pattern: '**/analysis_options.yaml'); /// A [ProgressToken] used for reporting progress while the server is analyzing. @@ -73,14 +73,14 @@ final fileOperationRegistrationOptions = FileOperationRegistrationOptions( ], ); -/// A [TextDocumentFilterWithScheme] for Fix Data files. -final fixDataFile = TextDocumentFilterWithScheme( +/// A [TextDocumentFilterScheme] for Fix Data files. +final fixDataFile = TextDocumentFilterScheme( language: 'yaml', scheme: 'file', pattern: '**/lib/{fix_data.yaml,fix_data/**.yaml}'); -/// A [TextDocumentFilterWithScheme] for Pubspec files. -final pubspecFile = TextDocumentFilterWithScheme( +/// A [TextDocumentFilterScheme] for Pubspec files. +final pubspecFile = TextDocumentFilterScheme( language: 'yaml', scheme: 'file', pattern: '**/pubspec.yaml'); /// IDs of client-provided commands that the server knows about. diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart index 1afff6b213bd..3c66a9f82698 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart @@ -247,7 +247,7 @@ class CompletionHandler /// Computes all supported defaults for completion items based on /// [capabilities]. - CompletionListItemDefaults? _computeCompletionDefaults( + CompletionItemDefaults? _computeCompletionDefaults( LspClientCapabilities capabilities, Range insertionRange, Range replacementRange, @@ -258,7 +258,7 @@ class CompletionHandler return null; } - return CompletionListItemDefaults( + return CompletionItemDefaults( insertTextMode: capabilities.completionDefaultTextMode ? InsertTextMode.asIs : null, editRange: _computeDefaultEditRange( @@ -268,7 +268,7 @@ class CompletionHandler /// Computes the default completion edit range based on [capabilities] and /// whether the insert/replacement ranges differ. - Either2? _computeDefaultEditRange( + Either2? _computeDefaultEditRange( LspClientCapabilities capabilities, Range insertionRange, Range replacementRange, @@ -279,10 +279,10 @@ class CompletionHandler if (!capabilities.insertReplaceCompletionRanges || insertionRange == replacementRange) { - return Either2.t2(replacementRange); + return Either2.t2(replacementRange); } else { - return Either2.t1( - CompletionItemEditRange( + return Either2.t1( + EditRangeWithInsertReplace( insert: insertionRange, replace: replacementRange, ), @@ -306,7 +306,7 @@ class CompletionHandler required int offset, required LineInfo lineInfo, required bool Function(String input) filter, - CompletionListItemDefaults? defaults, + CompletionItemDefaults? defaults, }) async { var request = DartSnippetRequest( unit: unit, @@ -845,7 +845,7 @@ class CompletionRegistrations extends FeatureRegistration previewCommitCharacters ? dartCompletionCommitCharacters : null, resolveProvider: true, completionItem: - CompletionOptionsCompletionItem(labelDetailsSupport: true), + ServerCompletionItemOptions(labelDetailsSupport: true), ), ), ( @@ -862,7 +862,7 @@ class CompletionRegistrations extends FeatureRegistration /// /// We use two dynamic registrations because for Dart we support trigger /// characters but for other kinds of files we do not. - List get nonDartCompletionTypes { + List get nonDartCompletionTypes { var pluginTypesExcludingDart = pluginTypes.where((filter) => filter.pattern != '**/*.dart'); @@ -883,8 +883,7 @@ class CompletionRegistrations extends FeatureRegistration allCommitCharacters: previewCommitCharacters ? dartCompletionCommitCharacters : null, resolveProvider: true, - completionItem: - CompletionOptionsCompletionItem(labelDetailsSupport: true), + completionItem: ServerCompletionItemOptions(labelDetailsSupport: true), ); @override @@ -908,7 +907,7 @@ class _CompletionResults { /// Item defaults for completion items. /// /// Defaults are only supported on Dart server items (not plugins). - final CompletionListItemDefaults? defaults; + final CompletionItemDefaults? defaults; _CompletionResults({ this.rankedItems = const [], diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart index 1fdd08d5e410..517a4e088e3a 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart @@ -74,7 +74,7 @@ class InitializeMessageHandler return success(InitializeResult( capabilities: capabilities, - serverInfo: InitializeResultServerInfo( + serverInfo: ServerInfo( name: 'Dart SDK LSP Analysis Server', version: sdkVersion, ), diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_rename.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_rename.dart index a46f7ec70ed0..c203c4ae6a86 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_rename.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_rename.dart @@ -82,7 +82,8 @@ class PrepareRenameHandler extends LspMessageHandler SemanticTokensRegistrationOptions( documentSelector: fullySupportedTypes, legend: semanticTokenLegend.lspLegend, - full: Either2.t2( - SemanticTokensOptionsFull(delta: false), + full: Either2.t2( + SemanticTokensFullDelta(delta: false), ), range: Either2.t1(true), ); @@ -173,7 +173,7 @@ class SemanticTokensRegistrations extends FeatureRegistration StaticOptions get staticOptions => Either2.t1( SemanticTokensOptions( legend: semanticTokenLegend.lspLegend, - full: Either2.t2(SemanticTokensOptionsFull(delta: false)), + full: Either2.t2(SemanticTokensFullDelta(delta: false)), range: Either2.t1(true), ), ); diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_text_document_changes.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_text_document_changes.dart index b31fd2affbdf..b9d2d3a0e6e3 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_text_document_changes.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_text_document_changes.dart @@ -169,7 +169,7 @@ class TextDocumentRegistrations extends FeatureRegistration @override bool get supportsDynamic => clientDynamic.textSync; - List get synchronisedTypes { + List get synchronisedTypes { return { ...fullySupportedTypes, pubspecFile, diff --git a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart index 52d392be4c8d..d15372d51eba 100644 --- a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart +++ b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart @@ -61,7 +61,7 @@ class LspAnalysisServer extends AnalysisServer { /// Information about the connected client. Will be null prior to /// initialization or if the client did not provide it. - InitializeParamsClientInfo? _clientInfo; + ClientInfo? _clientInfo; /// Initialization options provided by the LSP client. Allows opting in/out of /// specific server functionality. Will be null prior to initialization. @@ -213,7 +213,7 @@ class LspAnalysisServer extends AnalysisServer { /// Information about the connected editor client. Will be `null` prior to /// initialization. - InitializeParamsClientInfo? get clientInfo => _clientInfo; + ClientInfo? get clientInfo => _clientInfo; /// The name of the remote when the client is running using a remote workspace. /// @@ -407,7 +407,7 @@ class LspAnalysisServer extends AnalysisServer { void handleClientConnection( ClientCapabilities capabilities, - InitializeParamsClientInfo? clientInfo, + ClientInfo? clientInfo, Object? initializationOptions, ) { _clientCapabilities = LspClientCapabilities(capabilities); diff --git a/pkg/analysis_server/lib/src/lsp/mapping.dart b/pkg/analysis_server/lib/src/lsp/mapping.dart index 4432d1d265d7..2d5da40950e8 100644 --- a/pkg/analysis_server/lib/src/lsp/mapping.dart +++ b/pkg/analysis_server/lib/src/lsp/mapping.dart @@ -792,7 +792,7 @@ lsp.CompletionItem snippetToCompletionItem( LineInfo lineInfo, Position position, Snippet snippet, - CompletionListItemDefaults? defaults, + CompletionItemDefaults? defaults, ) { assert(capabilities.completionSnippets); diff --git a/pkg/analysis_server/lib/src/lsp/registration/feature_registration.dart b/pkg/analysis_server/lib/src/lsp/registration/feature_registration.dart index 4e8a6e20d65e..1d227b5c624e 100644 --- a/pkg/analysis_server/lib/src/lsp/registration/feature_registration.dart +++ b/pkg/analysis_server/lib/src/lsp/registration/feature_registration.dart @@ -57,7 +57,7 @@ abstract class FeatureRegistration { ClientDynamicRegistrations get clientDynamic => _context.clientDynamic; /// A set of filters for the currently supported Dart files. - List get dartFiles => _context.dartFilters; + List get dartFiles => _context.dartFilters; /// Gets all dynamic registrations for this feature. /// @@ -69,7 +69,7 @@ abstract class FeatureRegistration { /// File types like pubspec.yaml, analysis_options.yaml and fix_data files are /// not included here as their support is very limited and do not provide /// functionality in most handlers. - List get fullySupportedTypes { + List get fullySupportedTypes { return { ...dartFiles, ...pluginTypes, @@ -77,7 +77,7 @@ abstract class FeatureRegistration { } /// Types of documents that loaded plugins are interested in. - List get pluginTypes => _context.pluginTypes; + List get pluginTypes => _context.pluginTypes; /// Whether both the client, and this feature, support dynamic registration. bool get supportsDynamic; @@ -191,7 +191,7 @@ class RegistrationContext { final ClientDynamicRegistrations clientDynamic; /// Types of documents that loaded plugins are interested in. - final List pluginTypes; + final List pluginTypes; /// The capabilities of the client. final LspClientCapabilities clientCapabilities; @@ -200,7 +200,7 @@ class RegistrationContext { final LspClientConfiguration clientConfiguration; /// Filters for all Dart files supported by the current server. - final List dartFilters; + final List dartFilters; /// Custom schemes supported for Dart files by the current server. /// 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 a3467925176c..26c1486bac23 100644 --- a/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart +++ b/pkg/analysis_server/lib/src/lsp/server_capabilities_computer.dart @@ -146,7 +146,7 @@ class ServerCapabilitiesComputer { ServerCapabilitiesComputer(this._server); - List get pluginTypes => AnalysisServer + List get pluginTypes => AnalysisServer .supportsPlugins ? _server.pluginManager.plugins .expand( @@ -156,9 +156,9 @@ class ServerCapabilitiesComputer { // interestingFiles. Prefix a `**/` so that the glob matches nested // folders as well. .map((glob) => - TextDocumentFilterWithScheme(scheme: 'file', pattern: '**/$glob')) + TextDocumentFilterScheme(scheme: 'file', pattern: '**/$glob')) .toList() - : []; + : []; ServerCapabilities computeServerCapabilities( LspClientCapabilities clientCapabilities, @@ -194,7 +194,7 @@ class ServerCapabilitiesComputer { typeHierarchyProvider: features.typeHierarchy.staticRegistration, executeCommandProvider: features.executeCommand.staticRegistration, workspaceSymbolProvider: features.workspaceSymbol.staticRegistration, - workspace: ServerCapabilitiesWorkspace( + workspace: WorkspaceOptions( workspaceFolders: WorkspaceFoldersServerCapabilities( supported: true, changeNotifications: features.changeNotifications.staticRegistration, @@ -336,7 +336,7 @@ class ServerCapabilitiesComputer { 'file', ..._server.uriConverter.supportedNonFileSchemes }) - TextDocumentFilterWithScheme(language: 'dart', scheme: scheme) + TextDocumentFilterScheme(language: 'dart', scheme: scheme) ], pluginTypes: pluginTypes, ); diff --git a/pkg/analysis_server/test/lsp/completion_dart_test.dart b/pkg/analysis_server/test/lsp/completion_dart_test.dart index fff476d8498d..9e7b16dddd58 100644 --- a/pkg/analysis_server/test/lsp/completion_dart_test.dart +++ b/pkg/analysis_server/test/lsp/completion_dart_test.dart @@ -4907,7 +4907,7 @@ abstract class SnippetCompletionTest extends AbstractLspAnalysisServerTest /// Expect that there is a snippet for [prefix] with the label [label] at /// [position] in [content]. - Future<({CompletionItem snippet, CompletionListItemDefaults? defaults})> + Future<({CompletionItem snippet, CompletionItemDefaults? defaults})> expectSnippet( TestCode code, { required String prefix, diff --git a/pkg/analysis_server/test/lsp/document_changes_test.dart b/pkg/analysis_server/test/lsp/document_changes_test.dart index 36eac286c2a4..f751903a3a32 100644 --- a/pkg/analysis_server/test/lsp/document_changes_test.dart +++ b/pkg/analysis_server/test/lsp/document_changes_test.dart @@ -37,13 +37,13 @@ class Bar { if (!AnalysisServer.supportsPlugins) return; await _initializeAndOpen(); await changeFile(2, mainFileUri, [ - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 0, character: 6), end: Position(line: 0, character: 9)), text: 'Bar', )), - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 1, character: 21), end: Position(line: 1, character: 24)), @@ -63,13 +63,13 @@ class Bar { Future test_documentChange_updatesOverlay() async { await _initializeAndOpen(); await changeFile(2, mainFileUri, [ - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 0, character: 6), end: Position(line: 0, character: 9)), text: 'Bar', )), - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 1, character: 21), end: Position(line: 1, character: 24)), diff --git a/pkg/analysis_server/test/lsp/file_modification_test.dart b/pkg/analysis_server/test/lsp/file_modification_test.dart index 52b48d02b021..e1ae4aebd065 100644 --- a/pkg/analysis_server/test/lsp/file_modification_test.dart +++ b/pkg/analysis_server/test/lsp/file_modification_test.dart @@ -26,7 +26,7 @@ class FileModificationTest extends AbstractLspAnalysisServerTest { // to alert the user to something failing. var error = await expectErrorNotification(() async { await changeFile(222, mainFileUri, [ - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 999, character: 999), end: Position(line: 999, character: 999)), @@ -59,7 +59,7 @@ class FileModificationTest extends AbstractLspAnalysisServerTest { await openFile(mainFileUri, initialContent); await changeFile(222, mainFileUri, [ // Replace line1:5-1:8 with spaces. - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 1, character: 8), end: Position(line: 1, character: 11)), @@ -77,7 +77,7 @@ class FileModificationTest extends AbstractLspAnalysisServerTest { // has not opened, but Visual Studio has done it in the past so we should // ensure it generates an obvious error that the user can understand. var simpleEdit = - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 1, character: 1), end: Position(line: 1, character: 1)), diff --git a/pkg/analysis_server/test/lsp/initialization_test.dart b/pkg/analysis_server/test/lsp/initialization_test.dart index 624375f2093a..2a8a807f099c 100644 --- a/pkg/analysis_server/test/lsp/initialization_test.dart +++ b/pkg/analysis_server/test/lsp/initialization_test.dart @@ -608,9 +608,9 @@ class InitializationTest extends AbstractLspAnalysisServerTest { .registrations; var documentFilterSql = - TextDocumentFilterWithScheme(scheme: 'file', pattern: '**/*.sql'); + TextDocumentFilterScheme(scheme: 'file', pattern: '**/*.sql'); var documentFilterDart = - TextDocumentFilterWithScheme(language: 'dart', scheme: 'file'); + TextDocumentFilterScheme(language: 'dart', scheme: 'file'); expect( registrations, diff --git a/pkg/analysis_server/test/lsp/request_helpers_mixin.dart b/pkg/analysis_server/test/lsp/request_helpers_mixin.dart index 4e06f6d3d012..cdfed686a820 100644 --- a/pkg/analysis_server/test/lsp/request_helpers_mixin.dart +++ b/pkg/analysis_server/test/lsp/request_helpers_mixin.dart @@ -710,7 +710,7 @@ mixin LspRequestHelpersMixin { request, _fromJsonList(CallHierarchyItem.fromJson)); } - Future prepareRename(Uri uri, Position pos) { + Future prepareRename(Uri uri, Position pos) { var request = makeRequest( Method.textDocument_prepareRename, TextDocumentPositionParams( @@ -718,7 +718,8 @@ mixin LspRequestHelpersMixin { position: pos, ), ); - return expectSuccessfulResponseTo(request, PlaceholderAndRange.fromJson); + return expectSuccessfulResponseTo( + request, PrepareRenamePlaceholder.fromJson); } Future?> prepareTypeHierarchy(Uri uri, Position pos) { diff --git a/pkg/analysis_server/test/lsp/server_abstract.dart b/pkg/analysis_server/test/lsp/server_abstract.dart index bf81caf3bbd5..c881c8c0e23a 100644 --- a/pkg/analysis_server/test/lsp/server_abstract.dart +++ b/pkg/analysis_server/test/lsp/server_abstract.dart @@ -751,7 +751,7 @@ mixin ClientCapabilitiesHelperMixin { var json = name == 'semanticTokens' ? SemanticTokensClientCapabilities( dynamicRegistration: true, - requests: SemanticTokensClientCapabilitiesRequests(), + requests: ClientSemanticTokensRequestOptions(), formats: [], tokenModifiers: [], tokenTypes: []).toJson() @@ -1407,7 +1407,7 @@ mixin LspAnalysisServerTestMixin uri, [ TextDocumentContentChangeEvent.t2( - TextDocumentContentChangeEvent2(text: content)) + TextDocumentContentChangeWholeDocument(text: content)) ], ); } diff --git a/pkg/analysis_server/test/lsp/server_test.dart b/pkg/analysis_server/test/lsp/server_test.dart index 27199e75d378..e53fc29cdc87 100644 --- a/pkg/analysis_server/test/lsp/server_test.dart +++ b/pkg/analysis_server/test/lsp/server_test.dart @@ -186,7 +186,7 @@ class ServerTest extends AbstractLspAnalysisServerTest { // client and server are out of sync and we expect the server to shut down. var error = await expectErrorNotification(() async { await changeFile(222, mainFileUri, [ - TextDocumentContentChangeEvent.t1(TextDocumentContentChangeEvent1( + TextDocumentContentChangeEvent.t1(TextDocumentContentChangePartial( range: Range( start: Position(line: 99, character: 99), end: Position(line: 99, character: 99)), 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 9180d52937bd..1a21e3d8cc52 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 @@ -16,10 +16,10 @@ void main() { }); test('with list fields can be checked for equality', () { - var a = CodeActionLiteralSupportCodeActionKind( + var a = ClientCodeActionKindOptions( valueSet: [CodeActionKind.QuickFix], ); - var b = CodeActionLiteralSupportCodeActionKind( + var b = ClientCodeActionKindOptions( valueSet: [CodeActionKind.QuickFix], ); @@ -29,10 +29,10 @@ void main() { test('with aliased list fields can be checked for equality', () { var a = TextDocumentRegistrationOptions(documentSelector: [ - TextDocumentFilterWithScheme(language: 'dart', scheme: 'file') + TextDocumentFilterScheme(language: 'dart', scheme: 'file') ]); var b = TextDocumentRegistrationOptions(documentSelector: [ - TextDocumentFilterWithScheme(language: 'dart', scheme: 'file') + TextDocumentFilterScheme(language: 'dart', scheme: 'file') ]); expect(a, equals(b)); @@ -87,12 +87,12 @@ void main() { test('consider subclasses when checking for equality', () { var a = TextDocumentRegistrationOptions(documentSelector: [ - TextDocumentFilterWithScheme(language: 'dart', scheme: 'file') + TextDocumentFilterScheme(language: 'dart', scheme: 'file') ]); var b = TextDocumentSaveRegistrationOptions( includeText: true, documentSelector: [ - TextDocumentFilterWithScheme(language: 'dart', scheme: 'file') + TextDocumentFilterScheme(language: 'dart', scheme: 'file') ]); expect(a, isNot(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 746a09c6e06a..74a12aa80d68 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/json_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/json_test.dart @@ -108,7 +108,7 @@ void main() { }); test('toJson() converts lists of enums to their underlying values', () { - var kind = CompletionClientCapabilitiesCompletionItemKind( + var kind = ClientCompletionItemOptionsKind( valueSet: [CompletionItemKind.Color], ); var json = kind.toJson(); @@ -444,11 +444,10 @@ void main() { ]; var obj = InitializeParams( processId: 1, - clientInfo: - InitializeParamsClientInfo(name: 'server name', version: '1.2.3'), + clientInfo: ClientInfo(name: 'server name', version: '1.2.3'), rootPath: '!root', capabilities: ClientCapabilities(), - trace: TraceValues.Off, + trace: TraceValue.Off, workspaceFolders: workspaceFolders, ); var json = jsonEncode(obj); diff --git a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart index 1625bd988a13..dea173f1938d 100644 --- a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart +++ b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart @@ -42,7 +42,7 @@ bool enumClassAllowsAnyValue(String name) { name != 'InsertTextFormat' && name != 'MarkupKind' && name != 'ResourceOperationKind' && - name != 'TraceValues'; + name != 'TraceValue'; } /// Generates the ultimate Dart code for [types], sorted and formatted. @@ -96,7 +96,7 @@ TypeBase resolveTypeAlias(TypeBase type, } var alias = _typeAliases[type.name]; - if (alias != null && (!onlyRenames || alias.isRename)) { + if (alias != null && (!onlyRenames || alias.renameReferences)) { // Resolve aliases recursively. var resolved = alias.baseType; for (int i = 0; i < 10; i++) { @@ -1123,7 +1123,7 @@ void _writeType(IndentableStringBuffer buffer, LspEntity type) { } void _writeTypeAlias(IndentableStringBuffer buffer, TypeAlias alias) { - if (alias.isRename) return; + if (!alias.generateTypeDef) return; var baseType = alias.baseType; var typeName = baseType.dartTypeWithTypeArgs; _writeDocCommentsAndAnnotations(buffer, alias); diff --git a/pkg/analysis_server/tool/lsp_spec/generate_all.dart b/pkg/analysis_server/tool/lsp_spec/generate_all.dart index 50a8a03346eb..4ab702cf50fb 100644 --- a/pkg/analysis_server/tool/lsp_spec/generate_all.dart +++ b/pkg/analysis_server/tool/lsp_spec/generate_all.dart @@ -165,12 +165,12 @@ List getCustomClasses() { TypeAlias( name: 'LSPAny', baseType: TypeReference.LspAny, - isRename: false, + renameReferences: false, ), TypeAlias( name: 'LSPObject', baseType: TypeReference.LspObject, - isRename: false, + renameReferences: false, ), // The DocumentFilter more complex in v3.17's meta_model (to allow // TextDocumentFilters to be guaranteed to have at least one of language, @@ -179,8 +179,8 @@ List getCustomClasses() { // TODO(dantup): Improve this after the TS->JSON Spec migration. TypeAlias( name: 'DocumentFilter', - baseType: TypeReference('TextDocumentFilter2'), - isRename: true, + baseType: TypeReference('TextDocumentFilterScheme'), + renameReferences: true, ), // Similarly, the meta_model includes String as an option for // DocumentSelector which is deprecated and we never previously supported @@ -189,8 +189,8 @@ List getCustomClasses() { // TODO(dantup): Improve this after the TS->JSON Spec migration. TypeAlias( name: 'DocumentSelector', - baseType: ArrayType(TypeReference('TextDocumentFilterWithScheme')), - isRename: true, + baseType: ArrayType(TypeReference('TextDocumentFilterScheme')), + renameReferences: true, ), interface('Message', [ field('jsonrpc', type: 'string'), @@ -257,7 +257,7 @@ List getCustomClasses() { TypeAlias( name: 'DocumentUri', baseType: TypeReference('Uri'), - isRename: false, + renameReferences: false, ), // The LSP Spec uses "URI" but since that's fairly generic and will show up // everywhere in code completion, we rename it to "LspUri" before using @@ -265,12 +265,12 @@ List getCustomClasses() { TypeAlias( name: 'URI', baseType: TypeReference('LSPUri'), - isRename: true, + renameReferences: true, ), TypeAlias( name: 'LSPUri', baseType: TypeReference('Uri'), - isRename: false, + renameReferences: false, ), interface('ConnectToDtdParams', [field('uri', type: 'Uri')]), @@ -426,7 +426,7 @@ List getCustomClasses() { TypeReference('TextEdit'), ]), ), - isRename: false, + renameReferences: false, ), // // Command parameter support diff --git a/pkg/analysis_server/tool/lsp_spec/meta_model.dart b/pkg/analysis_server/tool/lsp_spec/meta_model.dart index b3cc2a9ca7a7..ecde377f5e86 100644 --- a/pkg/analysis_server/tool/lsp_spec/meta_model.dart +++ b/pkg/analysis_server/tool/lsp_spec/meta_model.dart @@ -229,20 +229,21 @@ class NullableType extends TypeBase { class TypeAlias extends LspEntity { final TypeBase baseType; - /// Whether this alias is just a simple rename and not a name for a more - /// complex type. - /// - /// Renames will be followed when generating code, but other aliases may be - /// created as `typedef`s. - final bool isRename; + /// Whether this alias should be resolved to its base type when generating + /// code. + final bool renameReferences; + + /// Whether a typedef should be created for this alias. + final bool generateTypeDef; TypeAlias({ required super.name, super.comment, super.isProposed, required this.baseType, - required this.isRename, - }); + required this.renameReferences, + bool? generateTypeDef, + }) : generateTypeDef = generateTypeDef ?? !renameReferences; } /// Base class for a Type parsed from the LSP JSON model. diff --git a/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart b/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart index 0b77a22cd14d..3ee3f9e5e9d4 100644 --- a/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart +++ b/pkg/analysis_server/tool/lsp_spec/meta_model_cleaner.dart @@ -208,7 +208,7 @@ class LspMetaModelCleaner { name: typeAlias.name, comment: _cleanComment(typeAlias.comment), baseType: _cleanType(typeAlias.baseType), - isRename: typeAlias.isRename, + renameReferences: typeAlias.renameReferences, ); } @@ -419,23 +419,69 @@ class LspMetaModelCleaner { /// Renames types that may have been generated with bad (or long) names. Iterable _renameTypes(List types) sync* { const renames = { - 'CodeActionClientCapabilitiesCodeActionLiteralSupportCodeActionKind': - 'CodeActionLiteralSupportCodeActionKind', 'CompletionClientCapabilitiesCompletionItemInsertTextModeSupport': 'CompletionItemInsertTextModeSupport', 'CompletionClientCapabilitiesCompletionItemTagSupport': 'CompletionItemTagSupport', 'CompletionClientCapabilitiesCompletionItemResolveSupport': 'CompletionItemResolveSupport', - 'CompletionListItemDefaultsEditRange': 'CompletionItemEditRange', 'SignatureHelpClientCapabilitiesSignatureInformationParameterInformation': 'SignatureInformationParameterInformation', - 'TextDocumentFilter2': 'TextDocumentFilterWithScheme', - 'PrepareRenameResult1': 'PlaceholderAndRange', 'Pattern': 'LspPattern', 'URI': 'LSPUri', + + // In LSP 3.18, many types that were previously inline and got generated + // names have been extracted to their own definitions with hand-written + // names. + // To reduce the size of the upcoming diff when this happens, these + // renames change our 3.17 generated names to those that will be used + // for 3.18. + // TODO(dantup): Remove these once LSP 3.18 release and we regenerate + // using it. + 'TextDocumentFilter2': 'TextDocumentFilterScheme', + 'PrepareRenameResult1': 'PrepareRenamePlaceholder', + 'TextDocumentContentChangeEvent1': 'TextDocumentContentChangePartial', + 'TextDocumentContentChangeEvent2': + 'TextDocumentContentChangeWholeDocument', + 'CompletionListItemDefaults': 'CompletionItemDefaults', + 'InitializeParamsClientInfo': 'ClientInfo', + 'SemanticTokensClientCapabilitiesRequests': + 'ClientSemanticTokensRequestOptions', + 'TraceValues': 'TraceValue', + 'SemanticTokensOptionsFull': 'SemanticTokensFullDelta', + 'CompletionListItemDefaultsEditRange': 'EditRangeWithInsertReplace', + 'ServerCapabilitiesWorkspace': 'WorkspaceOptions', + 'CodeActionClientCapabilitiesCodeActionLiteralSupportCodeActionKind': + 'ClientCodeActionKindOptions', + 'CompletionClientCapabilitiesCompletionItemKind': + 'ClientCompletionItemOptionsKind', + 'CompletionOptionsCompletionItem': 'ServerCompletionItemOptions', + 'InitializeResultServerInfo': 'ServerInfo', + // End of temporary renames }; + // Temporary aliases for old names used in g3 + // TODO(dantup): Remove these once the internal code has been updated. + var typeNames = types.map((type) => type.name).toSet(); + if (typeNames.contains('TextDocumentContentChangeEvent2')) { + yield TypeAlias( + name: 'TextDocumentContentChangeEvent2', + baseType: TypeReference('TextDocumentContentChangeWholeDocument'), + renameReferences: true, + generateTypeDef: true, + ); + } + if (typeNames.contains( + 'CodeActionClientCapabilitiesCodeActionLiteralSupportCodeActionKind')) { + yield TypeAlias( + name: 'CodeActionLiteralSupportCodeActionKind', + baseType: TypeReference('ClientCodeActionKindOptions'), + renameReferences: true, + generateTypeDef: true, + ); + } + // End temporary aliases + for (var type in types) { var newName = renames[type.name]; if (newName == null) { @@ -449,7 +495,7 @@ class LspMetaModelCleaner { comment: type.comment, isProposed: type.isProposed, baseType: TypeReference(newName), - isRename: true, + renameReferences: true, ); // Replace the type with an equivalent with the same name. @@ -467,7 +513,15 @@ class LspMetaModelCleaner { comment: type.comment, isProposed: type.isProposed, baseType: type.baseType, - isRename: type.isRename, + renameReferences: type.renameReferences, + ); + } else if (type is LspEnum) { + yield LspEnum( + name: newName, + comment: type.comment, + isProposed: type.isProposed, + typeOfValues: type.typeOfValues, + members: type.members, ); } else { throw 'Renaming ${type.runtimeType} is not implemented'; diff --git a/pkg/analysis_server/tool/lsp_spec/meta_model_reader.dart b/pkg/analysis_server/tool/lsp_spec/meta_model_reader.dart index c8b8f4f29169..7dba4b036c73 100644 --- a/pkg/analysis_server/tool/lsp_spec/meta_model_reader.dart +++ b/pkg/analysis_server/tool/lsp_spec/meta_model_reader.dart @@ -130,7 +130,7 @@ class LspMetaModelReader { comment: documentation, isProposed: _isProposed(documentation), baseType: type, - isRename: false, + renameReferences: false, )); } } @@ -364,7 +364,7 @@ class LspMetaModelReader { comment: documentation, isProposed: _isProposed(documentation), baseType: _extractType(name, null, model['type']), - isRename: false, + renameReferences: false, ); } } diff --git a/third_party/pkg/language_server_protocol/lib/protocol_generated.dart b/third_party/pkg/language_server_protocol/lib/protocol_generated.dart index 5c700cda6e93..1a831cec22e8 100644 --- a/third_party/pkg/language_server_protocol/lib/protocol_generated.dart +++ b/third_party/pkg/language_server_protocol/lib/protocol_generated.dart @@ -676,7 +676,7 @@ bool _canParseBoolSemanticTokensClientCapabilitiesRequestsRange( return true; } -bool _canParseBoolSemanticTokensOptionsFull( +bool _canParseBoolSemanticTokensFullDelta( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -693,9 +693,9 @@ bool _canParseBoolSemanticTokensOptionsFull( } if ((!nullCheck || value != null) && (value is! bool && - !SemanticTokensOptionsFull.canParse(value, reporter))) { + !SemanticTokensFullDelta.canParse(value, reporter))) { reporter.reportError( - 'must be of type Either2'); + 'must be of type Either2'); return false; } } finally { @@ -920,7 +920,7 @@ bool _canParseClientCapabilities( return true; } -bool _canParseCodeActionClientCapabilities( +bool _canParseClientCodeActionKindOptions( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -936,8 +936,8 @@ bool _canParseCodeActionClientCapabilities( return false; } if ((!nullCheck || value != null) && - !CodeActionClientCapabilities.canParse(value, reporter)) { - reporter.reportError('must be of type CodeActionClientCapabilities'); + !ClientCodeActionKindOptions.canParse(value, reporter)) { + reporter.reportError('must be of type ClientCodeActionKindOptions'); return false; } } finally { @@ -946,7 +946,7 @@ bool _canParseCodeActionClientCapabilities( return true; } -bool _canParseCodeActionClientCapabilitiesCodeActionLiteralSupport( +bool _canParseClientCompletionItemOptionsKind( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -962,10 +962,8 @@ bool _canParseCodeActionClientCapabilitiesCodeActionLiteralSupport( return false; } if ((!nullCheck || value != null) && - !CodeActionClientCapabilitiesCodeActionLiteralSupport.canParse( - value, reporter)) { - reporter.reportError( - 'must be of type CodeActionClientCapabilitiesCodeActionLiteralSupport'); + !ClientCompletionItemOptionsKind.canParse(value, reporter)) { + reporter.reportError('must be of type ClientCompletionItemOptionsKind'); return false; } } finally { @@ -974,7 +972,7 @@ bool _canParseCodeActionClientCapabilitiesCodeActionLiteralSupport( return true; } -bool _canParseCodeActionClientCapabilitiesResolveSupport( +bool _canParseClientInfo( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -990,9 +988,8 @@ bool _canParseCodeActionClientCapabilitiesResolveSupport( return false; } if ((!nullCheck || value != null) && - !CodeActionClientCapabilitiesResolveSupport.canParse(value, reporter)) { - reporter.reportError( - 'must be of type CodeActionClientCapabilitiesResolveSupport'); + !ClientInfo.canParse(value, reporter)) { + reporter.reportError('must be of type ClientInfo'); return false; } } finally { @@ -1001,7 +998,7 @@ bool _canParseCodeActionClientCapabilitiesResolveSupport( return true; } -bool _canParseCodeActionContext( +bool _canParseClientSemanticTokensRequestOptions( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1017,8 +1014,9 @@ bool _canParseCodeActionContext( return false; } if ((!nullCheck || value != null) && - !CodeActionContext.canParse(value, reporter)) { - reporter.reportError('must be of type CodeActionContext'); + !ClientSemanticTokensRequestOptions.canParse(value, reporter)) { + reporter + .reportError('must be of type ClientSemanticTokensRequestOptions'); return false; } } finally { @@ -1027,7 +1025,7 @@ bool _canParseCodeActionContext( return true; } -bool _canParseCodeActionDisabled( +bool _canParseCodeActionClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1043,8 +1041,8 @@ bool _canParseCodeActionDisabled( return false; } if ((!nullCheck || value != null) && - !CodeActionDisabled.canParse(value, reporter)) { - reporter.reportError('must be of type CodeActionDisabled'); + !CodeActionClientCapabilities.canParse(value, reporter)) { + reporter.reportError('must be of type CodeActionClientCapabilities'); return false; } } finally { @@ -1053,7 +1051,7 @@ bool _canParseCodeActionDisabled( return true; } -bool _canParseCodeActionKind( +bool _canParseCodeActionClientCapabilitiesCodeActionLiteralSupport( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1069,8 +1067,10 @@ bool _canParseCodeActionKind( return false; } if ((!nullCheck || value != null) && - !CodeActionKind.canParse(value, reporter)) { - reporter.reportError('must be of type CodeActionKind'); + !CodeActionClientCapabilitiesCodeActionLiteralSupport.canParse( + value, reporter)) { + reporter.reportError( + 'must be of type CodeActionClientCapabilitiesCodeActionLiteralSupport'); return false; } } finally { @@ -1079,7 +1079,7 @@ bool _canParseCodeActionKind( return true; } -bool _canParseCodeActionLiteralSupportCodeActionKind( +bool _canParseCodeActionClientCapabilitiesResolveSupport( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1095,9 +1095,9 @@ bool _canParseCodeActionLiteralSupportCodeActionKind( return false; } if ((!nullCheck || value != null) && - !CodeActionLiteralSupportCodeActionKind.canParse(value, reporter)) { + !CodeActionClientCapabilitiesResolveSupport.canParse(value, reporter)) { reporter.reportError( - 'must be of type CodeActionLiteralSupportCodeActionKind'); + 'must be of type CodeActionClientCapabilitiesResolveSupport'); return false; } } finally { @@ -1106,7 +1106,7 @@ bool _canParseCodeActionLiteralSupportCodeActionKind( return true; } -bool _canParseCodeActionTriggerKind( +bool _canParseCodeActionContext( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1122,8 +1122,8 @@ bool _canParseCodeActionTriggerKind( return false; } if ((!nullCheck || value != null) && - !CodeActionTriggerKind.canParse(value, reporter)) { - reporter.reportError('must be of type CodeActionTriggerKind'); + !CodeActionContext.canParse(value, reporter)) { + reporter.reportError('must be of type CodeActionContext'); return false; } } finally { @@ -1132,7 +1132,7 @@ bool _canParseCodeActionTriggerKind( return true; } -bool _canParseCodeDescription( +bool _canParseCodeActionDisabled( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1148,8 +1148,8 @@ bool _canParseCodeDescription( return false; } if ((!nullCheck || value != null) && - !CodeDescription.canParse(value, reporter)) { - reporter.reportError('must be of type CodeDescription'); + !CodeActionDisabled.canParse(value, reporter)) { + reporter.reportError('must be of type CodeActionDisabled'); return false; } } finally { @@ -1158,7 +1158,7 @@ bool _canParseCodeDescription( return true; } -bool _canParseCodeLensClientCapabilities( +bool _canParseCodeActionKind( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1174,8 +1174,8 @@ bool _canParseCodeLensClientCapabilities( return false; } if ((!nullCheck || value != null) && - !CodeLensClientCapabilities.canParse(value, reporter)) { - reporter.reportError('must be of type CodeLensClientCapabilities'); + !CodeActionKind.canParse(value, reporter)) { + reporter.reportError('must be of type CodeActionKind'); return false; } } finally { @@ -1184,7 +1184,7 @@ bool _canParseCodeLensClientCapabilities( return true; } -bool _canParseCodeLensOptions( +bool _canParseCodeActionTriggerKind( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1200,8 +1200,8 @@ bool _canParseCodeLensOptions( return false; } if ((!nullCheck || value != null) && - !CodeLensOptions.canParse(value, reporter)) { - reporter.reportError('must be of type CodeLensOptions'); + !CodeActionTriggerKind.canParse(value, reporter)) { + reporter.reportError('must be of type CodeActionTriggerKind'); return false; } } finally { @@ -1210,7 +1210,7 @@ bool _canParseCodeLensOptions( return true; } -bool _canParseCodeLensWorkspaceClientCapabilities( +bool _canParseCodeDescription( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1226,9 +1226,8 @@ bool _canParseCodeLensWorkspaceClientCapabilities( return false; } if ((!nullCheck || value != null) && - !CodeLensWorkspaceClientCapabilities.canParse(value, reporter)) { - reporter - .reportError('must be of type CodeLensWorkspaceClientCapabilities'); + !CodeDescription.canParse(value, reporter)) { + reporter.reportError('must be of type CodeDescription'); return false; } } finally { @@ -1237,7 +1236,7 @@ bool _canParseCodeLensWorkspaceClientCapabilities( return true; } -bool _canParseColor( +bool _canParseCodeLensClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1252,8 +1251,9 @@ bool _canParseColor( reporter.reportError('must not be null'); return false; } - if ((!nullCheck || value != null) && !Color.canParse(value, reporter)) { - reporter.reportError('must be of type Color'); + if ((!nullCheck || value != null) && + !CodeLensClientCapabilities.canParse(value, reporter)) { + reporter.reportError('must be of type CodeLensClientCapabilities'); return false; } } finally { @@ -1262,7 +1262,7 @@ bool _canParseColor( return true; } -bool _canParseCommand( +bool _canParseCodeLensOptions( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1277,8 +1277,9 @@ bool _canParseCommand( reporter.reportError('must not be null'); return false; } - if ((!nullCheck || value != null) && !Command.canParse(value, reporter)) { - reporter.reportError('must be of type Command'); + if ((!nullCheck || value != null) && + !CodeLensOptions.canParse(value, reporter)) { + reporter.reportError('must be of type CodeLensOptions'); return false; } } finally { @@ -1287,7 +1288,7 @@ bool _canParseCommand( return true; } -bool _canParseCompletionClientCapabilities( +bool _canParseCodeLensWorkspaceClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1303,8 +1304,9 @@ bool _canParseCompletionClientCapabilities( return false; } if ((!nullCheck || value != null) && - !CompletionClientCapabilities.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionClientCapabilities'); + !CodeLensWorkspaceClientCapabilities.canParse(value, reporter)) { + reporter + .reportError('must be of type CodeLensWorkspaceClientCapabilities'); return false; } } finally { @@ -1313,7 +1315,7 @@ bool _canParseCompletionClientCapabilities( return true; } -bool _canParseCompletionClientCapabilitiesCompletionItem( +bool _canParseColor( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1328,10 +1330,8 @@ bool _canParseCompletionClientCapabilitiesCompletionItem( reporter.reportError('must not be null'); return false; } - if ((!nullCheck || value != null) && - !CompletionClientCapabilitiesCompletionItem.canParse(value, reporter)) { - reporter.reportError( - 'must be of type CompletionClientCapabilitiesCompletionItem'); + if ((!nullCheck || value != null) && !Color.canParse(value, reporter)) { + reporter.reportError('must be of type Color'); return false; } } finally { @@ -1340,7 +1340,7 @@ bool _canParseCompletionClientCapabilitiesCompletionItem( return true; } -bool _canParseCompletionClientCapabilitiesCompletionItemKind( +bool _canParseCommand( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1355,11 +1355,8 @@ bool _canParseCompletionClientCapabilitiesCompletionItemKind( reporter.reportError('must not be null'); return false; } - if ((!nullCheck || value != null) && - !CompletionClientCapabilitiesCompletionItemKind.canParse( - value, reporter)) { - reporter.reportError( - 'must be of type CompletionClientCapabilitiesCompletionItemKind'); + if ((!nullCheck || value != null) && !Command.canParse(value, reporter)) { + reporter.reportError('must be of type Command'); return false; } } finally { @@ -1368,7 +1365,7 @@ bool _canParseCompletionClientCapabilitiesCompletionItemKind( return true; } -bool _canParseCompletionClientCapabilitiesCompletionList( +bool _canParseCompletionClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1384,9 +1381,8 @@ bool _canParseCompletionClientCapabilitiesCompletionList( return false; } if ((!nullCheck || value != null) && - !CompletionClientCapabilitiesCompletionList.canParse(value, reporter)) { - reporter.reportError( - 'must be of type CompletionClientCapabilitiesCompletionList'); + !CompletionClientCapabilities.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionClientCapabilities'); return false; } } finally { @@ -1395,7 +1391,7 @@ bool _canParseCompletionClientCapabilitiesCompletionList( return true; } -bool _canParseCompletionContext( +bool _canParseCompletionClientCapabilitiesCompletionItem( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1411,8 +1407,9 @@ bool _canParseCompletionContext( return false; } if ((!nullCheck || value != null) && - !CompletionContext.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionContext'); + !CompletionClientCapabilitiesCompletionItem.canParse(value, reporter)) { + reporter.reportError( + 'must be of type CompletionClientCapabilitiesCompletionItem'); return false; } } finally { @@ -1421,7 +1418,7 @@ bool _canParseCompletionContext( return true; } -bool _canParseCompletionItemEditRangeRange( +bool _canParseCompletionClientCapabilitiesCompletionList( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1437,10 +1434,9 @@ bool _canParseCompletionItemEditRangeRange( return false; } if ((!nullCheck || value != null) && - (!CompletionItemEditRange.canParse(value, reporter) && - !Range.canParse(value, reporter))) { + !CompletionClientCapabilitiesCompletionList.canParse(value, reporter)) { reporter.reportError( - 'must be of type Either2'); + 'must be of type CompletionClientCapabilitiesCompletionList'); return false; } } finally { @@ -1449,7 +1445,7 @@ bool _canParseCompletionItemEditRangeRange( return true; } -bool _canParseCompletionItemInsertTextModeSupport( +bool _canParseCompletionContext( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1465,9 +1461,8 @@ bool _canParseCompletionItemInsertTextModeSupport( return false; } if ((!nullCheck || value != null) && - !CompletionItemInsertTextModeSupport.canParse(value, reporter)) { - reporter - .reportError('must be of type CompletionItemInsertTextModeSupport'); + !CompletionContext.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionContext'); return false; } } finally { @@ -1476,7 +1471,7 @@ bool _canParseCompletionItemInsertTextModeSupport( return true; } -bool _canParseCompletionItemKind( +bool _canParseCompletionItemDefaults( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1492,8 +1487,8 @@ bool _canParseCompletionItemKind( return false; } if ((!nullCheck || value != null) && - !CompletionItemKind.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionItemKind'); + !CompletionItemDefaults.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemDefaults'); return false; } } finally { @@ -1502,7 +1497,7 @@ bool _canParseCompletionItemKind( return true; } -bool _canParseCompletionItemLabelDetails( +bool _canParseCompletionItemInsertTextModeSupport( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1518,8 +1513,9 @@ bool _canParseCompletionItemLabelDetails( return false; } if ((!nullCheck || value != null) && - !CompletionItemLabelDetails.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionItemLabelDetails'); + !CompletionItemInsertTextModeSupport.canParse(value, reporter)) { + reporter + .reportError('must be of type CompletionItemInsertTextModeSupport'); return false; } } finally { @@ -1528,7 +1524,7 @@ bool _canParseCompletionItemLabelDetails( return true; } -bool _canParseCompletionItemResolutionInfo( +bool _canParseCompletionItemKind( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1544,8 +1540,8 @@ bool _canParseCompletionItemResolutionInfo( return false; } if ((!nullCheck || value != null) && - !CompletionItemResolutionInfo.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionItemResolutionInfo'); + !CompletionItemKind.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemKind'); return false; } } finally { @@ -1554,7 +1550,7 @@ bool _canParseCompletionItemResolutionInfo( return true; } -bool _canParseCompletionItemResolveSupport( +bool _canParseCompletionItemLabelDetails( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1570,8 +1566,8 @@ bool _canParseCompletionItemResolveSupport( return false; } if ((!nullCheck || value != null) && - !CompletionItemResolveSupport.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionItemResolveSupport'); + !CompletionItemLabelDetails.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemLabelDetails'); return false; } } finally { @@ -1580,7 +1576,7 @@ bool _canParseCompletionItemResolveSupport( return true; } -bool _canParseCompletionItemTagSupport( +bool _canParseCompletionItemResolutionInfo( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1596,8 +1592,8 @@ bool _canParseCompletionItemTagSupport( return false; } if ((!nullCheck || value != null) && - !CompletionItemTagSupport.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionItemTagSupport'); + !CompletionItemResolutionInfo.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemResolutionInfo'); return false; } } finally { @@ -1606,7 +1602,7 @@ bool _canParseCompletionItemTagSupport( return true; } -bool _canParseCompletionListItemDefaults( +bool _canParseCompletionItemResolveSupport( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1622,8 +1618,8 @@ bool _canParseCompletionListItemDefaults( return false; } if ((!nullCheck || value != null) && - !CompletionListItemDefaults.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionListItemDefaults'); + !CompletionItemResolveSupport.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemResolveSupport'); return false; } } finally { @@ -1632,7 +1628,7 @@ bool _canParseCompletionListItemDefaults( return true; } -bool _canParseCompletionOptions( +bool _canParseCompletionItemTagSupport( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1648,8 +1644,8 @@ bool _canParseCompletionOptions( return false; } if ((!nullCheck || value != null) && - !CompletionOptions.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionOptions'); + !CompletionItemTagSupport.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionItemTagSupport'); return false; } } finally { @@ -1658,7 +1654,7 @@ bool _canParseCompletionOptions( return true; } -bool _canParseCompletionOptionsCompletionItem( +bool _canParseCompletionOptions( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -1674,8 +1670,8 @@ bool _canParseCompletionOptionsCompletionItem( return false; } if ((!nullCheck || value != null) && - !CompletionOptionsCompletionItem.canParse(value, reporter)) { - reporter.reportError('must be of type CompletionOptionsCompletionItem'); + !CompletionOptions.canParse(value, reporter)) { + reporter.reportError('must be of type CompletionOptions'); return false; } } finally { @@ -2293,6 +2289,34 @@ bool _canParseDocumentSymbolClientCapabilitiesTagSupport( return true; } +bool _canParseEditRangeWithInsertReplaceRange( + Map map, LspJsonReporter reporter, String fieldName, + {required bool allowsUndefined, required bool allowsNull}) { + reporter.push(fieldName); + try { + if (!allowsUndefined && !map.containsKey(fieldName)) { + reporter.reportError('must not be undefined'); + return false; + } + final value = map[fieldName]; + final nullCheck = allowsNull || allowsUndefined; + if (!nullCheck && value == null) { + reporter.reportError('must not be null'); + return false; + } + if ((!nullCheck || value != null) && + (!EditRangeWithInsertReplace.canParse(value, reporter) && + !Range.canParse(value, reporter))) { + reporter.reportError( + 'must be of type Either2'); + return false; + } + } finally { + reporter.pop(); + } + return true; +} + bool _canParseExecuteCommandClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { @@ -2818,58 +2842,6 @@ bool _canParseImplementationClientCapabilities( return true; } -bool _canParseInitializeParamsClientInfo( - Map map, LspJsonReporter reporter, String fieldName, - {required bool allowsUndefined, required bool allowsNull}) { - reporter.push(fieldName); - try { - if (!allowsUndefined && !map.containsKey(fieldName)) { - reporter.reportError('must not be undefined'); - return false; - } - final value = map[fieldName]; - final nullCheck = allowsNull || allowsUndefined; - if (!nullCheck && value == null) { - reporter.reportError('must not be null'); - return false; - } - if ((!nullCheck || value != null) && - !InitializeParamsClientInfo.canParse(value, reporter)) { - reporter.reportError('must be of type InitializeParamsClientInfo'); - return false; - } - } finally { - reporter.pop(); - } - return true; -} - -bool _canParseInitializeResultServerInfo( - Map map, LspJsonReporter reporter, String fieldName, - {required bool allowsUndefined, required bool allowsNull}) { - reporter.push(fieldName); - try { - if (!allowsUndefined && !map.containsKey(fieldName)) { - reporter.reportError('must not be undefined'); - return false; - } - final value = map[fieldName]; - final nullCheck = allowsNull || allowsUndefined; - if (!nullCheck && value == null) { - reporter.reportError('must not be null'); - return false; - } - if ((!nullCheck || value != null) && - !InitializeResultServerInfo.canParse(value, reporter)) { - reporter.reportError('must be of type InitializeResultServerInfo'); - return false; - } - } finally { - reporter.pop(); - } - return true; -} - bool _canParseInlayHintClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { @@ -4352,7 +4324,7 @@ bool _canParseListSymbolTag( } bool - _canParseListTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( + _canParseListTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -4370,8 +4342,9 @@ bool if ((!nullCheck || value != null) && (value is! List || value.any((item) => - !TextDocumentContentChangeEvent1.canParse(item, reporter) && - !TextDocumentContentChangeEvent2.canParse(item, reporter)))) { + !TextDocumentContentChangePartial.canParse(item, reporter) && + !TextDocumentContentChangeWholeDocument.canParse( + item, reporter)))) { reporter .reportError('must be of type List'); return false; @@ -4382,7 +4355,7 @@ bool return true; } -bool _canParseListTextDocumentFilterWithScheme( +bool _canParseListTextDocumentFilterScheme( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -4400,9 +4373,8 @@ bool _canParseListTextDocumentFilterWithScheme( if ((!nullCheck || value != null) && (value is! List || value.any((item) => - !TextDocumentFilterWithScheme.canParse(item, reporter)))) { - reporter - .reportError('must be of type List'); + !TextDocumentFilterScheme.canParse(item, reporter)))) { + reporter.reportError('must be of type List'); return false; } } finally { @@ -5681,33 +5653,6 @@ bool _canParseSemanticTokensClientCapabilities( return true; } -bool _canParseSemanticTokensClientCapabilitiesRequests( - Map map, LspJsonReporter reporter, String fieldName, - {required bool allowsUndefined, required bool allowsNull}) { - reporter.push(fieldName); - try { - if (!allowsUndefined && !map.containsKey(fieldName)) { - reporter.reportError('must not be undefined'); - return false; - } - final value = map[fieldName]; - final nullCheck = allowsNull || allowsUndefined; - if (!nullCheck && value == null) { - reporter.reportError('must not be null'); - return false; - } - if ((!nullCheck || value != null) && - !SemanticTokensClientCapabilitiesRequests.canParse(value, reporter)) { - reporter.reportError( - 'must be of type SemanticTokensClientCapabilitiesRequests'); - return false; - } - } finally { - reporter.pop(); - } - return true; -} - bool _canParseSemanticTokensLegend( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { @@ -5815,7 +5760,7 @@ bool _canParseServerCapabilities( return true; } -bool _canParseServerCapabilitiesWorkspace( +bool _canParseServerCompletionItemOptions( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -5831,8 +5776,34 @@ bool _canParseServerCapabilitiesWorkspace( return false; } if ((!nullCheck || value != null) && - !ServerCapabilitiesWorkspace.canParse(value, reporter)) { - reporter.reportError('must be of type ServerCapabilitiesWorkspace'); + !ServerCompletionItemOptions.canParse(value, reporter)) { + reporter.reportError('must be of type ServerCompletionItemOptions'); + return false; + } + } finally { + reporter.pop(); + } + return true; +} + +bool _canParseServerInfo( + Map map, LspJsonReporter reporter, String fieldName, + {required bool allowsUndefined, required bool allowsNull}) { + reporter.push(fieldName); + try { + if (!allowsUndefined && !map.containsKey(fieldName)) { + reporter.reportError('must not be undefined'); + return false; + } + final value = map[fieldName]; + final nullCheck = allowsNull || allowsUndefined; + if (!nullCheck && value == null) { + reporter.reportError('must not be null'); + return false; + } + if ((!nullCheck || value != null) && + !ServerInfo.canParse(value, reporter)) { + reporter.reportError('must be of type ServerInfo'); return false; } } finally { @@ -6395,7 +6366,7 @@ bool _canParseTextEdit( return true; } -bool _canParseTraceValues( +bool _canParseTraceValue( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { reporter.push(fieldName); @@ -6411,8 +6382,8 @@ bool _canParseTraceValues( return false; } if ((!nullCheck || value != null) && - !TraceValues.canParse(value, reporter)) { - reporter.reportError('must be of type TraceValues'); + !TraceValue.canParse(value, reporter)) { + reporter.reportError('must be of type TraceValue'); return false; } } finally { @@ -6867,6 +6838,32 @@ bool _canParseWorkspaceFoldersServerCapabilities( return true; } +bool _canParseWorkspaceOptions( + Map map, LspJsonReporter reporter, String fieldName, + {required bool allowsUndefined, required bool allowsNull}) { + reporter.push(fieldName); + try { + if (!allowsUndefined && !map.containsKey(fieldName)) { + reporter.reportError('must not be undefined'); + return false; + } + final value = map[fieldName]; + final nullCheck = allowsNull || allowsUndefined; + if (!nullCheck && value == null) { + reporter.reportError('must not be null'); + return false; + } + if ((!nullCheck || value != null) && + !WorkspaceOptions.canParse(value, reporter)) { + reporter.reportError('must be of type WorkspaceOptions'); + return false; + } + } finally { + reporter.pop(); + } + return true; +} + bool _canParseWorkspaceSymbolClientCapabilities( Map map, LspJsonReporter reporter, String fieldName, {required bool allowsUndefined, required bool allowsNull}) { @@ -7239,14 +7236,14 @@ Either2 : throw '$value was not one of (bool, SemanticTokensClientCapabilitiesRequestsRange)'; } -Either2 _eitherBoolSemanticTokensOptionsFull( +Either2 _eitherBoolSemanticTokensFullDelta( Object? value) { return value is bool ? Either2.t1(value) - : SemanticTokensOptionsFull.canParse(value, nullLspJsonReporter) + : SemanticTokensFullDelta.canParse(value, nullLspJsonReporter) ? Either2.t2( - SemanticTokensOptionsFull.fromJson(value as Map)) - : throw '$value was not one of (bool, SemanticTokensOptionsFull)'; + SemanticTokensFullDelta.fromJson(value as Map)) + : throw '$value was not one of (bool, SemanticTokensFullDelta)'; } Either2 _eitherBoolSemanticTokensOptionsRange( @@ -7307,16 +7304,6 @@ Either2 _eitherBoolWorkspaceSymbolOptions( : throw '$value was not one of (bool, WorkspaceSymbolOptions)'; } -Either2 _eitherCompletionItemEditRangeRange( - Object? value) { - return CompletionItemEditRange.canParse(value, nullLspJsonReporter) - ? Either2.t1( - CompletionItemEditRange.fromJson(value as Map)) - : Range.canParse(value, nullLspJsonReporter) - ? Either2.t2(Range.fromJson(value as Map)) - : throw '$value was not one of (CompletionItemEditRange, Range)'; -} - Either4 _eitherCreateFileDeleteFileRenameFileTextDocumentEdit(Object? value) { return CreateFile.canParse(value, nullLspJsonReporter) @@ -7341,6 +7328,16 @@ Either2 : throw '$value was not one of (DiagnosticOptions, DiagnosticRegistrationOptions)'; } +Either2 + _eitherEditRangeWithInsertReplaceRange(Object? value) { + return EditRangeWithInsertReplace.canParse(value, nullLspJsonReporter) + ? Either2.t1( + EditRangeWithInsertReplace.fromJson(value as Map)) + : Range.canParse(value, nullLspJsonReporter) + ? Either2.t2(Range.fromJson(value as Map)) + : throw '$value was not one of (EditRangeWithInsertReplace, Range)'; +} + Either2 _eitherFullDocumentDiagnosticReportUnchangedDocumentDiagnosticReport( Object? value) { @@ -7481,16 +7478,18 @@ Either2 _eitherStringRelativePattern( : throw '$value was not one of (LspPattern, RelativePattern)'; } -Either2 - _eitherTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( +Either2 + _eitherTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( Object? value) { - return TextDocumentContentChangeEvent1.canParse(value, nullLspJsonReporter) - ? Either2.t1(TextDocumentContentChangeEvent1.fromJson( + return TextDocumentContentChangePartial.canParse(value, nullLspJsonReporter) + ? Either2.t1(TextDocumentContentChangePartial.fromJson( value as Map)) - : TextDocumentContentChangeEvent2.canParse(value, nullLspJsonReporter) - ? Either2.t2(TextDocumentContentChangeEvent2.fromJson( + : TextDocumentContentChangeWholeDocument.canParse( + value, nullLspJsonReporter) + ? Either2.t2(TextDocumentContentChangeWholeDocument.fromJson( value as Map)) - : throw '$value was not one of (TextDocumentContentChangeEvent1, TextDocumentContentChangeEvent2)'; + : throw '$value was not one of (TextDocumentContentChangePartial, TextDocumentContentChangeWholeDocument)'; } Either2 @@ -7541,6 +7540,8 @@ typedef CallHierarchyOutgoingCallsResult = List?; /// An identifier to refer to a change annotation stored with a workspace edit. typedef ChangeAnnotationIdentifier = String; +typedef CodeActionLiteralSupportCodeActionKind = ClientCodeActionKindOptions; + /// The declaration of a symbol representation as one or many [Location]. typedef Declaration = Either2, Location>; @@ -7589,7 +7590,7 @@ typedef DocumentFilter /// 'json', pattern: '**∕tsconfig.json' }]`; /// /// The use of a string as a document filter is deprecated @since 3.16.0. -typedef DocumentSelector = List; +typedef DocumentSelector = List; /// The glob pattern. Either a string pattern or a relative pattern. /// @@ -7634,7 +7635,7 @@ typedef NotebookDocumentFilter = Either3; typedef PrepareRenameResult - = Either3; + = Either3; typedef ProgressToken = Either2; @@ -7661,8 +7662,11 @@ typedef TextDocumentCompletionResult /// An event describing a change to a text document. If only a text is provided /// it is considered to be the full content of the document. -typedef TextDocumentContentChangeEvent - = Either2; +typedef TextDocumentContentChangeEvent = Either2< + TextDocumentContentChangePartial, TextDocumentContentChangeWholeDocument>; + +typedef TextDocumentContentChangeEvent2 + = TextDocumentContentChangeWholeDocument; /// Result for a request to resolve the type definition locations of a symbol at /// a given text document position. The request's parameter is of type @@ -7716,7 +7720,7 @@ typedef TextDocumentDocumentSymbolResult /// /// @since 3.17.0 typedef TextDocumentFilter = Either3; + TextDocumentFilterScheme, TextDocumentFilter3>; /// Result for a request to provide folding ranges in a document. The request's /// parameter is of type [FoldingRangeParams], the response is of type @@ -8979,7 +8983,7 @@ class CallHierarchyRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -9028,7 +9032,7 @@ class CallHierarchyRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -9049,7 +9053,7 @@ class CallHierarchyRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -9356,6 +9360,274 @@ class ClientCapabilities implements ToJsonable { } } +class ClientCodeActionKindOptions implements ToJsonable { + static const jsonHandler = LspJsonHandler( + ClientCodeActionKindOptions.canParse, + ClientCodeActionKindOptions.fromJson, + ); + + /// The code action kind values the client supports. When this property exists + /// the client also guarantees that it will handle values outside its set + /// gracefully and falls back to a default value when unknown. + final List valueSet; + + ClientCodeActionKindOptions({ + required this.valueSet, + }); + + @override + int get hashCode => lspHashCode(valueSet); + + @override + bool operator ==(Object other) { + return other is ClientCodeActionKindOptions && + other.runtimeType == ClientCodeActionKindOptions && + const DeepCollectionEquality().equals(valueSet, other.valueSet); + } + + @override + Map toJson() { + var result = {}; + result['valueSet'] = valueSet.map((item) => item.toJson()).toList(); + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + return _canParseListCodeActionKind(obj, reporter, 'valueSet', + allowsUndefined: false, allowsNull: false); + } else { + reporter.reportError('must be of type ClientCodeActionKindOptions'); + return false; + } + } + + static ClientCodeActionKindOptions fromJson(Map json) { + final valueSetJson = json['valueSet']; + final valueSet = (valueSetJson as List) + .map((item) => CodeActionKind.fromJson(item as String)) + .toList(); + return ClientCodeActionKindOptions( + valueSet: valueSet, + ); + } +} + +class ClientCompletionItemOptionsKind implements ToJsonable { + static const jsonHandler = LspJsonHandler( + ClientCompletionItemOptionsKind.canParse, + ClientCompletionItemOptionsKind.fromJson, + ); + + /// The completion item kind values the client supports. When this property + /// exists the client also guarantees that it will handle values outside its + /// set gracefully and falls back to a default value when unknown. + /// + /// If this property is not present the client only supports the completion + /// items kinds from `Text` to `Reference` as defined in the initial version + /// of the protocol. + final List? valueSet; + + ClientCompletionItemOptionsKind({ + this.valueSet, + }); + + @override + int get hashCode => lspHashCode(valueSet); + + @override + bool operator ==(Object other) { + return other is ClientCompletionItemOptionsKind && + other.runtimeType == ClientCompletionItemOptionsKind && + const DeepCollectionEquality().equals(valueSet, other.valueSet); + } + + @override + Map toJson() { + var result = {}; + if (valueSet != null) { + result['valueSet'] = valueSet?.map((item) => item.toJson()).toList(); + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + return _canParseListCompletionItemKind(obj, reporter, 'valueSet', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type ClientCompletionItemOptionsKind'); + return false; + } + } + + static ClientCompletionItemOptionsKind fromJson(Map json) { + final valueSetJson = json['valueSet']; + final valueSet = (valueSetJson as List?) + ?.map((item) => CompletionItemKind.fromJson(item as int)) + .toList(); + return ClientCompletionItemOptionsKind( + valueSet: valueSet, + ); + } +} + +class ClientInfo implements ToJsonable { + static const jsonHandler = LspJsonHandler( + ClientInfo.canParse, + ClientInfo.fromJson, + ); + + /// The name of the client as defined by the client. + final String name; + + /// The client's version as defined by the client. + final String? version; + + ClientInfo({ + required this.name, + this.version, + }); + @override + int get hashCode => Object.hash( + name, + version, + ); + + @override + bool operator ==(Object other) { + return other is ClientInfo && + other.runtimeType == ClientInfo && + name == other.name && + version == other.version; + } + + @override + Map toJson() { + var result = {}; + result['name'] = name; + if (version != null) { + result['version'] = version; + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParseString(obj, reporter, 'name', + allowsUndefined: false, allowsNull: false)) { + return false; + } + return _canParseString(obj, reporter, 'version', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type ClientInfo'); + return false; + } + } + + static ClientInfo fromJson(Map json) { + final nameJson = json['name']; + final name = nameJson as String; + final versionJson = json['version']; + final version = versionJson as String?; + return ClientInfo( + name: name, + version: version, + ); + } +} + +class ClientSemanticTokensRequestOptions implements ToJsonable { + static const jsonHandler = LspJsonHandler( + ClientSemanticTokensRequestOptions.canParse, + ClientSemanticTokensRequestOptions.fromJson, + ); + + /// The client will send the `textDocument/semanticTokens/full` request if the + /// server provides a corresponding handler. + final Either2? full; + + /// The client will send the `textDocument/semanticTokens/range` request if + /// the server provides a corresponding handler. + final Either2? range; + + ClientSemanticTokensRequestOptions({ + this.full, + this.range, + }); + @override + int get hashCode => Object.hash( + full, + range, + ); + + @override + bool operator ==(Object other) { + return other is ClientSemanticTokensRequestOptions && + other.runtimeType == ClientSemanticTokensRequestOptions && + full == other.full && + range == other.range; + } + + @override + Map toJson() { + var result = {}; + if (full != null) { + result['full'] = full; + } + if (range != null) { + result['range'] = range; + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParseBoolSemanticTokensClientCapabilitiesRequestsFull( + obj, reporter, 'full', + allowsUndefined: true, allowsNull: false)) { + return false; + } + return _canParseBoolSemanticTokensClientCapabilitiesRequestsRange( + obj, reporter, 'range', + allowsUndefined: true, allowsNull: false); + } else { + reporter + .reportError('must be of type ClientSemanticTokensRequestOptions'); + return false; + } + } + + static ClientSemanticTokensRequestOptions fromJson( + Map json) { + final fullJson = json['full']; + final full = fullJson == null + ? null + : _eitherBoolSemanticTokensClientCapabilitiesRequestsFull(fullJson); + final rangeJson = json['range']; + final range = rangeJson == null + ? null + : _eitherBoolSemanticTokensClientCapabilitiesRequestsRange(rangeJson); + return ClientSemanticTokensRequestOptions( + full: full, + range: range, + ); + } +} + /// A code action represents a change that can be performed in code, e.g. to fix /// a problem or to refactor code. /// @@ -9750,7 +10022,7 @@ class CodeActionClientCapabilitiesCodeActionLiteralSupport ); /// The code action kind is support with the following value set. - final CodeActionLiteralSupportCodeActionKind codeActionKind; + final ClientCodeActionKindOptions codeActionKind; CodeActionClientCapabilitiesCodeActionLiteralSupport({ required this.codeActionKind, @@ -9779,7 +10051,7 @@ class CodeActionClientCapabilitiesCodeActionLiteralSupport static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - return _canParseCodeActionLiteralSupportCodeActionKind( + return _canParseClientCodeActionKindOptions( obj, reporter, 'codeActionKind', allowsUndefined: false, allowsNull: false); } else { @@ -9792,7 +10064,7 @@ class CodeActionClientCapabilitiesCodeActionLiteralSupport static CodeActionClientCapabilitiesCodeActionLiteralSupport fromJson( Map json) { final codeActionKindJson = json['codeActionKind']; - final codeActionKind = CodeActionLiteralSupportCodeActionKind.fromJson( + final codeActionKind = ClientCodeActionKindOptions.fromJson( codeActionKindJson as Map); return CodeActionClientCapabilitiesCodeActionLiteralSupport( codeActionKind: codeActionKind, @@ -10091,64 +10363,6 @@ class CodeActionKind implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) => obj is String; } -class CodeActionLiteralSupportCodeActionKind implements ToJsonable { - static const jsonHandler = LspJsonHandler( - CodeActionLiteralSupportCodeActionKind.canParse, - CodeActionLiteralSupportCodeActionKind.fromJson, - ); - - /// The code action kind values the client supports. When this property exists - /// the client also guarantees that it will handle values outside its set - /// gracefully and falls back to a default value when unknown. - final List valueSet; - - CodeActionLiteralSupportCodeActionKind({ - required this.valueSet, - }); - - @override - int get hashCode => lspHashCode(valueSet); - - @override - bool operator ==(Object other) { - return other is CodeActionLiteralSupportCodeActionKind && - other.runtimeType == CodeActionLiteralSupportCodeActionKind && - const DeepCollectionEquality().equals(valueSet, other.valueSet); - } - - @override - Map toJson() { - var result = {}; - result['valueSet'] = valueSet.map((item) => item.toJson()).toList(); - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - return _canParseListCodeActionKind(obj, reporter, 'valueSet', - allowsUndefined: false, allowsNull: false); - } else { - reporter.reportError( - 'must be of type CodeActionLiteralSupportCodeActionKind'); - return false; - } - } - - static CodeActionLiteralSupportCodeActionKind fromJson( - Map json) { - final valueSetJson = json['valueSet']; - final valueSet = (valueSetJson as List) - .map((item) => CodeActionKind.fromJson(item as String)) - .toList(); - return CodeActionLiteralSupportCodeActionKind( - valueSet: valueSet, - ); - } -} - /// Provider options for a [CodeActionRequest]. class CodeActionOptions implements WorkDoneProgressOptions, ToJsonable { static const jsonHandler = LspJsonHandler( @@ -10389,7 +10603,7 @@ class CodeActionRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The server provides support to resolve additional information for a code /// action. @@ -10451,7 +10665,7 @@ class CodeActionRegistrationOptions allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -10476,7 +10690,7 @@ class CodeActionRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final resolveProviderJson = json['resolveProvider']; final resolveProvider = resolveProviderJson as bool?; @@ -10903,7 +11117,7 @@ class CodeLensRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// Code lens has a resolve provider as well. @override @@ -10951,7 +11165,7 @@ class CodeLensRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -10972,7 +11186,7 @@ class CodeLensRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final resolveProviderJson = json['resolveProvider']; final resolveProvider = resolveProviderJson as bool?; @@ -11526,7 +11740,7 @@ class CompletionClientCapabilities implements ToJsonable { /// The client supports the following `CompletionItem` specific capabilities. final CompletionClientCapabilitiesCompletionItem? completionItem; - final CompletionClientCapabilitiesCompletionItemKind? completionItemKind; + final ClientCompletionItemOptionsKind? completionItemKind; /// The client supports the following `CompletionList` specific capabilities. /// @@ -11610,7 +11824,7 @@ class CompletionClientCapabilities implements ToJsonable { allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseCompletionClientCapabilitiesCompletionItemKind( + if (!_canParseClientCompletionItemOptionsKind( obj, reporter, 'completionItemKind', allowsUndefined: true, allowsNull: false)) { return false; @@ -11644,7 +11858,7 @@ class CompletionClientCapabilities implements ToJsonable { : null; final completionItemKindJson = json['completionItemKind']; final completionItemKind = completionItemKindJson != null - ? CompletionClientCapabilitiesCompletionItemKind.fromJson( + ? ClientCompletionItemOptionsKind.fromJson( completionItemKindJson as Map) : null; final completionListJson = json['completionList']; @@ -11911,70 +12125,6 @@ class CompletionClientCapabilitiesCompletionItem implements ToJsonable { } } -class CompletionClientCapabilitiesCompletionItemKind implements ToJsonable { - static const jsonHandler = LspJsonHandler( - CompletionClientCapabilitiesCompletionItemKind.canParse, - CompletionClientCapabilitiesCompletionItemKind.fromJson, - ); - - /// The completion item kind values the client supports. When this property - /// exists the client also guarantees that it will handle values outside its - /// set gracefully and falls back to a default value when unknown. - /// - /// If this property is not present the client only supports the completion - /// items kinds from `Text` to `Reference` as defined in the initial version - /// of the protocol. - final List? valueSet; - - CompletionClientCapabilitiesCompletionItemKind({ - this.valueSet, - }); - - @override - int get hashCode => lspHashCode(valueSet); - - @override - bool operator ==(Object other) { - return other is CompletionClientCapabilitiesCompletionItemKind && - other.runtimeType == CompletionClientCapabilitiesCompletionItemKind && - const DeepCollectionEquality().equals(valueSet, other.valueSet); - } - - @override - Map toJson() { - var result = {}; - if (valueSet != null) { - result['valueSet'] = valueSet?.map((item) => item.toJson()).toList(); - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - return _canParseListCompletionItemKind(obj, reporter, 'valueSet', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError( - 'must be of type CompletionClientCapabilitiesCompletionItemKind'); - return false; - } - } - - static CompletionClientCapabilitiesCompletionItemKind fromJson( - Map json) { - final valueSetJson = json['valueSet']; - final valueSet = (valueSetJson as List?) - ?.map((item) => CompletionItemKind.fromJson(item as int)) - .toList(); - return CompletionClientCapabilitiesCompletionItemKind( - valueSet: valueSet, - ); - } -} - class CompletionClientCapabilitiesCompletionList implements ToJsonable { static const jsonHandler = LspJsonHandler( CompletionClientCapabilitiesCompletionList.canParse, @@ -12555,39 +12705,82 @@ class CompletionItem implements ToJsonable { } } -class CompletionItemEditRange implements ToJsonable { +class CompletionItemDefaults implements ToJsonable { static const jsonHandler = LspJsonHandler( - CompletionItemEditRange.canParse, - CompletionItemEditRange.fromJson, + CompletionItemDefaults.canParse, + CompletionItemDefaults.fromJson, ); - final Range insert; + /// A default commit character set. + /// + /// @since 3.17.0 + final List? commitCharacters; - final Range replace; + /// A default data value. + /// + /// @since 3.17.0 + final LSPAny data; - CompletionItemEditRange({ - required this.insert, - required this.replace, + /// A default edit range. + /// + /// @since 3.17.0 + final Either2? editRange; + + /// A default insert text format. + /// + /// @since 3.17.0 + final InsertTextFormat? insertTextFormat; + + /// A default insert text mode. + /// + /// @since 3.17.0 + final InsertTextMode? insertTextMode; + CompletionItemDefaults({ + this.commitCharacters, + this.data, + this.editRange, + this.insertTextFormat, + this.insertTextMode, }); @override int get hashCode => Object.hash( - insert, - replace, + lspHashCode(commitCharacters), + data, + editRange, + insertTextFormat, + insertTextMode, ); @override bool operator ==(Object other) { - return other is CompletionItemEditRange && - other.runtimeType == CompletionItemEditRange && - insert == other.insert && - replace == other.replace; + return other is CompletionItemDefaults && + other.runtimeType == CompletionItemDefaults && + const DeepCollectionEquality() + .equals(commitCharacters, other.commitCharacters) && + data == other.data && + editRange == other.editRange && + insertTextFormat == other.insertTextFormat && + insertTextMode == other.insertTextMode; } @override Map toJson() { var result = {}; - result['insert'] = insert.toJson(); - result['replace'] = replace.toJson(); + if (commitCharacters != null) { + result['commitCharacters'] = commitCharacters; + } + if (data != null) { + result['data'] = data; + } + if (editRange != null) { + result['editRange'] = editRange; + } + if (insertTextFormat != null) { + result['insertTextFormat'] = insertTextFormat?.toJson(); + } + if (insertTextMode != null) { + result['insertTextMode'] = insertTextMode?.toJson(); + } return result; } @@ -12596,26 +12789,51 @@ class CompletionItemEditRange implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseRange(obj, reporter, 'insert', - allowsUndefined: false, allowsNull: false)) { + if (!_canParseListString(obj, reporter, 'commitCharacters', + allowsUndefined: true, allowsNull: false)) { return false; } - return _canParseRange(obj, reporter, 'replace', - allowsUndefined: false, allowsNull: false); + if (!_canParseEditRangeWithInsertReplaceRange(obj, reporter, 'editRange', + allowsUndefined: true, allowsNull: false)) { + return false; + } + if (!_canParseInsertTextFormat(obj, reporter, 'insertTextFormat', + allowsUndefined: true, allowsNull: false)) { + return false; + } + return _canParseInsertTextMode(obj, reporter, 'insertTextMode', + allowsUndefined: true, allowsNull: false); } else { - reporter.reportError('must be of type CompletionItemEditRange'); + reporter.reportError('must be of type CompletionItemDefaults'); return false; } } - static CompletionItemEditRange fromJson(Map json) { - final insertJson = json['insert']; - final insert = Range.fromJson(insertJson as Map); - final replaceJson = json['replace']; - final replace = Range.fromJson(replaceJson as Map); - return CompletionItemEditRange( - insert: insert, - replace: replace, + static CompletionItemDefaults fromJson(Map json) { + final commitCharactersJson = json['commitCharacters']; + final commitCharacters = (commitCharactersJson as List?) + ?.map((item) => item as String) + .toList(); + final dataJson = json['data']; + final data = dataJson; + final editRangeJson = json['editRange']; + final editRange = editRangeJson == null + ? null + : _eitherEditRangeWithInsertReplaceRange(editRangeJson); + final insertTextFormatJson = json['insertTextFormat']; + final insertTextFormat = insertTextFormatJson != null + ? InsertTextFormat.fromJson(insertTextFormatJson as int) + : null; + final insertTextModeJson = json['insertTextMode']; + final insertTextMode = insertTextModeJson != null + ? InsertTextMode.fromJson(insertTextModeJson as int) + : null; + return CompletionItemDefaults( + commitCharacters: commitCharacters, + data: data, + editRange: editRange, + insertTextFormat: insertTextFormat, + insertTextMode: insertTextMode, ); } } @@ -12964,7 +13182,7 @@ class CompletionList implements ToJsonable { /// support for this via the `completionList.itemDefaults` capability. /// /// @since 3.17.0 - final CompletionListItemDefaults? itemDefaults; + final CompletionItemDefaults? itemDefaults; /// The completion items. final List items; @@ -13009,7 +13227,7 @@ class CompletionList implements ToJsonable { allowsUndefined: false, allowsNull: false)) { return false; } - if (!_canParseCompletionListItemDefaults(obj, reporter, 'itemDefaults', + if (!_canParseCompletionItemDefaults(obj, reporter, 'itemDefaults', allowsUndefined: true, allowsNull: false)) { return false; } @@ -13026,7 +13244,7 @@ class CompletionList implements ToJsonable { final isIncomplete = isIncompleteJson as bool; final itemDefaultsJson = json['itemDefaults']; final itemDefaults = itemDefaultsJson != null - ? CompletionListItemDefaults.fromJson( + ? CompletionItemDefaults.fromJson( itemDefaultsJson as Map) : null; final itemsJson = json['items']; @@ -13041,139 +13259,6 @@ class CompletionList implements ToJsonable { } } -class CompletionListItemDefaults implements ToJsonable { - static const jsonHandler = LspJsonHandler( - CompletionListItemDefaults.canParse, - CompletionListItemDefaults.fromJson, - ); - - /// A default commit character set. - /// - /// @since 3.17.0 - final List? commitCharacters; - - /// A default data value. - /// - /// @since 3.17.0 - final LSPAny data; - - /// A default edit range. - /// - /// @since 3.17.0 - final Either2? editRange; - - /// A default insert text format. - /// - /// @since 3.17.0 - final InsertTextFormat? insertTextFormat; - - /// A default insert text mode. - /// - /// @since 3.17.0 - final InsertTextMode? insertTextMode; - CompletionListItemDefaults({ - this.commitCharacters, - this.data, - this.editRange, - this.insertTextFormat, - this.insertTextMode, - }); - @override - int get hashCode => Object.hash( - lspHashCode(commitCharacters), - data, - editRange, - insertTextFormat, - insertTextMode, - ); - - @override - bool operator ==(Object other) { - return other is CompletionListItemDefaults && - other.runtimeType == CompletionListItemDefaults && - const DeepCollectionEquality() - .equals(commitCharacters, other.commitCharacters) && - data == other.data && - editRange == other.editRange && - insertTextFormat == other.insertTextFormat && - insertTextMode == other.insertTextMode; - } - - @override - Map toJson() { - var result = {}; - if (commitCharacters != null) { - result['commitCharacters'] = commitCharacters; - } - if (data != null) { - result['data'] = data; - } - if (editRange != null) { - result['editRange'] = editRange; - } - if (insertTextFormat != null) { - result['insertTextFormat'] = insertTextFormat?.toJson(); - } - if (insertTextMode != null) { - result['insertTextMode'] = insertTextMode?.toJson(); - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParseListString(obj, reporter, 'commitCharacters', - allowsUndefined: true, allowsNull: false)) { - return false; - } - if (!_canParseCompletionItemEditRangeRange(obj, reporter, 'editRange', - allowsUndefined: true, allowsNull: false)) { - return false; - } - if (!_canParseInsertTextFormat(obj, reporter, 'insertTextFormat', - allowsUndefined: true, allowsNull: false)) { - return false; - } - return _canParseInsertTextMode(obj, reporter, 'insertTextMode', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type CompletionListItemDefaults'); - return false; - } - } - - static CompletionListItemDefaults fromJson(Map json) { - final commitCharactersJson = json['commitCharacters']; - final commitCharacters = (commitCharactersJson as List?) - ?.map((item) => item as String) - .toList(); - final dataJson = json['data']; - final data = dataJson; - final editRangeJson = json['editRange']; - final editRange = editRangeJson == null - ? null - : _eitherCompletionItemEditRangeRange(editRangeJson); - final insertTextFormatJson = json['insertTextFormat']; - final insertTextFormat = insertTextFormatJson != null - ? InsertTextFormat.fromJson(insertTextFormatJson as int) - : null; - final insertTextModeJson = json['insertTextMode']; - final insertTextMode = insertTextModeJson != null - ? InsertTextMode.fromJson(insertTextModeJson as int) - : null; - return CompletionListItemDefaults( - commitCharacters: commitCharacters, - data: data, - editRange: editRange, - insertTextFormat: insertTextFormat, - insertTextMode: insertTextMode, - ); - } -} - /// Completion options. class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { static const jsonHandler = LspJsonHandler( @@ -13195,7 +13280,7 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { /// The server supports the following `CompletionItem` specific capabilities. /// /// @since 3.17.0 - final CompletionOptionsCompletionItem? completionItem; + final ServerCompletionItemOptions? completionItem; /// The server provides support to resolve additional information for a /// completion item. @@ -13273,8 +13358,7 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseCompletionOptionsCompletionItem( - obj, reporter, 'completionItem', + if (!_canParseServerCompletionItemOptions(obj, reporter, 'completionItem', allowsUndefined: true, allowsNull: false)) { return false; } @@ -13304,7 +13388,7 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { .toList(); final completionItemJson = json['completionItem']; final completionItem = completionItemJson != null - ? CompletionOptionsCompletionItem.fromJson( + ? ServerCompletionItemOptions.fromJson( completionItemJson as Map) : null; final resolveProviderJson = json['resolveProvider']; @@ -13325,64 +13409,6 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { } } -class CompletionOptionsCompletionItem implements ToJsonable { - static const jsonHandler = LspJsonHandler( - CompletionOptionsCompletionItem.canParse, - CompletionOptionsCompletionItem.fromJson, - ); - - /// The server has support for completion item label details (see also - /// `CompletionItemLabelDetails`) when receiving a completion item in a - /// resolve call. - /// - /// @since 3.17.0 - final bool? labelDetailsSupport; - - CompletionOptionsCompletionItem({ - this.labelDetailsSupport, - }); - - @override - int get hashCode => labelDetailsSupport.hashCode; - - @override - bool operator ==(Object other) { - return other is CompletionOptionsCompletionItem && - other.runtimeType == CompletionOptionsCompletionItem && - labelDetailsSupport == other.labelDetailsSupport; - } - - @override - Map toJson() { - var result = {}; - if (labelDetailsSupport != null) { - result['labelDetailsSupport'] = labelDetailsSupport; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - return _canParseBool(obj, reporter, 'labelDetailsSupport', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type CompletionOptionsCompletionItem'); - return false; - } - } - - static CompletionOptionsCompletionItem fromJson(Map json) { - final labelDetailsSupportJson = json['labelDetailsSupport']; - final labelDetailsSupport = labelDetailsSupportJson as bool?; - return CompletionOptionsCompletionItem( - labelDetailsSupport: labelDetailsSupport, - ); - } -} - /// Completion parameters class CompletionParams implements @@ -13540,12 +13566,12 @@ class CompletionRegistrationOptions /// /// @since 3.17.0 @override - final CompletionOptionsCompletionItem? completionItem; + final ServerCompletionItemOptions? completionItem; /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The server provides support to resolve additional information for a /// completion item. @@ -13630,12 +13656,11 @@ class CompletionRegistrationOptions allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseCompletionOptionsCompletionItem( - obj, reporter, 'completionItem', + if (!_canParseServerCompletionItemOptions(obj, reporter, 'completionItem', allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -13663,13 +13688,13 @@ class CompletionRegistrationOptions .toList(); final completionItemJson = json['completionItem']; final completionItem = completionItemJson != null - ? CompletionOptionsCompletionItem.fromJson( + ? ServerCompletionItemOptions.fromJson( completionItemJson as Map) : null; final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final resolveProviderJson = json['resolveProvider']; final resolveProvider = resolveProviderJson as bool?; @@ -14352,7 +14377,7 @@ class DeclarationRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -14401,7 +14426,7 @@ class DeclarationRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -14422,7 +14447,7 @@ class DeclarationRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -14692,7 +14717,7 @@ class DefinitionRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -14731,7 +14756,7 @@ class DefinitionRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -14748,7 +14773,7 @@ class DefinitionRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -15401,7 +15426,7 @@ class DiagnosticRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -15479,7 +15504,7 @@ class DiagnosticRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -15512,7 +15537,7 @@ class DiagnosticRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -16048,7 +16073,7 @@ class DidChangeTextDocumentParams implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( + if (!_canParseListTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( obj, reporter, 'contentChanges', allowsUndefined: false, allowsNull: false)) { return false; @@ -16066,7 +16091,7 @@ class DidChangeTextDocumentParams implements ToJsonable { final contentChangesJson = json['contentChanges']; final contentChanges = (contentChangesJson as List) .map((item) => - _eitherTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( + _eitherTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( item)) .toList(); final textDocumentJson = json['textDocument']; @@ -16933,7 +16958,7 @@ class DocumentColorRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -16982,7 +17007,7 @@ class DocumentColorRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -17003,7 +17028,7 @@ class DocumentColorRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -17457,7 +17482,7 @@ class DocumentFormattingRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -17496,7 +17521,7 @@ class DocumentFormattingRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -17515,7 +17540,7 @@ class DocumentFormattingRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -17873,7 +17898,7 @@ class DocumentHighlightRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -17912,7 +17937,7 @@ class DocumentHighlightRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -17931,7 +17956,7 @@ class DocumentHighlightRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -18304,7 +18329,7 @@ class DocumentLinkRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// Document links have a resolve provider as well. @override @@ -18352,7 +18377,7 @@ class DocumentLinkRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -18373,7 +18398,7 @@ class DocumentLinkRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final resolveProviderJson = json['resolveProvider']; final resolveProvider = resolveProviderJson as bool?; @@ -18637,7 +18662,7 @@ class DocumentOnTypeFormattingRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// A character on which formatting should be triggered, like `{`. @override @@ -18685,7 +18710,7 @@ class DocumentOnTypeFormattingRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -18708,7 +18733,7 @@ class DocumentOnTypeFormattingRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final firstTriggerCharacterJson = json['firstTriggerCharacter']; final firstTriggerCharacter = firstTriggerCharacterJson as String; @@ -18957,7 +18982,7 @@ class DocumentRangeFormattingRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -18996,7 +19021,7 @@ class DocumentRangeFormattingRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -19015,7 +19040,7 @@ class DocumentRangeFormattingRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -19646,7 +19671,7 @@ class DocumentSymbolRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// A human-readable string that is shown when multiple outlines trees are /// shown for the same document. @@ -19697,7 +19722,7 @@ class DocumentSymbolRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -19718,7 +19743,7 @@ class DocumentSymbolRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final labelJson = json['label']; final label = labelJson as String?; @@ -19732,6 +19757,71 @@ class DocumentSymbolRegistrationOptions } } +class EditRangeWithInsertReplace implements ToJsonable { + static const jsonHandler = LspJsonHandler( + EditRangeWithInsertReplace.canParse, + EditRangeWithInsertReplace.fromJson, + ); + + final Range insert; + + final Range replace; + + EditRangeWithInsertReplace({ + required this.insert, + required this.replace, + }); + @override + int get hashCode => Object.hash( + insert, + replace, + ); + + @override + bool operator ==(Object other) { + return other is EditRangeWithInsertReplace && + other.runtimeType == EditRangeWithInsertReplace && + insert == other.insert && + replace == other.replace; + } + + @override + Map toJson() { + var result = {}; + result['insert'] = insert.toJson(); + result['replace'] = replace.toJson(); + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParseRange(obj, reporter, 'insert', + allowsUndefined: false, allowsNull: false)) { + return false; + } + return _canParseRange(obj, reporter, 'replace', + allowsUndefined: false, allowsNull: false); + } else { + reporter.reportError('must be of type EditRangeWithInsertReplace'); + return false; + } + } + + static EditRangeWithInsertReplace fromJson(Map json) { + final insertJson = json['insert']; + final insert = Range.fromJson(insertJson as Map); + final replaceJson = json['replace']; + final replace = Range.fromJson(replaceJson as Map); + return EditRangeWithInsertReplace( + insert: insert, + replace: replace, + ); + } +} + /// Predefined error codes. class ErrorCodes implements ToJsonable { /// The server detected that the content of a document got modified outside @@ -21783,7 +21873,7 @@ class FoldingRangeRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -21832,7 +21922,7 @@ class FoldingRangeRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -21853,7 +21943,7 @@ class FoldingRangeRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -22611,7 +22701,7 @@ class HoverRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -22650,7 +22740,7 @@ class HoverRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -22667,7 +22757,7 @@ class HoverRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -22937,7 +23027,7 @@ class ImplementationRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -22986,7 +23076,7 @@ class ImplementationRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -23007,7 +23097,7 @@ class ImplementationRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -23068,7 +23158,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { /// Information about the client /// /// @since 3.15.0 - final InitializeParamsClientInfo? clientInfo; + final ClientInfo? clientInfo; /// User provided initialization options. final LSPAny initializationOptions; @@ -23100,7 +23190,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { final DocumentUri? rootUri; /// The initial trace setting. If omitted trace is disabled ('off'). - final TraceValues? trace; + final TraceValue? trace; /// An optional token that a server can use to report work done progress. @override @@ -23197,7 +23287,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { allowsUndefined: false, allowsNull: false)) { return false; } - if (!_canParseInitializeParamsClientInfo(obj, reporter, 'clientInfo', + if (!_canParseClientInfo(obj, reporter, 'clientInfo', allowsUndefined: true, allowsNull: false)) { return false; } @@ -23217,7 +23307,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { allowsUndefined: false, allowsNull: true)) { return false; } - if (!_canParseTraceValues(obj, reporter, 'trace', + if (!_canParseTraceValue(obj, reporter, 'trace', allowsUndefined: true, allowsNull: false)) { return false; } @@ -23239,8 +23329,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { ClientCapabilities.fromJson(capabilitiesJson as Map); final clientInfoJson = json['clientInfo']; final clientInfo = clientInfoJson != null - ? InitializeParamsClientInfo.fromJson( - clientInfoJson as Map) + ? ClientInfo.fromJson(clientInfoJson as Map) : null; final initializationOptionsJson = json['initializationOptions']; final initializationOptions = initializationOptionsJson; @@ -23255,7 +23344,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { rootUriJson != null ? Uri.parse(rootUriJson as String) : null; final traceJson = json['trace']; final trace = - traceJson != null ? TraceValues.fromJson(traceJson as String) : null; + traceJson != null ? TraceValue.fromJson(traceJson as String) : null; final workDoneTokenJson = json['workDoneToken']; final workDoneToken = workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson); @@ -23278,75 +23367,6 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { } } -class InitializeParamsClientInfo implements ToJsonable { - static const jsonHandler = LspJsonHandler( - InitializeParamsClientInfo.canParse, - InitializeParamsClientInfo.fromJson, - ); - - /// The name of the client as defined by the client. - final String name; - - /// The client's version as defined by the client. - final String? version; - - InitializeParamsClientInfo({ - required this.name, - this.version, - }); - @override - int get hashCode => Object.hash( - name, - version, - ); - - @override - bool operator ==(Object other) { - return other is InitializeParamsClientInfo && - other.runtimeType == InitializeParamsClientInfo && - name == other.name && - version == other.version; - } - - @override - Map toJson() { - var result = {}; - result['name'] = name; - if (version != null) { - result['version'] = version; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParseString(obj, reporter, 'name', - allowsUndefined: false, allowsNull: false)) { - return false; - } - return _canParseString(obj, reporter, 'version', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type InitializeParamsClientInfo'); - return false; - } - } - - static InitializeParamsClientInfo fromJson(Map json) { - final nameJson = json['name']; - final name = nameJson as String; - final versionJson = json['version']; - final version = versionJson as String?; - return InitializeParamsClientInfo( - name: name, - version: version, - ); - } -} - /// The result returned from an initialize request. class InitializeResult implements ToJsonable { static const jsonHandler = LspJsonHandler( @@ -23360,7 +23380,7 @@ class InitializeResult implements ToJsonable { /// Information about the server. /// /// @since 3.15.0 - final InitializeResultServerInfo? serverInfo; + final ServerInfo? serverInfo; InitializeResult({ required this.capabilities, @@ -23399,7 +23419,7 @@ class InitializeResult implements ToJsonable { allowsUndefined: false, allowsNull: false)) { return false; } - return _canParseInitializeResultServerInfo(obj, reporter, 'serverInfo', + return _canParseServerInfo(obj, reporter, 'serverInfo', allowsUndefined: true, allowsNull: false); } else { reporter.reportError('must be of type InitializeResult'); @@ -23413,8 +23433,7 @@ class InitializeResult implements ToJsonable { ServerCapabilities.fromJson(capabilitiesJson as Map); final serverInfoJson = json['serverInfo']; final serverInfo = serverInfoJson != null - ? InitializeResultServerInfo.fromJson( - serverInfoJson as Map) + ? ServerInfo.fromJson(serverInfoJson as Map) : null; return InitializeResult( capabilities: capabilities, @@ -23423,75 +23442,6 @@ class InitializeResult implements ToJsonable { } } -class InitializeResultServerInfo implements ToJsonable { - static const jsonHandler = LspJsonHandler( - InitializeResultServerInfo.canParse, - InitializeResultServerInfo.fromJson, - ); - - /// The name of the server as defined by the server. - final String name; - - /// The server's version as defined by the server. - final String? version; - - InitializeResultServerInfo({ - required this.name, - this.version, - }); - @override - int get hashCode => Object.hash( - name, - version, - ); - - @override - bool operator ==(Object other) { - return other is InitializeResultServerInfo && - other.runtimeType == InitializeResultServerInfo && - name == other.name && - version == other.version; - } - - @override - Map toJson() { - var result = {}; - result['name'] = name; - if (version != null) { - result['version'] = version; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParseString(obj, reporter, 'name', - allowsUndefined: false, allowsNull: false)) { - return false; - } - return _canParseString(obj, reporter, 'version', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type InitializeResultServerInfo'); - return false; - } - } - - static InitializeResultServerInfo fromJson(Map json) { - final nameJson = json['name']; - final name = nameJson as String; - final versionJson = json['version']; - final version = versionJson as String?; - return InitializeResultServerInfo( - name: name, - version: version, - ); - } -} - /// Inlay hint information. /// /// @since 3.17.0 @@ -24144,7 +24094,7 @@ class InlayHintRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -24203,7 +24153,7 @@ class InlayHintRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -24228,7 +24178,7 @@ class InlayHintRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -24694,7 +24644,7 @@ class InlineValueRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -24743,7 +24693,7 @@ class InlineValueRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -24764,7 +24714,7 @@ class InlineValueRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -25388,7 +25338,7 @@ class LinkedEditingRangeRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -25437,7 +25387,7 @@ class LinkedEditingRangeRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -25460,7 +25410,7 @@ class LinkedEditingRangeRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -26868,7 +26818,7 @@ class MonikerRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -26907,7 +26857,7 @@ class MonikerRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -26924,7 +26874,7 @@ class MonikerRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -27671,7 +27621,7 @@ class NotebookDocumentChangeEventCellsTextContent implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( + if (!_canParseListTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( obj, reporter, 'changes', allowsUndefined: false, allowsNull: false)) { return false; @@ -27690,7 +27640,7 @@ class NotebookDocumentChangeEventCellsTextContent implements ToJsonable { final changesJson = json['changes']; final changes = (changesJson as List) .map((item) => - _eitherTextDocumentContentChangeEvent1TextDocumentContentChangeEvent2( + _eitherTextDocumentContentChangePartialTextDocumentContentChangeWholeDocument( item)) .toList(); final documentJson = json['document']; @@ -28912,17 +28862,248 @@ class PartialResultParams implements ToJsonable { } } -class PlaceholderAndRange implements ToJsonable { +/// Position in a text document expressed as zero-based line and character +/// offset. Prior to 3.17 the offsets were always based on a UTF-16 string +/// representation. So a string of the form `a𐐀b` the character offset of the +/// character `a` is 0, the character offset of `𐐀` is 1 and the character +/// offset of b is 3 since `𐐀` is represented using two code units in UTF-16. +/// Since 3.17 clients and servers can agree on a different string encoding +/// representation (e.g. UTF-8). The client announces it's supported encoding +/// via the client capability +/// [`general.positionEncodings`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#clientCapabilities). +/// The value is an array of position encodings the client supports, with +/// decreasing preference (e.g. the encoding at index `0` is the most preferred +/// one). To stay backwards compatible the only mandatory encoding is UTF-16 +/// represented via the string `utf-16`. The server can pick one of the +/// encodings offered by the client and signals that encoding back to the client +/// via the initialize result's property +/// [`capabilities.positionEncoding`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#serverCapabilities). +/// If the string value `utf-16` is missing from the client's capability +/// `general.positionEncodings` servers can safely assume that the client +/// supports UTF-16. If the server omits the position encoding in its initialize +/// result the encoding defaults to the string value `utf-16`. Implementation +/// considerations: since the conversion from one encoding into another requires +/// the content of the file / line the conversion is best done where the file is +/// read which is usually on the server side. +/// +/// Positions are line end character agnostic. So you can not specify a position +/// that denotes `\r|\n` or `\n|` where `|` represents the character offset. +/// +/// @since 3.17.0 - support for negotiated position encoding. +class Position implements ToJsonable { + static const jsonHandler = LspJsonHandler( + Position.canParse, + Position.fromJson, + ); + + /// Character offset on a line in a document (zero-based). + /// + /// The meaning of this offset is determined by the negotiated + /// `PositionEncodingKind`. + /// + /// If the character value is greater than the line length it defaults back to + /// the line length. + final int character; + + /// Line position in a document (zero-based). + /// + /// If a line number is greater than the number of lines in a document, it + /// defaults back to the number of lines in the document. If a line number is + /// negative, it defaults to 0. + final int line; + + Position({ + required this.character, + required this.line, + }); + @override + int get hashCode => Object.hash( + character, + line, + ); + + @override + bool operator ==(Object other) { + return other is Position && + other.runtimeType == Position && + character == other.character && + line == other.line; + } + + @override + Map toJson() { + var result = {}; + result['character'] = character; + result['line'] = line; + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParseInt(obj, reporter, 'character', + allowsUndefined: false, allowsNull: false)) { + return false; + } + return _canParseInt(obj, reporter, 'line', + allowsUndefined: false, allowsNull: false); + } else { + reporter.reportError('must be of type Position'); + return false; + } + } + + static Position fromJson(Map json) { + final characterJson = json['character']; + final character = characterJson as int; + final lineJson = json['line']; + final line = lineJson as int; + return Position( + character: character, + line: line, + ); + } +} + +/// A set of predefined position encoding kinds. +/// +/// @since 3.17.0 +class PositionEncodingKind implements ToJsonable { + /// Character offsets count UTF-16 code units. + /// + /// This is the default and must always be supported by servers + static const UTF16 = PositionEncodingKind('utf-16'); + + /// Character offsets count UTF-32 code units. + /// + /// Implementation note: these are the same as Unicode codepoints, + /// so this `PositionEncodingKind` may also be used for an encoding-agnostic + /// representation of character offsets. + static const UTF32 = PositionEncodingKind('utf-32'); + + /// Character offsets count UTF-8 code units (e.g. bytes). + static const UTF8 = PositionEncodingKind('utf-8'); + + final String _value; + const PositionEncodingKind(this._value); + const PositionEncodingKind.fromJson(this._value); + @override + int get hashCode => _value.hashCode; + + @override + bool operator ==(Object other) => + other is PositionEncodingKind && other._value == _value; + + @override + String toJson() => _value; + + @override + String toString() => _value.toString(); + + static bool canParse(Object? obj, LspJsonReporter reporter) => obj is String; +} + +class PrepareRenameParams + implements TextDocumentPositionParams, WorkDoneProgressParams, ToJsonable { + static const jsonHandler = LspJsonHandler( + PrepareRenameParams.canParse, + PrepareRenameParams.fromJson, + ); + + /// The position inside the text document. + @override + final Position position; + + /// The text document. + @override + final TextDocumentIdentifier textDocument; + + /// An optional token that a server can use to report work done progress. + @override + final ProgressToken? workDoneToken; + PrepareRenameParams({ + required this.position, + required this.textDocument, + this.workDoneToken, + }); + @override + int get hashCode => Object.hash( + position, + textDocument, + workDoneToken, + ); + + @override + bool operator ==(Object other) { + return other is PrepareRenameParams && + other.runtimeType == PrepareRenameParams && + position == other.position && + textDocument == other.textDocument && + workDoneToken == other.workDoneToken; + } + + @override + Map toJson() { + var result = {}; + result['position'] = position.toJson(); + result['textDocument'] = textDocument.toJson(); + if (workDoneToken != null) { + result['workDoneToken'] = workDoneToken; + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParsePosition(obj, reporter, 'position', + allowsUndefined: false, allowsNull: false)) { + return false; + } + if (!_canParseTextDocumentIdentifier(obj, reporter, 'textDocument', + allowsUndefined: false, allowsNull: false)) { + return false; + } + return _canParseIntString(obj, reporter, 'workDoneToken', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type PrepareRenameParams'); + return false; + } + } + + static PrepareRenameParams fromJson(Map json) { + final positionJson = json['position']; + final position = Position.fromJson(positionJson as Map); + final textDocumentJson = json['textDocument']; + final textDocument = TextDocumentIdentifier.fromJson( + textDocumentJson as Map); + final workDoneTokenJson = json['workDoneToken']; + final workDoneToken = + workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson); + return PrepareRenameParams( + position: position, + textDocument: textDocument, + workDoneToken: workDoneToken, + ); + } +} + +class PrepareRenamePlaceholder implements ToJsonable { static const jsonHandler = LspJsonHandler( - PlaceholderAndRange.canParse, - PlaceholderAndRange.fromJson, + PrepareRenamePlaceholder.canParse, + PrepareRenamePlaceholder.fromJson, ); final String placeholder; final Range range; - PlaceholderAndRange({ + PrepareRenamePlaceholder({ required this.placeholder, required this.range, }); @@ -28934,8 +29115,8 @@ class PlaceholderAndRange implements ToJsonable { @override bool operator ==(Object other) { - return other is PlaceholderAndRange && - other.runtimeType == PlaceholderAndRange && + return other is PrepareRenamePlaceholder && + other.runtimeType == PrepareRenamePlaceholder && placeholder == other.placeholder && range == other.range; } @@ -28960,254 +29141,23 @@ class PlaceholderAndRange implements ToJsonable { return _canParseRange(obj, reporter, 'range', allowsUndefined: false, allowsNull: false); } else { - reporter.reportError('must be of type PlaceholderAndRange'); + reporter.reportError('must be of type PrepareRenamePlaceholder'); return false; } } - static PlaceholderAndRange fromJson(Map json) { + static PrepareRenamePlaceholder fromJson(Map json) { final placeholderJson = json['placeholder']; final placeholder = placeholderJson as String; final rangeJson = json['range']; final range = Range.fromJson(rangeJson as Map); - return PlaceholderAndRange( + return PrepareRenamePlaceholder( placeholder: placeholder, range: range, ); } } -/// Position in a text document expressed as zero-based line and character -/// offset. Prior to 3.17 the offsets were always based on a UTF-16 string -/// representation. So a string of the form `a𐐀b` the character offset of the -/// character `a` is 0, the character offset of `𐐀` is 1 and the character -/// offset of b is 3 since `𐐀` is represented using two code units in UTF-16. -/// Since 3.17 clients and servers can agree on a different string encoding -/// representation (e.g. UTF-8). The client announces it's supported encoding -/// via the client capability -/// [`general.positionEncodings`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#clientCapabilities). -/// The value is an array of position encodings the client supports, with -/// decreasing preference (e.g. the encoding at index `0` is the most preferred -/// one). To stay backwards compatible the only mandatory encoding is UTF-16 -/// represented via the string `utf-16`. The server can pick one of the -/// encodings offered by the client and signals that encoding back to the client -/// via the initialize result's property -/// [`capabilities.positionEncoding`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#serverCapabilities). -/// If the string value `utf-16` is missing from the client's capability -/// `general.positionEncodings` servers can safely assume that the client -/// supports UTF-16. If the server omits the position encoding in its initialize -/// result the encoding defaults to the string value `utf-16`. Implementation -/// considerations: since the conversion from one encoding into another requires -/// the content of the file / line the conversion is best done where the file is -/// read which is usually on the server side. -/// -/// Positions are line end character agnostic. So you can not specify a position -/// that denotes `\r|\n` or `\n|` where `|` represents the character offset. -/// -/// @since 3.17.0 - support for negotiated position encoding. -class Position implements ToJsonable { - static const jsonHandler = LspJsonHandler( - Position.canParse, - Position.fromJson, - ); - - /// Character offset on a line in a document (zero-based). - /// - /// The meaning of this offset is determined by the negotiated - /// `PositionEncodingKind`. - /// - /// If the character value is greater than the line length it defaults back to - /// the line length. - final int character; - - /// Line position in a document (zero-based). - /// - /// If a line number is greater than the number of lines in a document, it - /// defaults back to the number of lines in the document. If a line number is - /// negative, it defaults to 0. - final int line; - - Position({ - required this.character, - required this.line, - }); - @override - int get hashCode => Object.hash( - character, - line, - ); - - @override - bool operator ==(Object other) { - return other is Position && - other.runtimeType == Position && - character == other.character && - line == other.line; - } - - @override - Map toJson() { - var result = {}; - result['character'] = character; - result['line'] = line; - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParseInt(obj, reporter, 'character', - allowsUndefined: false, allowsNull: false)) { - return false; - } - return _canParseInt(obj, reporter, 'line', - allowsUndefined: false, allowsNull: false); - } else { - reporter.reportError('must be of type Position'); - return false; - } - } - - static Position fromJson(Map json) { - final characterJson = json['character']; - final character = characterJson as int; - final lineJson = json['line']; - final line = lineJson as int; - return Position( - character: character, - line: line, - ); - } -} - -/// A set of predefined position encoding kinds. -/// -/// @since 3.17.0 -class PositionEncodingKind implements ToJsonable { - /// Character offsets count UTF-16 code units. - /// - /// This is the default and must always be supported by servers - static const UTF16 = PositionEncodingKind('utf-16'); - - /// Character offsets count UTF-32 code units. - /// - /// Implementation note: these are the same as Unicode codepoints, - /// so this `PositionEncodingKind` may also be used for an encoding-agnostic - /// representation of character offsets. - static const UTF32 = PositionEncodingKind('utf-32'); - - /// Character offsets count UTF-8 code units (e.g. bytes). - static const UTF8 = PositionEncodingKind('utf-8'); - - final String _value; - const PositionEncodingKind(this._value); - const PositionEncodingKind.fromJson(this._value); - @override - int get hashCode => _value.hashCode; - - @override - bool operator ==(Object other) => - other is PositionEncodingKind && other._value == _value; - - @override - String toJson() => _value; - - @override - String toString() => _value.toString(); - - static bool canParse(Object? obj, LspJsonReporter reporter) => obj is String; -} - -class PrepareRenameParams - implements TextDocumentPositionParams, WorkDoneProgressParams, ToJsonable { - static const jsonHandler = LspJsonHandler( - PrepareRenameParams.canParse, - PrepareRenameParams.fromJson, - ); - - /// The position inside the text document. - @override - final Position position; - - /// The text document. - @override - final TextDocumentIdentifier textDocument; - - /// An optional token that a server can use to report work done progress. - @override - final ProgressToken? workDoneToken; - PrepareRenameParams({ - required this.position, - required this.textDocument, - this.workDoneToken, - }); - @override - int get hashCode => Object.hash( - position, - textDocument, - workDoneToken, - ); - - @override - bool operator ==(Object other) { - return other is PrepareRenameParams && - other.runtimeType == PrepareRenameParams && - position == other.position && - textDocument == other.textDocument && - workDoneToken == other.workDoneToken; - } - - @override - Map toJson() { - var result = {}; - result['position'] = position.toJson(); - result['textDocument'] = textDocument.toJson(); - if (workDoneToken != null) { - result['workDoneToken'] = workDoneToken; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParsePosition(obj, reporter, 'position', - allowsUndefined: false, allowsNull: false)) { - return false; - } - if (!_canParseTextDocumentIdentifier(obj, reporter, 'textDocument', - allowsUndefined: false, allowsNull: false)) { - return false; - } - return _canParseIntString(obj, reporter, 'workDoneToken', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type PrepareRenameParams'); - return false; - } - } - - static PrepareRenameParams fromJson(Map json) { - final positionJson = json['position']; - final position = Position.fromJson(positionJson as Map); - final textDocumentJson = json['textDocument']; - final textDocument = TextDocumentIdentifier.fromJson( - textDocumentJson as Map); - final workDoneTokenJson = json['workDoneToken']; - final workDoneToken = - workDoneTokenJson == null ? null : _eitherIntString(workDoneTokenJson); - return PrepareRenameParams( - position: position, - textDocument: textDocument, - workDoneToken: workDoneToken, - ); - } -} - class PrepareRenameResult2 implements ToJsonable { static const jsonHandler = LspJsonHandler( PrepareRenameResult2.canParse, @@ -30082,7 +30032,7 @@ class ReferenceRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; @override final bool? workDoneProgress; @@ -30121,7 +30071,7 @@ class ReferenceRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -30138,7 +30088,7 @@ class ReferenceRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final workDoneProgressJson = json['workDoneProgress']; final workDoneProgress = workDoneProgressJson as bool?; @@ -31237,7 +31187,7 @@ class RenameRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// Renames should be checked and tested before being executed. /// @@ -31287,7 +31237,7 @@ class RenameRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -31308,7 +31258,7 @@ class RenameRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final prepareProviderJson = json['prepareProvider']; final prepareProvider = prepareProviderJson as bool?; @@ -31810,7 +31760,7 @@ class SelectionRangeRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -31859,7 +31809,7 @@ class SelectionRangeRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -31880,7 +31830,7 @@ class SelectionRangeRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -32044,7 +31994,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { /// set to true but the server only provides a range provider the client might /// not render a minimap correctly or might even decide to not show any /// semantic tokens at all. - final SemanticTokensClientCapabilitiesRequests requests; + final ClientSemanticTokensRequestOptions requests; /// Whether the client allows the server to actively cancel a semantic token /// request, e.g. supports returning LSPErrorCodes.ServerCancelled. If a @@ -32148,7 +32098,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseSemanticTokensClientCapabilitiesRequests( + if (!_canParseClientSemanticTokensRequestOptions( obj, reporter, 'requests', allowsUndefined: false, allowsNull: false)) { return false; @@ -32183,7 +32133,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { final overlappingTokenSupportJson = json['overlappingTokenSupport']; final overlappingTokenSupport = overlappingTokenSupportJson as bool?; final requestsJson = json['requests']; - final requests = SemanticTokensClientCapabilitiesRequests.fromJson( + final requests = ClientSemanticTokensRequestOptions.fromJson( requestsJson as Map); final serverCancelSupportJson = json['serverCancelSupport']; final serverCancelSupport = serverCancelSupportJson as bool?; @@ -32209,87 +32159,6 @@ class SemanticTokensClientCapabilities implements ToJsonable { } } -class SemanticTokensClientCapabilitiesRequests implements ToJsonable { - static const jsonHandler = LspJsonHandler( - SemanticTokensClientCapabilitiesRequests.canParse, - SemanticTokensClientCapabilitiesRequests.fromJson, - ); - - /// The client will send the `textDocument/semanticTokens/full` request if the - /// server provides a corresponding handler. - final Either2? full; - - /// The client will send the `textDocument/semanticTokens/range` request if - /// the server provides a corresponding handler. - final Either2? range; - - SemanticTokensClientCapabilitiesRequests({ - this.full, - this.range, - }); - @override - int get hashCode => Object.hash( - full, - range, - ); - - @override - bool operator ==(Object other) { - return other is SemanticTokensClientCapabilitiesRequests && - other.runtimeType == SemanticTokensClientCapabilitiesRequests && - full == other.full && - range == other.range; - } - - @override - Map toJson() { - var result = {}; - if (full != null) { - result['full'] = full; - } - if (range != null) { - result['range'] = range; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - if (!_canParseBoolSemanticTokensClientCapabilitiesRequestsFull( - obj, reporter, 'full', - allowsUndefined: true, allowsNull: false)) { - return false; - } - return _canParseBoolSemanticTokensClientCapabilitiesRequestsRange( - obj, reporter, 'range', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError( - 'must be of type SemanticTokensClientCapabilitiesRequests'); - return false; - } - } - - static SemanticTokensClientCapabilitiesRequests fromJson( - Map json) { - final fullJson = json['full']; - final full = fullJson == null - ? null - : _eitherBoolSemanticTokensClientCapabilitiesRequestsFull(fullJson); - final rangeJson = json['range']; - final range = rangeJson == null - ? null - : _eitherBoolSemanticTokensClientCapabilitiesRequestsRange(rangeJson); - return SemanticTokensClientCapabilitiesRequests( - full: full, - range: range, - ); - } -} - class SemanticTokensClientCapabilitiesRequestsFull implements ToJsonable { static const jsonHandler = LspJsonHandler( SemanticTokensClientCapabilitiesRequestsFull.canParse, @@ -32703,6 +32572,60 @@ class SemanticTokensEdit implements ToJsonable { } } +class SemanticTokensFullDelta implements ToJsonable { + static const jsonHandler = LspJsonHandler( + SemanticTokensFullDelta.canParse, + SemanticTokensFullDelta.fromJson, + ); + + /// The server supports deltas for full documents. + final bool? delta; + + SemanticTokensFullDelta({ + this.delta, + }); + + @override + int get hashCode => delta.hashCode; + + @override + bool operator ==(Object other) { + return other is SemanticTokensFullDelta && + other.runtimeType == SemanticTokensFullDelta && + delta == other.delta; + } + + @override + Map toJson() { + var result = {}; + if (delta != null) { + result['delta'] = delta; + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + return _canParseBool(obj, reporter, 'delta', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type SemanticTokensFullDelta'); + return false; + } + } + + static SemanticTokensFullDelta fromJson(Map json) { + final deltaJson = json['delta']; + final delta = deltaJson as bool?; + return SemanticTokensFullDelta( + delta: delta, + ); + } +} + /// @since 3.16.0 class SemanticTokensLegend implements ToJsonable { static const jsonHandler = LspJsonHandler( @@ -32784,7 +32707,7 @@ class SemanticTokensOptions implements WorkDoneProgressOptions, ToJsonable { ); /// Server supports providing semantic tokens for a full document. - final Either2? full; + final Either2? full; /// The legend used by the server final SemanticTokensLegend legend; @@ -32839,7 +32762,7 @@ class SemanticTokensOptions implements WorkDoneProgressOptions, ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseBoolSemanticTokensOptionsFull(obj, reporter, 'full', + if (!_canParseBoolSemanticTokensFullDelta(obj, reporter, 'full', allowsUndefined: true, allowsNull: false)) { return false; } @@ -32864,9 +32787,8 @@ class SemanticTokensOptions implements WorkDoneProgressOptions, ToJsonable { return SemanticTokensRegistrationOptions.fromJson(json); } final fullJson = json['full']; - final full = fullJson == null - ? null - : _eitherBoolSemanticTokensOptionsFull(fullJson); + final full = + fullJson == null ? null : _eitherBoolSemanticTokensFullDelta(fullJson); final legendJson = json['legend']; final legend = SemanticTokensLegend.fromJson(legendJson as Map); @@ -32885,60 +32807,6 @@ class SemanticTokensOptions implements WorkDoneProgressOptions, ToJsonable { } } -class SemanticTokensOptionsFull implements ToJsonable { - static const jsonHandler = LspJsonHandler( - SemanticTokensOptionsFull.canParse, - SemanticTokensOptionsFull.fromJson, - ); - - /// The server supports deltas for full documents. - final bool? delta; - - SemanticTokensOptionsFull({ - this.delta, - }); - - @override - int get hashCode => delta.hashCode; - - @override - bool operator ==(Object other) { - return other is SemanticTokensOptionsFull && - other.runtimeType == SemanticTokensOptionsFull && - delta == other.delta; - } - - @override - Map toJson() { - var result = {}; - if (delta != null) { - result['delta'] = delta; - } - return result; - } - - @override - String toString() => jsonEncoder.convert(toJson()); - - static bool canParse(Object? obj, LspJsonReporter reporter) { - if (obj is Map) { - return _canParseBool(obj, reporter, 'delta', - allowsUndefined: true, allowsNull: false); - } else { - reporter.reportError('must be of type SemanticTokensOptionsFull'); - return false; - } - } - - static SemanticTokensOptionsFull fromJson(Map json) { - final deltaJson = json['delta']; - final delta = deltaJson as bool?; - return SemanticTokensOptionsFull( - delta: delta, - ); - } -} - class SemanticTokensOptionsRange implements ToJsonable { static const jsonHandler = LspJsonHandler( SemanticTokensOptionsRange.canParse, @@ -33242,11 +33110,11 @@ class SemanticTokensRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// Server supports providing semantic tokens for a full document. @override - final Either2? full; + final Either2? full; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -33319,12 +33187,12 @@ class SemanticTokensRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; } - if (!_canParseBoolSemanticTokensOptionsFull(obj, reporter, 'full', + if (!_canParseBoolSemanticTokensFullDelta(obj, reporter, 'full', allowsUndefined: true, allowsNull: false)) { return false; } @@ -33352,12 +33220,11 @@ class SemanticTokensRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final fullJson = json['full']; - final full = fullJson == null - ? null - : _eitherBoolSemanticTokensOptionsFull(fullJson); + final full = + fullJson == null ? null : _eitherBoolSemanticTokensFullDelta(fullJson); final idJson = json['id']; final id = idJson as String?; final legendJson = json['legend']; @@ -33652,7 +33519,7 @@ class ServerCapabilities implements ToJsonable { typeHierarchyProvider; /// Workspace specific server capabilities. - final ServerCapabilitiesWorkspace? workspace; + final WorkspaceOptions? workspace; /// The server provides workspace symbol support. final Either2? workspaceSymbolProvider; @@ -34043,7 +33910,7 @@ class ServerCapabilities implements ToJsonable { allowsUndefined: true, allowsNull: false)) { return false; } - if (!_canParseServerCapabilitiesWorkspace(obj, reporter, 'workspace', + if (!_canParseWorkspaceOptions(obj, reporter, 'workspace', allowsUndefined: true, allowsNull: false)) { return false; } @@ -34215,8 +34082,7 @@ class ServerCapabilities implements ToJsonable { typeHierarchyProviderJson); final workspaceJson = json['workspace']; final workspace = workspaceJson != null - ? ServerCapabilitiesWorkspace.fromJson( - workspaceJson as Map) + ? WorkspaceOptions.fromJson(workspaceJson as Map) : null; final workspaceSymbolProviderJson = json['workspaceSymbolProvider']; final workspaceSymbolProvider = workspaceSymbolProviderJson == null @@ -34262,49 +34128,100 @@ class ServerCapabilities implements ToJsonable { } } -class ServerCapabilitiesWorkspace implements ToJsonable { +class ServerCompletionItemOptions implements ToJsonable { static const jsonHandler = LspJsonHandler( - ServerCapabilitiesWorkspace.canParse, - ServerCapabilitiesWorkspace.fromJson, + ServerCompletionItemOptions.canParse, + ServerCompletionItemOptions.fromJson, ); - /// The server is interested in notifications/requests for operations on - /// files. + /// The server has support for completion item label details (see also + /// `CompletionItemLabelDetails`) when receiving a completion item in a + /// resolve call. /// - /// @since 3.16.0 - final FileOperationOptions? fileOperations; + /// @since 3.17.0 + final bool? labelDetailsSupport; - /// The server supports workspace folder. - /// - /// @since 3.6.0 - final WorkspaceFoldersServerCapabilities? workspaceFolders; + ServerCompletionItemOptions({ + this.labelDetailsSupport, + }); - ServerCapabilitiesWorkspace({ - this.fileOperations, - this.workspaceFolders, + @override + int get hashCode => labelDetailsSupport.hashCode; + + @override + bool operator ==(Object other) { + return other is ServerCompletionItemOptions && + other.runtimeType == ServerCompletionItemOptions && + labelDetailsSupport == other.labelDetailsSupport; + } + + @override + Map toJson() { + var result = {}; + if (labelDetailsSupport != null) { + result['labelDetailsSupport'] = labelDetailsSupport; + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + return _canParseBool(obj, reporter, 'labelDetailsSupport', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type ServerCompletionItemOptions'); + return false; + } + } + + static ServerCompletionItemOptions fromJson(Map json) { + final labelDetailsSupportJson = json['labelDetailsSupport']; + final labelDetailsSupport = labelDetailsSupportJson as bool?; + return ServerCompletionItemOptions( + labelDetailsSupport: labelDetailsSupport, + ); + } +} + +class ServerInfo implements ToJsonable { + static const jsonHandler = LspJsonHandler( + ServerInfo.canParse, + ServerInfo.fromJson, + ); + + /// The name of the server as defined by the server. + final String name; + + /// The server's version as defined by the server. + final String? version; + + ServerInfo({ + required this.name, + this.version, }); @override int get hashCode => Object.hash( - fileOperations, - workspaceFolders, + name, + version, ); @override bool operator ==(Object other) { - return other is ServerCapabilitiesWorkspace && - other.runtimeType == ServerCapabilitiesWorkspace && - fileOperations == other.fileOperations && - workspaceFolders == other.workspaceFolders; + return other is ServerInfo && + other.runtimeType == ServerInfo && + name == other.name && + version == other.version; } @override Map toJson() { var result = {}; - if (fileOperations != null) { - result['fileOperations'] = fileOperations?.toJson(); - } - if (workspaceFolders != null) { - result['workspaceFolders'] = workspaceFolders?.toJson(); + result['name'] = name; + if (version != null) { + result['version'] = version; } return result; } @@ -34314,33 +34231,26 @@ class ServerCapabilitiesWorkspace implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseFileOperationOptions(obj, reporter, 'fileOperations', - allowsUndefined: true, allowsNull: false)) { + if (!_canParseString(obj, reporter, 'name', + allowsUndefined: false, allowsNull: false)) { return false; } - return _canParseWorkspaceFoldersServerCapabilities( - obj, reporter, 'workspaceFolders', + return _canParseString(obj, reporter, 'version', allowsUndefined: true, allowsNull: false); } else { - reporter.reportError('must be of type ServerCapabilitiesWorkspace'); + reporter.reportError('must be of type ServerInfo'); return false; } } - static ServerCapabilitiesWorkspace fromJson(Map json) { - final fileOperationsJson = json['fileOperations']; - final fileOperations = fileOperationsJson != null - ? FileOperationOptions.fromJson( - fileOperationsJson as Map) - : null; - final workspaceFoldersJson = json['workspaceFolders']; - final workspaceFolders = workspaceFoldersJson != null - ? WorkspaceFoldersServerCapabilities.fromJson( - workspaceFoldersJson as Map) - : null; - return ServerCapabilitiesWorkspace( - fileOperations: fileOperations, - workspaceFolders: workspaceFolders, + static ServerInfo fromJson(Map json) { + final nameJson = json['name']; + final name = nameJson as String; + final versionJson = json['version']; + final version = versionJson as String?; + return ServerInfo( + name: name, + version: version, ); } } @@ -34351,7 +34261,7 @@ class SetTraceParams implements ToJsonable { SetTraceParams.fromJson, ); - final TraceValues value; + final TraceValue value; SetTraceParams({ required this.value, @@ -34379,7 +34289,7 @@ class SetTraceParams implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - return _canParseTraceValues(obj, reporter, 'value', + return _canParseTraceValue(obj, reporter, 'value', allowsUndefined: false, allowsNull: false); } else { reporter.reportError('must be of type SetTraceParams'); @@ -34389,7 +34299,7 @@ class SetTraceParams implements ToJsonable { static SetTraceParams fromJson(Map json) { final valueJson = json['value']; - final value = TraceValues.fromJson(valueJson as String); + final value = TraceValue.fromJson(valueJson as String); return SetTraceParams( value: value, ); @@ -35536,7 +35446,7 @@ class SignatureHelpRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// List of characters that re-trigger signature help. /// @@ -35600,7 +35510,7 @@ class SignatureHelpRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -35625,7 +35535,7 @@ class SignatureHelpRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final retriggerCharactersJson = json['retriggerCharacters']; final retriggerCharacters = (retriggerCharactersJson as List?) @@ -36188,7 +36098,7 @@ class TextDocumentChangeRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// How documents are synced to the server. final TextDocumentSyncKind syncKind; @@ -36225,7 +36135,7 @@ class TextDocumentChangeRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -36244,7 +36154,7 @@ class TextDocumentChangeRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final syncKindJson = json['syncKind']; final syncKind = TextDocumentSyncKind.fromJson(syncKindJson as int); @@ -36910,10 +36820,10 @@ class TextDocumentClientCapabilities implements ToJsonable { } } -class TextDocumentContentChangeEvent1 implements ToJsonable { +class TextDocumentContentChangePartial implements ToJsonable { static const jsonHandler = LspJsonHandler( - TextDocumentContentChangeEvent1.canParse, - TextDocumentContentChangeEvent1.fromJson, + TextDocumentContentChangePartial.canParse, + TextDocumentContentChangePartial.fromJson, ); /// The range of the document that changed. @@ -36926,7 +36836,7 @@ class TextDocumentContentChangeEvent1 implements ToJsonable { /// The new text for the provided range. final String text; - TextDocumentContentChangeEvent1({ + TextDocumentContentChangePartial({ required this.range, this.rangeLength, required this.text, @@ -36940,8 +36850,8 @@ class TextDocumentContentChangeEvent1 implements ToJsonable { @override bool operator ==(Object other) { - return other is TextDocumentContentChangeEvent1 && - other.runtimeType == TextDocumentContentChangeEvent1 && + return other is TextDocumentContentChangePartial && + other.runtimeType == TextDocumentContentChangePartial && range == other.range && rangeLength == other.rangeLength && text == other.text; @@ -36974,19 +36884,19 @@ class TextDocumentContentChangeEvent1 implements ToJsonable { return _canParseString(obj, reporter, 'text', allowsUndefined: false, allowsNull: false); } else { - reporter.reportError('must be of type TextDocumentContentChangeEvent1'); + reporter.reportError('must be of type TextDocumentContentChangePartial'); return false; } } - static TextDocumentContentChangeEvent1 fromJson(Map json) { + static TextDocumentContentChangePartial fromJson(Map json) { final rangeJson = json['range']; final range = Range.fromJson(rangeJson as Map); final rangeLengthJson = json['rangeLength']; final rangeLength = rangeLengthJson as int?; final textJson = json['text']; final text = textJson as String; - return TextDocumentContentChangeEvent1( + return TextDocumentContentChangePartial( range: range, rangeLength: rangeLength, text: text, @@ -36994,16 +36904,16 @@ class TextDocumentContentChangeEvent1 implements ToJsonable { } } -class TextDocumentContentChangeEvent2 implements ToJsonable { +class TextDocumentContentChangeWholeDocument implements ToJsonable { static const jsonHandler = LspJsonHandler( - TextDocumentContentChangeEvent2.canParse, - TextDocumentContentChangeEvent2.fromJson, + TextDocumentContentChangeWholeDocument.canParse, + TextDocumentContentChangeWholeDocument.fromJson, ); /// The new text of the whole document. final String text; - TextDocumentContentChangeEvent2({ + TextDocumentContentChangeWholeDocument({ required this.text, }); @@ -37012,8 +36922,8 @@ class TextDocumentContentChangeEvent2 implements ToJsonable { @override bool operator ==(Object other) { - return other is TextDocumentContentChangeEvent2 && - other.runtimeType == TextDocumentContentChangeEvent2 && + return other is TextDocumentContentChangeWholeDocument && + other.runtimeType == TextDocumentContentChangeWholeDocument && text == other.text; } @@ -37032,15 +36942,17 @@ class TextDocumentContentChangeEvent2 implements ToJsonable { return _canParseString(obj, reporter, 'text', allowsUndefined: false, allowsNull: false); } else { - reporter.reportError('must be of type TextDocumentContentChangeEvent2'); + reporter.reportError( + 'must be of type TextDocumentContentChangeWholeDocument'); return false; } } - static TextDocumentContentChangeEvent2 fromJson(Map json) { + static TextDocumentContentChangeWholeDocument fromJson( + Map json) { final textJson = json['text']; final text = textJson as String; - return TextDocumentContentChangeEvent2( + return TextDocumentContentChangeWholeDocument( text: text, ); } @@ -37294,10 +37206,10 @@ class TextDocumentFilter3 implements ToJsonable { } } -class TextDocumentFilterWithScheme implements ToJsonable { +class TextDocumentFilterScheme implements ToJsonable { static const jsonHandler = LspJsonHandler( - TextDocumentFilterWithScheme.canParse, - TextDocumentFilterWithScheme.fromJson, + TextDocumentFilterScheme.canParse, + TextDocumentFilterScheme.fromJson, ); /// A language id, like `typescript`. @@ -37308,7 +37220,7 @@ class TextDocumentFilterWithScheme implements ToJsonable { /// A Uri [Uri.scheme], like `file` or `untitled`. final String scheme; - TextDocumentFilterWithScheme({ + TextDocumentFilterScheme({ this.language, this.pattern, required this.scheme, @@ -37322,8 +37234,8 @@ class TextDocumentFilterWithScheme implements ToJsonable { @override bool operator ==(Object other) { - return other is TextDocumentFilterWithScheme && - other.runtimeType == TextDocumentFilterWithScheme && + return other is TextDocumentFilterScheme && + other.runtimeType == TextDocumentFilterScheme && language == other.language && pattern == other.pattern && scheme == other.scheme; @@ -37358,19 +37270,19 @@ class TextDocumentFilterWithScheme implements ToJsonable { return _canParseString(obj, reporter, 'scheme', allowsUndefined: false, allowsNull: false); } else { - reporter.reportError('must be of type TextDocumentFilterWithScheme'); + reporter.reportError('must be of type TextDocumentFilterScheme'); return false; } } - static TextDocumentFilterWithScheme fromJson(Map json) { + static TextDocumentFilterScheme fromJson(Map json) { final languageJson = json['language']; final language = languageJson as String?; final patternJson = json['pattern']; final pattern = patternJson as String?; final schemeJson = json['scheme']; final scheme = schemeJson as String; - return TextDocumentFilterWithScheme( + return TextDocumentFilterScheme( language: language, pattern: pattern, scheme: scheme, @@ -37655,7 +37567,7 @@ class TextDocumentRegistrationOptions implements ToJsonable { /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. - final List? documentSelector; + final List? documentSelector; TextDocumentRegistrationOptions({ this.documentSelector, @@ -37684,7 +37596,7 @@ class TextDocumentRegistrationOptions implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - return _canParseListTextDocumentFilterWithScheme( + return _canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true); } else { @@ -37794,7 +37706,7 @@ class TextDocumentRegistrationOptions implements ToJsonable { final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); return TextDocumentRegistrationOptions( documentSelector: documentSelector, @@ -37844,7 +37756,7 @@ class TextDocumentSaveRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The client is supposed to include the content on save. @override @@ -37884,7 +37796,7 @@ class TextDocumentSaveRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -37903,7 +37815,7 @@ class TextDocumentSaveRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final includeTextJson = json['includeText']; final includeText = includeTextJson as bool?; @@ -38277,25 +38189,25 @@ class TokenFormat implements ToJsonable { static bool canParse(Object? obj, LspJsonReporter reporter) => obj is String; } -class TraceValues implements ToJsonable { +class TraceValue implements ToJsonable { /// Trace messages only. - static const Messages = TraceValues._('messages'); + static const Messages = TraceValue._('messages'); /// Turn tracing off. - static const Off = TraceValues._('off'); + static const Off = TraceValue._('off'); /// Verbose message tracing. - static const Verbose = TraceValues._('verbose'); + static const Verbose = TraceValue._('verbose'); final String _value; - const TraceValues.fromJson(this._value); - const TraceValues._(this._value); + const TraceValue.fromJson(this._value); + const TraceValue._(this._value); @override int get hashCode => _value.hashCode; @override bool operator ==(Object other) => - other is TraceValues && other._value == _value; + other is TraceValue && other._value == _value; @override String toJson() => _value; @@ -38573,7 +38485,7 @@ class TypeDefinitionRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -38622,7 +38534,7 @@ class TypeDefinitionRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -38643,7 +38555,7 @@ class TypeDefinitionRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -39051,7 +38963,7 @@ class TypeHierarchyRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// null the document selector provided on the client side will be used. @override - final List? documentSelector; + final List? documentSelector; /// The id used to register the request. The id can be used to deregister the /// request again. See also Registration#id. @@ -39100,7 +39012,7 @@ class TypeHierarchyRegistrationOptions static bool canParse(Object? obj, LspJsonReporter reporter) { if (obj is Map) { - if (!_canParseListTextDocumentFilterWithScheme( + if (!_canParseListTextDocumentFilterScheme( obj, reporter, 'documentSelector', allowsUndefined: false, allowsNull: true)) { return false; @@ -39121,7 +39033,7 @@ class TypeHierarchyRegistrationOptions final documentSelectorJson = json['documentSelector']; final documentSelector = (documentSelectorJson as List?) ?.map((item) => - TextDocumentFilterWithScheme.fromJson(item as Map)) + TextDocumentFilterScheme.fromJson(item as Map)) .toList(); final idJson = json['id']; final id = idJson as String?; @@ -41897,6 +41809,89 @@ class WorkspaceFullDocumentDiagnosticReport } } +class WorkspaceOptions implements ToJsonable { + static const jsonHandler = LspJsonHandler( + WorkspaceOptions.canParse, + WorkspaceOptions.fromJson, + ); + + /// The server is interested in notifications/requests for operations on + /// files. + /// + /// @since 3.16.0 + final FileOperationOptions? fileOperations; + + /// The server supports workspace folder. + /// + /// @since 3.6.0 + final WorkspaceFoldersServerCapabilities? workspaceFolders; + + WorkspaceOptions({ + this.fileOperations, + this.workspaceFolders, + }); + @override + int get hashCode => Object.hash( + fileOperations, + workspaceFolders, + ); + + @override + bool operator ==(Object other) { + return other is WorkspaceOptions && + other.runtimeType == WorkspaceOptions && + fileOperations == other.fileOperations && + workspaceFolders == other.workspaceFolders; + } + + @override + Map toJson() { + var result = {}; + if (fileOperations != null) { + result['fileOperations'] = fileOperations?.toJson(); + } + if (workspaceFolders != null) { + result['workspaceFolders'] = workspaceFolders?.toJson(); + } + return result; + } + + @override + String toString() => jsonEncoder.convert(toJson()); + + static bool canParse(Object? obj, LspJsonReporter reporter) { + if (obj is Map) { + if (!_canParseFileOperationOptions(obj, reporter, 'fileOperations', + allowsUndefined: true, allowsNull: false)) { + return false; + } + return _canParseWorkspaceFoldersServerCapabilities( + obj, reporter, 'workspaceFolders', + allowsUndefined: true, allowsNull: false); + } else { + reporter.reportError('must be of type WorkspaceOptions'); + return false; + } + } + + static WorkspaceOptions fromJson(Map json) { + final fileOperationsJson = json['fileOperations']; + final fileOperations = fileOperationsJson != null + ? FileOperationOptions.fromJson( + fileOperationsJson as Map) + : null; + final workspaceFoldersJson = json['workspaceFolders']; + final workspaceFolders = workspaceFoldersJson != null + ? WorkspaceFoldersServerCapabilities.fromJson( + workspaceFoldersJson as Map) + : null; + return WorkspaceOptions( + fileOperations: fileOperations, + workspaceFolders: workspaceFolders, + ); + } +} + /// A special workspace symbol that supports locations without a range. /// /// See also SymbolInformation. From 81ba8939112c624356d0732b8713e0e09649faa0 Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 10 Oct 2024 15:19:51 +0000 Subject: [PATCH 2/7] [element model] fix `macro_test` expectations To fix failures: https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/analyzer-mac-release/29081/overview Change-Id: I1444b927f80c52d9730ed4d1fd8982e3727f7a15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389401 Commit-Queue: Samuel Rawlins Auto-Submit: Phil Quitslund Reviewed-by: Samuel Rawlins --- pkg/analyzer/test/src/summary/macro_test.dart | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/pkg/analyzer/test/src/summary/macro_test.dart b/pkg/analyzer/test/src/summary/macro_test.dart index 6a333b96266d..6b49c404c7c6 100644 --- a/pkg/analyzer/test/src/summary/macro_test.dart +++ b/pkg/analyzer/test/src/summary/macro_test.dart @@ -4390,10 +4390,56 @@ library topLevelVariables const x firstFragment: ::@fragment::package:test/test.macro.dart::@topLevelVariable::x + metadata + Annotation + atSign: @ @77 + name: PrefixedIdentifier + prefix: SimpleIdentifier + token: prefix0 @78 + staticElement: ::@fragment::package:test/test.macro.dart::@prefix::prefix0 + element: ::@fragment::package:test/test.macro.dart::@prefix2::prefix0 + staticType: null + period: . @85 + identifier: SimpleIdentifier + token: A @86 + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + arguments: ArgumentList + leftParenthesis: ( @87 + rightParenthesis: ) @88 + element: package:test/a.dart::::@class::A::@constructor::new + element2: package:test/a.dart::::@class::A::@constructor::new#element type: int getter: ::@fragment::package:test/test.macro.dart::@accessor::x#element const y firstFragment: ::@fragment::package:test/test.macro.dart::@topLevelVariable::y + metadata + Annotation + atSign: @ @77 + name: PrefixedIdentifier + prefix: SimpleIdentifier + token: prefix0 @78 + staticElement: ::@fragment::package:test/test.macro.dart::@prefix::prefix0 + element: ::@fragment::package:test/test.macro.dart::@prefix2::prefix0 + staticType: null + period: . @85 + identifier: SimpleIdentifier + token: A @86 + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + arguments: ArgumentList + leftParenthesis: ( @87 + rightParenthesis: ) @88 + element: package:test/a.dart::::@class::A::@constructor::new + element2: package:test/a.dart::::@class::A::@constructor::new#element type: int getter: ::@fragment::package:test/test.macro.dart::@accessor::y#element getters @@ -5191,6 +5237,29 @@ library topLevelVariables final foo firstFragment: ::@fragment::package:test/test.macro.dart::@topLevelVariable::foo + metadata + Annotation + atSign: @ @77 + name: PrefixedIdentifier + prefix: SimpleIdentifier + token: prefix0 @78 + staticElement: ::@fragment::package:test/test.macro.dart::@prefix::prefix0 + element: ::@fragment::package:test/test.macro.dart::@prefix2::prefix0 + staticType: null + period: . @85 + identifier: SimpleIdentifier + token: A @86 + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + arguments: ArgumentList + leftParenthesis: ( @87 + rightParenthesis: ) @88 + element: package:test/a.dart::::@class::A::@constructor::new + element2: package:test/a.dart::::@class::A::@constructor::new#element type: int getter: ::@fragment::package:test/test.macro.dart::@accessor::foo#element getters @@ -5236,10 +5305,56 @@ library topLevelVariables final foo firstFragment: ::@fragment::package:test/test.macro.dart::@topLevelVariable::foo + metadata + Annotation + atSign: @ @77 + name: PrefixedIdentifier + prefix: SimpleIdentifier + token: prefix0 @78 + staticElement: ::@fragment::package:test/test.macro.dart::@prefix::prefix0 + element: ::@fragment::package:test/test.macro.dart::@prefix2::prefix0 + staticType: null + period: . @85 + identifier: SimpleIdentifier + token: A @86 + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + arguments: ArgumentList + leftParenthesis: ( @87 + rightParenthesis: ) @88 + element: package:test/a.dart::::@class::A::@constructor::new + element2: package:test/a.dart::::@class::A::@constructor::new#element type: int getter: ::@fragment::package:test/test.macro.dart::@accessor::foo#element final bar firstFragment: ::@fragment::package:test/test.macro.dart::@topLevelVariable::bar + metadata + Annotation + atSign: @ @77 + name: PrefixedIdentifier + prefix: SimpleIdentifier + token: prefix0 @78 + staticElement: ::@fragment::package:test/test.macro.dart::@prefix::prefix0 + element: ::@fragment::package:test/test.macro.dart::@prefix2::prefix0 + staticType: null + period: . @85 + identifier: SimpleIdentifier + token: A @86 + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + staticElement: package:test/a.dart::::@class::A + element: package:test/a.dart::::@class::A#element + staticType: null + arguments: ArgumentList + leftParenthesis: ( @87 + rightParenthesis: ) @88 + element: package:test/a.dart::::@class::A::@constructor::new + element2: package:test/a.dart::::@class::A::@constructor::new#element type: int getter: ::@fragment::package:test/test.macro.dart::@accessor::bar#element getters From edecf19c84d15e8087e7bd710f8ba1e39a80e36e Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 10 Oct 2024 15:42:18 +0000 Subject: [PATCH 3/7] Small changes to invalid_runtime_checks_with_js_interop_types * Make top-level functions private. * Make `isFromLibrary` an extension method, which makes for some nice readability. * Remove the `typeProvider` field from the `_Visitor` class. * Null-check some values before passing to `getInvalidJsInteropTypeTest` which reduces the number of following null-asserts. * Don't convert DartTypes into strings when passing to `reportLint` as there is logic in there to qualify type names with library paths if they have the same name. Change-Id: Ifc0eab77fef774bebd22779e336457223c31ae7c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389420 Reviewed-by: Srujan Gaddam Auto-Submit: Samuel Rawlins Commit-Queue: Srujan Gaddam --- ...d_runtime_check_with_js_interop_types.dart | 253 +++++++++--------- 1 file changed, 122 insertions(+), 131 deletions(-) diff --git a/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart b/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart index 9afe1e598e55..d01f6615c16f 100644 --- a/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart +++ b/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart @@ -7,7 +7,6 @@ import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/dart/element/type_provider.dart'; // ignore: implementation_imports import 'package:analyzer/src/dart/element/type.dart'; // ignore: implementation_imports @@ -32,74 +31,33 @@ const Set _sdkWebLibraries = { 'dart:web_gl', }; -/// If [type] is a type declared using `@staticInterop` through -/// `dart:js_interop`, returns the JS type equivalent for that class, which is -/// just `JSObject`. -/// -/// `@staticInterop` types that were declared using `package:js` do not apply as -/// that package is incompatible with dart2wasm. -/// -/// Returns null if `type` is not a `dart:js_interop` `@staticInterop` class. -DartType? getJsTypeForStaticInterop(InterfaceType type) { - var element = type.element; - if (element is! ClassElement) return null; - var metadata = element.metadata; - var hasJS = false; - var hasStaticInterop = false; - late LibraryElement dartJsInterop; - for (var i = 0; i < metadata.length; i++) { - var annotation = metadata[i]; - var annotationElement = annotation.element; - if (annotationElement is ConstructorElement && - isFromLibrary(annotationElement.library, _dartJsInteropUri) && - annotationElement.enclosingElement3.name == 'JS') { - hasJS = true; - dartJsInterop = annotationElement.library; - } else if (annotationElement is PropertyAccessorElement && - isFromLibrary(annotationElement.library, _dartJsAnnotationsUri) && - annotationElement.name == 'staticInterop') { - hasStaticInterop = true; - } - } - return (hasJS && hasStaticInterop) - ? dartJsInterop.units.single.extensionTypes - .singleWhere((extType) => extType.name == 'JSObject') - // Nullability is ignored in this lint, so just return `thisType`. - .thisType - : null; -} - /// Given a [type] erased by [EraseNonJSInteropTypes], determine if it is a type /// that is a `dart:js_interop` type or is bound to one. -bool isDartJsInteropType(DartType type) { - if (type is TypeParameterType) return isDartJsInteropType(type.bound); +bool _isDartJsInteropType(DartType type) { + if (type is TypeParameterType) return _isDartJsInteropType(type.bound); if (type is InterfaceType) { var element = type.element; if (element is ExtensionTypeElement) { - return isFromLibrary(element.library, _dartJsInteropUri); + return element.isFromLibrary(_dartJsInteropUri); } } return false; } -bool isFromLibrary(LibraryElement elementLibrary, String uri) => - elementLibrary.definingCompilationUnit.source == - elementLibrary.context.sourceFactory.forUri(uri); - /// Whether [type] is a user JS interop type using `dart:js_interop` or is bound /// to one. /// /// An interop type is a user interop type if it's an extension type on another /// interop type or a `dart:js_interop` `@staticInterop` type. -bool isUserJsInteropType(DartType type) { - if (type is TypeParameterType) return isUserJsInteropType(type.bound); +bool _isUserJsInteropType(DartType type) { + if (type is TypeParameterType) return _isUserJsInteropType(type.bound); if (type is InterfaceType) { var element = type.element; if (element is ExtensionTypeElement) { var representationType = element.representation.type; - return isDartJsInteropType(representationType) || - isUserJsInteropType(representationType); - } else if (getJsTypeForStaticInterop(type) != null) { + return _isDartJsInteropType(representationType) || + _isUserJsInteropType(representationType); + } else if (_jsTypeForStaticInterop(type) != null) { return true; } } @@ -115,17 +73,55 @@ bool isUserJsInteropType(DartType type) { /// Since dart2wasm doesn't support these libraries, users can't come across /// platform-inconsistent type tests, and therefore we should not lint for these /// types. -bool isWasmIncompatibleJsInterop(DartType type) { - if (type is TypeParameterType) return isWasmIncompatibleJsInterop(type.bound); +bool _isWasmIncompatibleJsInterop(DartType type) { + if (type is TypeParameterType) { + return _isWasmIncompatibleJsInterop(type.bound); + } if (type is! InterfaceType) return false; var element = type.element; // `hasJS` only checks for the `dart:_js_annotations` definition, which is // what we want here. if (element.hasJS) return true; - return _sdkWebLibraries.any((uri) => isFromLibrary(element.library, uri)) || + return _sdkWebLibraries.any((uri) => element.isFromLibrary(uri)) || // While a type test with types from this library is very rare, we should // still ignore it for consistency. - isFromLibrary(element.library, _dartJsUri); + element.isFromLibrary(_dartJsUri); +} + +/// If [type] is a type declared using `@staticInterop` through +/// `dart:js_interop`, returns the JS type equivalent for that class, which is +/// just `JSObject`. +/// +/// `@staticInterop` types that were declared using `package:js` do not apply as +/// that package is incompatible with dart2wasm. +/// +/// Returns null if `type` is not a `dart:js_interop` `@staticInterop` class. +DartType? _jsTypeForStaticInterop(InterfaceType type) { + var element = type.element; + if (element is! ClassElement) return null; + var metadata = element.metadata; + var hasJS = false; + var hasStaticInterop = false; + late LibraryElement dartJsInterop; + for (var annotation in metadata) { + var annotationElement = annotation.element; + if (annotationElement is ConstructorElement && + annotationElement.isFromLibrary(_dartJsInteropUri) && + annotationElement.enclosingElement3.name == 'JS') { + hasJS = true; + dartJsInterop = annotationElement.library; + } else if (annotationElement is PropertyAccessorElement && + annotationElement.isFromLibrary(_dartJsAnnotationsUri) && + annotationElement.name == 'staticInterop') { + hasStaticInterop = true; + } + } + return (hasJS && hasStaticInterop) + ? dartJsInterop.units.single.extensionTypes + .singleWhere((extType) => extType.name == 'JSObject') + // Nullability is ignored in this lint, so just return `thisType`. + .thisType + : null; } /// Erases extension types except for JS interop types so that @@ -138,8 +134,6 @@ class EraseNonJSInteropTypes extends ExtensionTypeErasure { final _visitedTypes = {}; - EraseNonJSInteropTypes(); - @override DartType perform(DartType type, {bool keepUserInteropTypes = false}) { _keepUserInteropTypes = keepUserInteropTypes; @@ -150,13 +144,13 @@ class EraseNonJSInteropTypes extends ExtensionTypeErasure { @override DartType? visitInterfaceType(covariant InterfaceTypeImpl type) { if (_keepUserInteropTypes - ? isUserJsInteropType(type) - : isDartJsInteropType(type)) { + ? _isUserJsInteropType(type) + : _isDartJsInteropType(type)) { // Nullability and generics on interop types are ignored for this lint. In // order to just compare the interfaces themselves, we use `thisType`. return type.element.thisType; } else { - return getJsTypeForStaticInterop(type) ?? super.visitInterfaceType(type); + return _jsTypeForStaticInterop(type) ?? super.visitInterfaceType(type); } } @@ -200,7 +194,7 @@ class InvalidRuntimeCheckWithJSInteropTypes extends LintRule { @override void registerNodeProcessors( NodeLintRegistry registry, LinterContext context) { - var visitor = _Visitor(this, context.typeSystem, context.typeProvider); + var visitor = _Visitor(this, context.typeSystem); registry.addIsExpression(this, visitor); registry.addAsExpression(this, visitor); } @@ -209,10 +203,9 @@ class InvalidRuntimeCheckWithJSInteropTypes extends LintRule { class _Visitor extends SimpleAstVisitor { final LintRule rule; final TypeSystemImpl typeSystem; - final TypeProvider typeProvider; - late final EraseNonJSInteropTypes _eraseNonJsInteropTypes; + final EraseNonJSInteropTypes _eraseNonJsInteropTypes; - _Visitor(this.rule, TypeSystem typeSystem, this.typeProvider) + _Visitor(this.rule, TypeSystem typeSystem) : typeSystem = typeSystem as TypeSystemImpl, _eraseNonJsInteropTypes = EraseNonJSInteropTypes(); @@ -254,73 +247,71 @@ class _Visitor extends SimpleAstVisitor { /// Types that belong to JS interop libraries that are not available when /// compiling to Wasm are ignored. Nullability is also ignored for the purpose /// of this test. - LintCode? getInvalidJsInteropTypeTest(DartType? leftType, DartType? rightType, + LintCode? getInvalidJsInteropTypeTest(DartType leftType, DartType rightType, {required bool check}) { - if (leftType == null || rightType == null) return null; LintCode? lintCode; (DartType, DartType) eraseTypes(DartType left, DartType right) { var erasedLeft = typeSystem.promoteToNonNull(_eraseNonJsInteropTypes.perform(left)); var erasedRight = typeSystem.promoteToNonNull(_eraseNonJsInteropTypes.perform(right)); - var leftIsInteropType = isDartJsInteropType(erasedLeft); - var rightIsInteropType = isDartJsInteropType(erasedRight); + var leftIsInteropType = _isDartJsInteropType(erasedLeft); + var rightIsInteropType = _isDartJsInteropType(erasedRight); // If there's already an invalid check in this `canBeSubtypeOf` check, we // are already going to lint, so only continue checking if we haven't // found an issue. - if (lintCode == null) { - if (leftIsInteropType || rightIsInteropType) { - if (!isWasmIncompatibleJsInterop(erasedLeft) && - !isWasmIncompatibleJsInterop(erasedRight)) { - var erasedLeftIsSubtype = - typeSystem.isSubtypeOf(erasedLeft, erasedRight); - var erasedRightIsSubtype = - typeSystem.isSubtypeOf(erasedRight, erasedLeft); - var erasedLeftIsDynamic = erasedLeft is DynamicType; - var erasedRightIsDynamic = erasedRight is DynamicType; - if (check) { - if (!erasedLeftIsSubtype && !erasedRightIsDynamic) { - if (leftIsInteropType && rightIsInteropType) { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_js_is_inconsistent_js; - } else if (leftIsInteropType) { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_js_is_dart; - } else { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_dart_is_js; - } - } else if (erasedLeftIsSubtype && - leftIsInteropType && - rightIsInteropType) { - // Only report if the right type is a user JS interop type. - // Checks like `window is JSAny` are not confusing and not worth - // linting. - if (isUserJsInteropType(right) && - !typeSystem.isSubtypeOf( - _eraseNonJsInteropTypes.perform(left, - keepUserInteropTypes: true), - _eraseNonJsInteropTypes.perform(right, - keepUserInteropTypes: true))) { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_js_is_unrelated_js; - } + + if (lintCode == null && leftIsInteropType || rightIsInteropType) { + if (!_isWasmIncompatibleJsInterop(erasedLeft) && + !_isWasmIncompatibleJsInterop(erasedRight)) { + var erasedLeftIsSubtype = + typeSystem.isSubtypeOf(erasedLeft, erasedRight); + var erasedRightIsSubtype = + typeSystem.isSubtypeOf(erasedRight, erasedLeft); + var erasedLeftIsDynamic = erasedLeft is DynamicType; + var erasedRightIsDynamic = erasedRight is DynamicType; + if (check) { + if (!erasedLeftIsSubtype && !erasedRightIsDynamic) { + if (leftIsInteropType && rightIsInteropType) { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_js_is_inconsistent_js; + } else if (leftIsInteropType) { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_js_is_dart; + } else { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_dart_is_js; } - } else { - if (!erasedLeftIsSubtype && - !erasedRightIsSubtype && - !erasedLeftIsDynamic && - !erasedRightIsDynamic) { - if (leftIsInteropType && rightIsInteropType) { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_js_as_incompatible_js; - } else if (leftIsInteropType) { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_js_as_dart; - } else { - lintCode = LinterLintCode - .invalid_runtime_check_with_js_interop_types_dart_as_js; - } + } else if (erasedLeftIsSubtype && + leftIsInteropType && + rightIsInteropType) { + // Only report if the right type is a user JS interop type. + // Checks like `window is JSAny` are not confusing and not worth + // linting. + if (_isUserJsInteropType(right) && + !typeSystem.isSubtypeOf( + _eraseNonJsInteropTypes.perform(left, + keepUserInteropTypes: true), + _eraseNonJsInteropTypes.perform(right, + keepUserInteropTypes: true))) { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_js_is_unrelated_js; + } + } + } else { + if (!erasedLeftIsSubtype && + !erasedRightIsSubtype && + !erasedLeftIsDynamic && + !erasedRightIsDynamic) { + if (leftIsInteropType && rightIsInteropType) { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_js_as_incompatible_js; + } else if (leftIsInteropType) { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_js_as_dart; + } else { + lintCode = LinterLintCode + .invalid_runtime_check_with_js_interop_types_dart_as_js; } } } @@ -334,6 +325,7 @@ class _Visitor extends SimpleAstVisitor { return (erasedLeft, erasedRight); } + // Called here for the side effects of `eraseTypes`. typeSystem.canBeSubtypeOf(leftType, rightType, eraseTypes: eraseTypes); return lintCode; } @@ -342,14 +334,10 @@ class _Visitor extends SimpleAstVisitor { void visitAsExpression(AsExpression node) { var leftType = node.expression.staticType; var rightType = node.type.type; + if (leftType == null || rightType == null) return; var code = getInvalidJsInteropTypeTest(leftType, rightType, check: false); if (code != null) { - rule.reportLint(node, - arguments: [ - leftType!.getDisplayString(), - rightType!.getDisplayString(), - ], - errorCode: code); + rule.reportLint(node, arguments: [leftType, rightType], errorCode: code); } } @@ -357,14 +345,17 @@ class _Visitor extends SimpleAstVisitor { void visitIsExpression(IsExpression node) { var leftType = node.expression.staticType; var rightType = node.type.type; + if (leftType == null || rightType == null) return; var code = getInvalidJsInteropTypeTest(leftType, rightType, check: true); if (code != null) { - rule.reportLint(node, - arguments: [ - leftType!.getDisplayString(), - rightType!.getDisplayString(), - ], - errorCode: code); + rule.reportLint(node, arguments: [leftType, rightType], errorCode: code); } } } + +extension on Element { + /// Returns whether this is from the Dart library at [uri]. + bool isFromLibrary(String uri) => + library?.definingCompilationUnit.source == + context.sourceFactory.forUri(uri); +} From d27e14496fdee58aabbc9513bed2fa84fedf0696 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 10 Oct 2024 16:06:10 +0000 Subject: [PATCH 4/7] Bump args to 09c0fca1785c9df39288a48f767994eed80bed40 Changes: ``` > git log --format="%C(auto) %h %s" e623652..09c0fca https://dart.googlesource.com/args.git/+/09c0fca Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group (286) https://dart.googlesource.com/args.git/+/9cdc872 Add argument name when throwing a `ArgParserException`. (283) ``` Diff: https://dart.googlesource.com/args.git/+/e623652744c82533829f2e62b1aba1a6cf06e291..09c0fca1785c9df39288a48f767994eed80bed40/ Change-Id: I804c86db060b3c83acd34c00dd76953c6f28f70a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388744 Reviewed-by: Nate Bosch Commit-Queue: Devon Carew --- DEPS | 2 +- pkg/dartdev/test/commands/pub_test.dart | 3 ++- pkg/dartdev/test/commands/run_test.dart | 4 ++-- pkg/dev_compiler/test/worker/worker_test.dart | 2 +- pkg/test_runner/test/options_test.dart | 8 ++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/DEPS b/DEPS index 2653ba936982..3d3f64b9e4f6 100644 --- a/DEPS +++ b/DEPS @@ -120,7 +120,7 @@ vars = { # EOL comment after a dependency to disable this and pin it at its current # revision. - "args_rev": "e623652744c82533829f2e62b1aba1a6cf06e291", # + "args_rev": "09c0fca1785c9df39288a48f767994eed80bed40", # "async_rev": "5f70a996f673d625e3502597084653686c3e754c", "bazel_worker_rev": "aa3cc9e826350b960e0c5a67e6065bcedba8b0ac", "benchmark_harness_rev": "44f125ae1d045aa3de09fe88a8dd70cb7352d563", diff --git a/pkg/dartdev/test/commands/pub_test.dart b/pkg/dartdev/test/commands/pub_test.dart index 8356282a308f..4cfe94667733 100644 --- a/pkg/dartdev/test/commands/pub_test.dart +++ b/pkg/dartdev/test/commands/pub_test.dart @@ -91,6 +91,7 @@ void pub() { var result = await p.run(['pub', 'deps', '--foo']); expect(result.exitCode, 64); expect(result.stdout, isEmpty); - expect(result.stderr, startsWith('Could not find an option named "foo".')); + expect( + result.stderr, startsWith('Could not find an option named "--foo".')); }); } diff --git a/pkg/dartdev/test/commands/run_test.dart b/pkg/dartdev/test/commands/run_test.dart index 0c1a58b415c4..6954dec69258 100644 --- a/pkg/dartdev/test/commands/run_test.dart +++ b/pkg/dartdev/test/commands/run_test.dart @@ -414,7 +414,7 @@ void main(List args) => print("$b $args"); expect(result.stdout, isEmpty); expect( result.stderr, - contains('Could not find an option named "vm-name".'), + contains('Could not find an option named "--vm-name".'), ); expect(result.exitCode, 64); }); @@ -433,7 +433,7 @@ void main(List args) => print("$b $args"); expect(result.stdout, isEmpty); expect( result.stderr, - contains('Could not find an option named "verbose_gc".'), + contains('Could not find an option named "--verbose_gc".'), ); expect(result.exitCode, 64); }); diff --git a/pkg/dev_compiler/test/worker/worker_test.dart b/pkg/dev_compiler/test/worker/worker_test.dart index b6652aac85b6..5e341162495e 100644 --- a/pkg/dev_compiler/test/worker/worker_test.dart +++ b/pkg/dev_compiler/test/worker/worker_test.dart @@ -113,7 +113,7 @@ void main() { expect(result.exitCode, 64); expect(result.stdout, - contains('Could not find an option named "does-not-exist"')); + contains('Could not find an option named "--does-not-exist"')); expect(result.stderr, isEmpty); expect(outputJsFile.existsSync(), isFalse); }); diff --git a/pkg/test_runner/test/options_test.dart b/pkg/test_runner/test/options_test.dart index c8c1e93df738..204a28417767 100644 --- a/pkg/test_runner/test/options_test.dart +++ b/pkg/test_runner/test/options_test.dart @@ -86,16 +86,16 @@ void testValidation() { ['--timeout=1,2'], 'Integer value expected for option "--timeout".'); expectValidationError(['--progress=unknown'], - '"unknown" is not an allowed value for option "progress".'); + '"unknown" is not an allowed value for option "--progress".'); // Don't allow multiple. expectValidationError(['--progress=compact,silent'], - '"compact,silent" is not an allowed value for option "progress".'); + '"compact,silent" is not an allowed value for option "--progress".'); expectValidationError(['--nnbd=unknown'], - '"unknown" is not an allowed value for option "nnbd".'); + '"unknown" is not an allowed value for option "--nnbd".'); // Don't allow multiple. expectValidationError(['--nnbd=weak,strong'], - '"weak,strong" is not an allowed value for option "nnbd".'); + '"weak,strong" is not an allowed value for option "--nnbd".'); // Don't allow invalid named configurations. expectValidationError(['-ninvalid-vm-android-simarm'], From 867391edc238d058c442542f057c88d8ea1ecaf4 Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 10 Oct 2024 17:30:20 +0000 Subject: [PATCH 5/7] [element model] migrate `prefer_const_constructors` Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I1298112a1b565724b651fe107e4f573fe2f795e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389404 Reviewed-by: Konstantin Shcheglov Commit-Queue: Phil Quitslund --- pkg/linter/analyzer_use_new_elements.txt | 12 ++++++++---- .../lib/src/rules/prefer_const_constructors.dart | 13 +++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/linter/analyzer_use_new_elements.txt b/pkg/linter/analyzer_use_new_elements.txt index 12f131800c59..0723602d426e 100644 --- a/pkg/linter/analyzer_use_new_elements.txt +++ b/pkg/linter/analyzer_use_new_elements.txt @@ -1,6 +1,8 @@ lib/src/analyzer.dart +lib/src/lint_codes.dart +lib/src/lint_codes.g.dart lib/src/lint_names.dart -lib/src/linter_lint_codes.dart +lib/src/lint_names.g.dart lib/src/rules.dart lib/src/rules/always_declare_return_types.dart lib/src/rules/always_put_control_body_on_new_line.dart @@ -98,6 +100,7 @@ lib/src/rules/prefer_asserts_with_message.dart lib/src/rules/prefer_bool_in_asserts.dart lib/src/rules/prefer_collection_literals.dart lib/src/rules/prefer_conditional_assignment.dart +lib/src/rules/prefer_const_constructors.dart lib/src/rules/prefer_const_declarations.dart lib/src/rules/prefer_const_literals_to_create_immutables.dart lib/src/rules/prefer_contains.dart @@ -153,6 +156,7 @@ lib/src/rules/unnecessary_library_name.dart lib/src/rules/unnecessary_new.dart lib/src/rules/unnecessary_null_aware_assignments.dart lib/src/rules/unnecessary_null_in_if_null_operators.dart +lib/src/rules/unnecessary_nullable_for_final_variable_declarations.dart lib/src/rules/unnecessary_parenthesis.dart lib/src/rules/unnecessary_raw_strings.dart lib/src/rules/unnecessary_statements.dart @@ -431,7 +435,7 @@ test/validate_incompatible_rules_test.dart test/validate_no_rule_description_references_test.dart test/validate_rule_description_format_test.dart test/verify_checks_test.dart -test/verify_generated_codes_test.dart +test/verify_generated_files_test.dart test/verify_reflective_test_suites_test.dart test_data/rules/no_default_cases.dart test_data/rules/overridden_fields.dart @@ -447,14 +451,14 @@ test_data/rules/unmocked/unsafe_html.dart test_data/rules/unnecessary_lambdas.dart test_data/rules/unnecessary_parenthesis.dart test_data/rules/void_checks.dart +tool/benchmark.dart tool/changelog.dart tool/checks/check_all_yaml.dart tool/checks/check_messages_yaml.dart tool/checks/driver.dart tool/checks/rules/no_solo_tests.dart tool/checks/rules/no_trailing_spaces.dart -tool/cli.dart -tool/codes/generate.dart +tool/generate_lints.dart tool/labeler/issue_config.dart tool/labeler/pr_config.dart tool/legacy_test_move.dart diff --git a/pkg/linter/lib/src/rules/prefer_const_constructors.dart b/pkg/linter/lib/src/rules/prefer_const_constructors.dart index 2b45bf045ed4..ec5c9ac01976 100644 --- a/pkg/linter/lib/src/rules/prefer_const_constructors.dart +++ b/pkg/linter/lib/src/rules/prefer_const_constructors.dart @@ -4,7 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/ast/visitor.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/lint/linter.dart'; // ignore: implementation_imports @@ -41,24 +41,25 @@ class _Visitor extends SimpleAstVisitor { if (node.isConst) return; if (node.constructorName.type.isDeferred) return; - var element = node.constructorName.staticElement; + var element = node.constructorName.element; if (element == null) return; if (!element.isConst) return; // Handled by an analyzer warning. if (element.hasLiteral) return; - var enclosingElement = element.enclosingElement3; - if (enclosingElement is ClassElement && enclosingElement.isDartCoreObject) { + var enclosingElement = element.enclosingElement2; + if (enclosingElement is ClassElement2 && + enclosingElement.isDartCoreObject) { // Skip lint for `new Object()`, because it can be used for ID creation. return; } - if (enclosingElement.typeParameters.isNotEmpty && + if (enclosingElement.typeParameters2.isNotEmpty && node.constructorName.type.typeArguments == null) { var approximateContextType = node.approximateContextType; var contextTypeAsInstanceOfEnclosing = - approximateContextType?.asInstanceOf(enclosingElement); + approximateContextType?.asInstanceOf2(enclosingElement); if (contextTypeAsInstanceOfEnclosing != null) { if (contextTypeAsInstanceOfEnclosing.typeArguments .any((e) => e is TypeParameterType)) { From e8ff9efe9a10ed35450c799fe4ebb7bc3e54fcd4 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 10 Oct 2024 17:40:03 +0000 Subject: [PATCH 6/7] Add _PropertyElement.toString. This improves the debug experience when debugging flow analysis code. Change-Id: I876dece6213b0495caae5a9e673376898198e709 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389221 Commit-Queue: Paul Berry Reviewed-by: Kallen Tu --- pkg/_fe_analyzer_shared/test/mini_ast.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart index 657105dcf706..9bb9d646fcaf 100644 --- a/pkg/_fe_analyzer_shared/test/mini_ast.dart +++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart @@ -1682,7 +1682,7 @@ class Harness { late final Map _members = { for (var entry in _coreMemberTypes.entries) - entry.key: _PropertyElement(entry.value, + entry.key: _PropertyElement(entry.value, entry.key.split('.').last, isPromotable: false, whyNotPromotable: null) }; @@ -1769,7 +1769,7 @@ class Harness { _members[query] = null; return; } - _members[query] = _PropertyElement(Type(type), + _members[query] = _PropertyElement(Type(type), memberName, isPromotable: promotable, whyNotPromotable: whyNotPromotable); } @@ -6209,6 +6209,12 @@ class _PropertyElement { /// The type of the property. final Type _type; + /// The name of the property (used by toString) + final String _name; + + @override + String toString() => '$_type.$_name'; + /// Whether the property is promotable. final bool isPromotable; @@ -6223,7 +6229,7 @@ class _PropertyElement { /// to the test. final PropertyNonPromotabilityReason? whyNotPromotable; - _PropertyElement(this._type, + _PropertyElement(this._type, this._name, {required this.isPromotable, required this.whyNotPromotable}) { if (isPromotable) { assert(whyNotPromotable == null); From 280fd4c36260b427a1bc8ec1bc2c4d86ee8601a3 Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 10 Oct 2024 18:07:00 +0000 Subject: [PATCH 7/7] [element model] migrate `test_types_in_equals` Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I454fac69834b9616387520166f36780ee39e3bc9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389421 Commit-Queue: Phil Quitslund Reviewed-by: Konstantin Shcheglov --- pkg/linter/lib/src/rules/test_types_in_equals.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/linter/lib/src/rules/test_types_in_equals.dart b/pkg/linter/lib/src/rules/test_types_in_equals.dart index e4ac73a78fb4..2d66674110de 100644 --- a/pkg/linter/lib/src/rules/test_types_in_equals.dart +++ b/pkg/linter/lib/src/rules/test_types_in_equals.dart @@ -41,7 +41,7 @@ class _Visitor extends SimpleAstVisitor { } var parameters = declaration?.parameters; - var parameterName = parameters?.parameterElements.first?.name; + var parameterName = parameters?.parameterFragments.first?.name; if (expression.name == parameterName) { var typeName = _getTypeName(declaration!); rule.reportLint(node, arguments: [typeName]); @@ -68,5 +68,5 @@ class _Visitor extends SimpleAstVisitor { declaration != null && declaration.isOperator && declaration.name.lexeme == '==' && - declaration.parameters?.parameterElements.length == 1; + declaration.parameters?.parameterFragments.length == 1; }