From 60464713a64ad98779fcf59b44247e4c565381e1 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Tue, 23 Apr 2024 18:04:18 -0700 Subject: [PATCH] Switch Roslyn protocol types to System.Text.Json serialization --- .../LanguageServerEndpointAttribute.cs | 1 - .../RequestExecutionQueue.cs | 1 - .../CSharpVisualBasicLanguageServerFactory.cs | 2 - ...tocolConversions.MarkdownContentBuilder.cs | 1 - .../CodeCleanup/AbstractCodeCleanupService.cs | 1 - ...CodeFixService.FixAllDiagnosticProvider.cs | 2 - .../CodeFixService.ProjectCodeFixProvider.cs | 2 - .../Features/CodeFixes/ICodeFixService.cs | 1 - .../Diagnostics/DiagnosticAnalyzerService.cs | 2 - .../Diagnostics/DocumentAnalysisExecutor.cs | 1 - ...gnosticIncrementalAnalyzer.AnalysisData.cs | 1 - ...lAnalyzer.IncrementalMemberEditAnalyzer.cs | 1 - ...gnosticIncrementalAnalyzer.ProjectState.cs | 1 - ...gnosticIncrementalAnalyzer.StateManager.cs | 3 - .../DiagnosticIncrementalAnalyzer.StateSet.cs | 1 - .../EngineV2/DiagnosticIncrementalAnalyzer.cs | 1 - ...Span.ProjectAndCompilationWithAnalyzers.cs | 14 - .../FindUsages/SimpleFindUsagesContext.cs | 1 - .../Options/CodeActionOptionsStorage.cs | 1 - .../DocumentationCommentOptionsStorage.cs | 2 - .../GlobalCodeActionOptionsProvider.cs | 3 - .../Options/WorkspaceConfigurationService.cs | 1 - .../UnifiedFixAllCodeFixSuggestedAction.cs | 1 - ...iedFixAllCodeRefactoringSuggestedAction.cs | 1 - .../UnifiedSuggestedAction.cs | 1 - .../Handler/CodeActions/CodeActionHelpers.cs | 2 - .../Handler/CodeActions/CodeActionsHandler.cs | 2 - .../Handler/CodeLens/CodeLensHandler.cs | 2 - .../CodeLens/CodeLensResolveHandler.cs | 2 - .../Handler/Completion/CompletionListCache.cs | 1 - .../ILspCompletionResultCreationService.cs | 1 - .../AbstractGoToDefinitionHandler.cs | 3 - .../AbstractPullDiagnosticHandler.cs | 1 - ...AbstractWorkspacePullDiagnosticsHandler.cs | 3 + .../DocumentPullDiagnosticHandler.cs | 2 + .../Diagnostics/PullDiagnosticConstants.cs | 2 - .../Handler/DocumentChanges/DidOpenHandler.cs | 1 - .../AbstractFormatDocumentHandlerBase.cs | 1 - .../Formatting/FormatDocumentOnTypeHandler.cs | 4 - .../Handler/IDocumentChangeTracker.cs | 2 - .../Handler/InlayHint/InlayHintCache.cs | 1 - .../Handler/InlayHint/InlayHintHandler.cs | 2 - .../InlayHint/InlayHintRefreshQueueFactory.cs | 1 - .../InlayHint/InlayHintResolveHandler.cs | 4 - .../Protocol/Handler/LspErrorCodes.cs | 4 - .../PullHandlers/VersionedPullCache`1.cs | 1 - .../References/FindAllReferencesHandler.cs | 1 - .../References/FindImplementationsHandler.cs | 1 - .../References/FindUsagesLSPContext.cs | 1 - .../Protocol/Handler/RequestContext.cs | 1 - .../SemanticTokensRangeHandler.cs | 1 - .../SpellCheck/DocumentSpellCheckHandler.cs | 1 - ...rpVisualBasicLspServiceFactoryAttribute.cs | 3 - .../LspServices/RoslynLspServiceProvider.cs | 1 - .../Protocol/ApplyWorkspaceEditParams.cs | 10 +- .../Protocol/ApplyWorkspaceEditResponse.cs | 11 +- .../Protocol/Protocol/ClientCapabilities.cs | 16 +- .../Protocol/Protocol/CodeAction.cs | 26 +- .../Protocol/Protocol/CodeActionContext.cs | 14 +- .../Protocol/Protocol/CodeActionKind.cs | 4 +- .../Protocol/CodeActionKindSetting.cs | 5 +- .../Protocol/CodeActionLiteralSetting.cs | 5 +- .../Protocol/Protocol/CodeActionOptions.cs | 16 +- .../Protocol/Protocol/CodeActionParams.cs | 9 +- .../CodeActionResolveSupportSetting.cs | 6 +- .../Protocol/Protocol/CodeActionSetting.cs | 16 +- .../Protocol/CodeActionTriggerKind.cs | 3 - .../Protocol/Protocol/CodeDescription.cs | 6 +- .../Protocol/Protocol/CodeLens.cs | 14 +- .../Protocol/Protocol/CodeLensOptions.cs | 12 +- .../Protocol/Protocol/CodeLensParams.cs | 5 +- .../Protocol/CodeLensWorkspaceSetting.cs | 8 +- .../LanguageServer/Protocol/Protocol/Color.cs | 11 +- .../Protocol/Protocol/ColorInformation.cs | 7 +- .../Protocol/Protocol/Command.cs | 16 +- .../Protocol/Protocol/CompletionContext.cs | 10 +- .../Protocol/Protocol/CompletionItem.cs | 71 ++- .../Protocol/CompletionItemKindSetting.cs | 8 +- .../Protocol/CompletionItemLabelDetails.cs | 12 +- .../Protocol/CompletionItemOptions.cs | 8 +- .../Protocol/CompletionItemSetting.cs | 44 +- .../CompletionItemTagSupportSetting.cs | 6 +- .../Protocol/Protocol/CompletionList.cs | 13 +- .../Protocol/CompletionListItemDefaults.cs | 24 +- .../Protocol/CompletionListSetting.cs | 9 +- .../Protocol/Protocol/CompletionOptions.cs | 24 +- .../Protocol/Protocol/CompletionParams.cs | 12 +- .../Protocol/Protocol/CompletionSetting.cs | 24 +- .../Protocol/CompletionTriggerKind.cs | 3 - .../Protocol/Protocol/ConfigurationItem.cs | 12 +- .../Protocol/Protocol/ConfigurationParams.cs | 5 +- .../Converters/DocumentUriConverter.cs | 65 +-- .../JsonConverterCollectionUtilities.cs | 19 - .../Converters/NaturalObjectConverter.cs | 71 +++ .../ParameterInformationConverter.cs | 82 ++-- .../Converters/StringEnumConverter.cs | 43 +- .../Protocol/Converters/SumConverter.cs | 443 ++++++++++-------- .../Converters/TextDocumentSyncConverter.cs | 117 ++--- .../Protocol/Protocol/CreateFile.cs | 13 +- .../Protocol/Protocol/CreateFileOptions.cs | 12 +- .../Protocol/DefaultBehaviorPrepareRename.cs | 8 +- .../Protocol/Protocol/DefinitionOptions.cs | 8 +- .../Protocol/Protocol/DeleteFile.cs | 13 +- .../Protocol/Protocol/DeleteFileOptions.cs | 13 +- .../Protocol/Protocol/Diagnostic.cs | 32 +- .../Protocol/Protocol/DiagnosticOptions.cs | 16 +- .../Protocol/DiagnosticRegistrationOptions.cs | 12 +- .../Protocol/DiagnosticRelatedInformation.cs | 7 +- .../DiagnosticServerCancellationData.cs | 5 +- .../Protocol/Protocol/DiagnosticSetting.cs | 8 +- .../Protocol/DiagnosticWorkspaceSetting.cs | 8 +- .../Protocol/DidChangeConfigurationParams.cs | 5 +- .../Protocol/DidChangeTextDocumentParams.cs | 7 +- .../Protocol/DidChangeWatchedFilesParams.cs | 6 +- .../Protocol/DidCloseTextDocumentParams.cs | 5 +- .../Protocol/DidOpenTextDocumentParams.cs | 5 +- .../Protocol/DidSaveTextDocumentParams.cs | 10 +- .../Protocol/Protocol/DocumentColorOptions.cs | 8 +- .../Protocol/Protocol/DocumentColorParams.cs | 5 +- .../Protocol/DocumentDiagnosticParams.cs | 18 +- .../DocumentDiagnosticReportPartialResult.cs | 5 +- .../Protocol/Protocol/DocumentFilter.cs | 16 +- .../Protocol/DocumentFormattingOptions.cs | 8 +- .../Protocol/DocumentFormattingParams.cs | 7 +- .../Protocol/Protocol/DocumentHighlight.cs | 10 +- .../Protocol/DocumentHighlightKind.cs | 3 - .../Protocol/DocumentHighlightOptions.cs | 8 +- .../Protocol/DocumentHighlightParams.cs | 7 +- .../Protocol/Protocol/DocumentLink.cs | 10 +- .../Protocol/Protocol/DocumentLinkOptions.cs | 12 +- .../Protocol/Protocol/DocumentLinkParams.cs | 5 +- .../DocumentOnTypeFormattingOptions.cs | 10 +- .../DocumentOnTypeFormattingParams.cs | 7 +- .../DocumentRangeFormattingOptions.cs | 8 +- .../Protocol/DocumentRangeFormattingParams.cs | 9 +- .../Protocol/Protocol/DocumentSymbol.cs | 27 +- .../Protocol/DocumentSymbolOptions.cs | 8 +- .../Protocol/Protocol/DocumentSymbolParams.cs | 5 +- .../Protocol/DocumentSymbolSetting.cs | 12 +- .../Protocol/DynamicRegistrationSetting.cs | 8 +- .../Protocol/ExecuteCommandOptions.cs | 10 +- .../Protocol/Protocol/ExecuteCommandParams.cs | 10 +- .../Converters/VSExtensionConverter.cs | 47 +- .../Converters/VSExtensionUtilities.cs | 80 ++-- .../Protocol/Extensions/VSDiagnostic.cs | 32 +- .../VSDiagnosticProjectInformation.cs | 16 +- .../Extensions/VSGetProjectContextsParams.cs | 5 +- .../Protocol/Protocol/Extensions/VSImageId.cs | 7 +- .../Protocol/Extensions/VSLocation.cs | 12 +- .../Protocol/Extensions/VSProjectContext.cs | 11 +- .../Extensions/VSProjectContextList.cs | 7 +- .../Protocol/Extensions/VSProjectKind.cs | 3 - .../Extensions/VSServerCapabilities.cs | 8 +- .../Extensions/VSSymbolInformation.cs | 16 +- .../Extensions/VSTextDocumentIdentifier.cs | 8 +- .../Protocol/Protocol/FileEvent.cs | 8 +- .../Protocol/Protocol/FoldingRange.cs | 24 +- .../Protocol/Protocol/FoldingRangeKind.cs | 4 +- .../Protocol/Protocol/FoldingRangeOptions.cs | 8 +- .../Protocol/Protocol/FoldingRangeParams.cs | 5 +- .../Protocol/Protocol/FoldingRangeSetting.cs | 16 +- .../Protocol/FoldingRangeSettingOptions.cs | 8 +- .../Protocol/Protocol/FormattingOptions.cs | 9 +- .../Protocol/FullDocumentDiagnosticReport.cs | 12 +- .../LanguageServer/Protocol/Protocol/Hover.cs | 10 +- .../Protocol/Protocol/HoverOptions.cs | 8 +- .../Protocol/Protocol/HoverSetting.cs | 8 +- .../Protocol/ImplementationOptions.cs | 8 +- .../Protocol/Protocol/InitializeError.cs | 5 +- .../Protocol/Protocol/InitializeErrorCode.cs | 3 - .../Protocol/Protocol/InitializeParams.cs | 29 +- .../Protocol/Protocol/InitializeResult.cs | 5 +- .../Protocol/Protocol/InlayHint.cs | 32 +- .../Protocol/Protocol/InlayHintKind.cs | 3 - .../Protocol/Protocol/InlayHintLabelPart.cs | 18 +- .../Protocol/Protocol/InlayHintOptions.cs | 12 +- .../Protocol/Protocol/InlayHintParams.cs | 7 +- .../Protocol/InlayHintRegistrationOptions.cs | 12 +- .../InlayHintResolveSupportSetting.cs | 5 +- .../Protocol/Protocol/InlayHintSetting.cs | 8 +- .../Protocol/InlayHintWorkspaceSetting.cs | 8 +- .../Protocol/Protocol/InsertReplaceEdit.cs | 12 +- .../Protocol/Protocol/InsertReplaceRange.cs | 9 +- .../Protocol/InsertTextModeSupportSetting.cs | 6 +- .../ClassifiedTextElementConverter.cs | 104 ++-- .../Converters/ClassifiedTextRunConverter.cs | 95 ++-- .../Converters/ContainerElementConverter.cs | 119 +++-- .../Converters/DropProgressConverter.cs | 52 -- .../Converters/ImageElementConverter.cs | 99 ++-- .../Internal/Converters/ImageIdConverter.cs | 66 +-- .../Converters/ObjectContentConverter.cs | 172 +++---- .../Internal/Converters/RegexConverter.cs | 56 +-- .../VSCodeInternalExtensionUtilities.cs | 30 +- .../VSInternalExtensionUtilities.cs | 107 ++--- .../Diagnostics/VSInternalDiagnosticKind.cs | 5 +- .../VSInternalDiagnosticOptions.cs | 20 +- .../Diagnostics/VSInternalDiagnosticParams.cs | 16 +- .../Diagnostics/VSInternalDiagnosticReport.cs | 28 +- .../VSInternalDocumentDiagnosticsParams.cs | 12 +- .../VSInternalWorkspaceDiagnosticReport.cs | 6 +- .../VSInternalWorkspaceDiagnosticsParams.cs | 20 +- .../Efficiency/OptimizedVSCompletionList.cs | 4 +- .../OptimizedVSCompletionListJsonConverter.cs | 396 ++++++++-------- .../Internal/Text/ClassifiedTextElement.cs | 1 - .../Internal/VSFoldingRangeSetting.cs | 7 +- .../Internal/VSInternalClientCapabilities.cs | 24 +- .../Internal/VSInternalClipboardContent.cs | 9 +- .../Protocol/Internal/VSInternalCodeAction.cs | 24 +- .../Internal/VSInternalCodeActionContext.cs | 8 +- .../VSInternalCodeActionGroupSetting.cs | 5 +- .../VSInternalCodeActionLiteralSetting.cs | 8 +- .../Internal/VSInternalCommitCharacter.cs | 7 +- .../Internal/VSInternalCompletionContext.cs | 8 +- .../VSInternalCompletionInvokeKind.cs | 3 - .../Internal/VSInternalCompletionItem.cs | 20 +- .../Internal/VSInternalCompletionList.cs | 20 +- .../VSInternalCompletionListSetting.cs | 12 +- .../Internal/VSInternalCompletionSetting.cs | 8 +- .../VSInternalContinueCharacterClass.cs | 12 +- .../VSInternalContinueCharacterRange.cs | 16 +- .../VSInternalContinueCharacterSingle.cs | 12 +- .../VSInternalDocumentOnAutoInsertOptions.cs | 5 +- .../VSInternalDocumentOnAutoInsertParams.cs | 11 +- ...nternalDocumentOnAutoInsertResponseItem.cs | 12 +- .../VSInternalDocumentSpellCheckableParams.cs | 10 +- ...nternalExecuteCommandClientCapabilities.cs | 5 +- .../Protocol/Internal/VSInternalHover.cs | 7 +- .../Internal/VSInternalIconMapping.cs | 12 +- .../VSInternalInlineCompletionContext.cs | 12 +- .../VSInternalInlineCompletionItem.cs | 20 +- .../VSInternalInlineCompletionList.cs | 7 +- .../VSInternalInlineCompletionOptions.cs | 9 +- .../VSInternalInlineCompletionRequest.cs | 17 +- .../VSInternalInlineCompletionTriggerKind.cs | 3 - .../Internal/VSInternalKindAndModifier.cs | 10 +- .../Protocol/Internal/VSInternalLocation.cs | 8 +- .../Internal/VSInternalMapCodeMapping.cs | 14 +- .../Internal/VSInternalMapCodeParams.cs | 10 +- .../Internal/VSInternalProjectContext.cs | 8 +- .../Internal/VSInternalReferenceItem.cs | 53 +-- .../Internal/VSInternalReferenceKind.cs | 2 - .../Internal/VSInternalReferenceParams.cs | 7 +- .../VSInternalRenameOptionSelection.cs | 12 +- .../Internal/VSInternalRenameOptionSupport.cs | 16 +- .../Internal/VSInternalRenameParams.cs | 8 +- .../Internal/VSInternalRenameRange.cs | 8 +- .../VSInternalSelectedCompletionInfo.cs | 19 +- .../Internal/VSInternalServerCapabilities.cs | 58 ++- .../VSInternalSignatureInformation.cs | 8 +- .../VSInternalSpellCheckableRangeReport.cs | 13 +- .../Internal/VSInternalStreamingParams.cs | 11 +- .../Internal/VSInternalSymbolInformation.cs | 8 +- ...SInternalTextDocumentClientCapabilities.cs | 7 +- ...InternalTextDocumentRegistrationOptions.cs | 8 +- .../VSInternalTextPresentationParams.cs | 14 +- .../VSInternalUriPresentationParams.cs | 16 +- .../VSInternalValidateBreakableRangeParams.cs | 7 +- ...VSInternalWorkspaceSpellCheckableParams.cs | 14 +- ...VSInternalWorkspaceSpellCheckableReport.cs | 11 +- .../Protocol/LinkedEditingRangeOptions.cs | 8 +- .../Protocol/LinkedEditingRangeParams.cs | 3 - .../Protocol/Protocol/LinkedEditingRanges.cs | 10 +- .../Protocol/Protocol/Location.cs | 8 +- .../Protocol/Protocol/LogMessageParams.cs | 7 +- .../Protocol/Protocol/MarkedString.cs | 12 +- .../Protocol/Protocol/MarkupContent.cs | 7 +- .../Protocol/Protocol/MarkupKind.cs | 4 +- .../Protocol/Protocol/MessageActionItem.cs | 5 +- .../Protocol/Protocol/MessageType.cs | 3 - ...OptionalVersionedTextDocumentIdentifier.cs | 8 +- .../Protocol/Protocol/ParameterInformation.cs | 10 +- .../Protocol/ParameterInformationSetting.cs | 8 +- .../Protocol/Protocol/Position.cs | 8 +- .../Protocol/Protocol/PrepareRenameParams.cs | 7 +- .../Protocol/PrepareSupportDefaultBehavior.cs | 3 - .../Protocol/Protocol/PreviousResultId.cs | 8 +- .../Protocol/PublishDiagnosticParams.cs | 8 +- .../Protocol/PublishDiagnosticsSetting.cs | 8 +- .../LanguageServer/Protocol/Protocol/Range.cs | 12 +- .../Protocol/Protocol/ReferenceContext.cs | 5 +- .../Protocol/Protocol/ReferenceOptions.cs | 8 +- .../Protocol/Protocol/ReferenceParams.cs | 10 +- .../Protocol/Protocol/Registration.cs | 12 +- .../Protocol/Protocol/RegistrationParams.cs | 5 +- .../RelatedFullDocumentDiagnosticReport.cs | 8 +- ...elatedUnchangedDocumentDiagnosticReport.cs | 8 +- .../Protocol/RenameClientCapabilities.cs | 19 +- .../Protocol/Protocol/RenameFile.cs | 16 +- .../Protocol/Protocol/RenameFileOptions.cs | 12 +- .../Protocol/Protocol/RenameOptions.cs | 12 +- .../Protocol/Protocol/RenameParams.cs | 5 +- .../Protocol/Protocol/RenameRange.cs | 12 +- .../Protocol/ResolveSupportSetting.cs | 6 +- .../Protocol/ResourceOperationKind.cs | 4 +- .../Protocol/Protocol/SaveOptions.cs | 8 +- .../SemanticTokens/SemanticTokenFormat.cs | 4 +- .../Protocol/SemanticTokens/SemanticTokens.cs | 11 +- .../SemanticTokens/SemanticTokensDelta.cs | 12 +- .../SemanticTokensDeltaParams.cs | 12 +- .../SemanticTokensDeltaPartialResult.cs | 8 +- .../SemanticTokens/SemanticTokensEdit.cs | 12 +- .../SemanticTokensFullOptions.cs | 8 +- .../SemanticTokens/SemanticTokensLegend.cs | 7 +- .../SemanticTokens/SemanticTokensOptions.cs | 18 +- .../SemanticTokens/SemanticTokensParams.cs | 10 +- .../SemanticTokensPartialResult.cs | 6 +- .../SemanticTokensRangeParams.cs | 5 +- .../SemanticTokensRequestsFullSetting.cs | 8 +- .../SemanticTokensRequestsSetting.cs | 12 +- .../SemanticTokens/SemanticTokensSetting.cs | 20 +- .../SemanticTokensWorkspaceSetting.cs | 8 +- .../Protocol/Protocol/ServerCapabilities.cs | 106 ++--- .../Protocol/Protocol/ShowMessageParams.cs | 7 +- .../Protocol/ShowMessageRequestParams.cs | 8 +- .../Protocol/Protocol/SignatureHelp.cs | 16 +- .../Protocol/Protocol/SignatureHelpContext.cs | 16 +- .../Protocol/Protocol/SignatureHelpOptions.cs | 16 +- .../Protocol/Protocol/SignatureHelpParams.cs | 8 +- .../Protocol/Protocol/SignatureHelpSetting.cs | 12 +- .../Protocol/SignatureHelpTriggerKind.cs | 3 - .../Protocol/Protocol/SignatureInformation.cs | 14 +- .../Protocol/SignatureInformationSetting.cs | 12 +- .../Protocol/Protocol/SumType.cs | 4 +- .../Protocol/Protocol/SymbolInformation.cs | 14 +- .../Protocol/Protocol/SymbolKind.cs | 4 - .../Protocol/Protocol/SymbolKindSetting.cs | 8 +- .../Protocol/Protocol/SymbolSetting.cs | 8 +- .../Protocol/SynchronizationSetting.cs | 16 +- .../Protocol/Protocol/TagSupport.cs | 5 +- .../TextDocumentClientCapabilities.cs | 94 ++-- .../TextDocumentContentChangeEvent.cs | 12 +- .../Protocol/Protocol/TextDocumentEdit.cs | 9 +- .../Protocol/TextDocumentIdentifier.cs | 6 +- .../Protocol/Protocol/TextDocumentItem.cs | 12 +- .../Protocol/TextDocumentPositionParams.cs | 7 +- .../TextDocumentRegistrationOptions.cs | 7 +- .../Protocol/TextDocumentSaveReason.cs | 4 - .../Protocol/Protocol/TextDocumentSyncKind.cs | 3 - .../Protocol/TextDocumentSyncOptions.cs | 24 +- .../Protocol/Protocol/TextEdit.cs | 8 +- .../Protocol/Protocol/TraceSetting.cs | 2 +- .../Protocol/TypeDefinitionOptions.cs | 8 +- .../UnchangedDocumentDiagnosticReport.cs | 7 +- .../Protocol/Protocol/Unregistration.cs | 7 +- .../Protocol/Protocol/UnregistrationParams.cs | 5 +- .../VersionedTextDocumentIdentifier.cs | 6 +- .../Protocol/WillSaveTextDocumentParams.cs | 7 +- .../Protocol/WorkspaceClientCapabilities.cs | 48 +- .../Protocol/WorkspaceDiagnosticParams.cs | 14 +- .../Protocol/WorkspaceDiagnosticReport.cs | 8 +- .../WorkspaceDiagnosticReportPartialResult.cs | 8 +- .../Protocol/Protocol/WorkspaceEdit.cs | 12 +- .../Protocol/Protocol/WorkspaceEditSetting.cs | 12 +- .../WorkspaceFullDocumentDiagnosticReport.cs | 8 +- .../Protocol/WorkspaceSymbolOptions.cs | 8 +- .../Protocol/WorkspaceSymbolParams.cs | 10 +- ...kspaceUnchangedDocumentDiagnosticReport.cs | 8 +- .../LspMiscellaneousFilesWorkspace.cs | 4 - .../Workspaces/LspWorkspaceManager.cs | 1 - 359 files changed, 2410 insertions(+), 3212 deletions(-) delete mode 100644 src/Features/LanguageServer/Protocol/Protocol/Converters/JsonConverterCollectionUtilities.cs create mode 100644 src/Features/LanguageServer/Protocol/Protocol/Converters/NaturalObjectConverter.cs delete mode 100644 src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/DropProgressConverter.cs diff --git a/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/LanguageServerEndpointAttribute.cs b/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/LanguageServerEndpointAttribute.cs index a7bb1e13ac058..9f2a608ea16fc 100644 --- a/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/LanguageServerEndpointAttribute.cs +++ b/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/LanguageServerEndpointAttribute.cs @@ -6,7 +6,6 @@ #nullable enable using System; -using System.Linq; namespace Microsoft.CommonLanguageServerProtocol.Framework; diff --git a/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs b/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs index cd200a1ca0ec7..60f3bf3271c00 100644 --- a/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs +++ b/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs @@ -12,7 +12,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.Threading; -using Newtonsoft.Json.Linq; namespace Microsoft.CommonLanguageServerProtocol.Framework; diff --git a/src/Features/LanguageServer/Protocol/CSharpVisualBasicLanguageServerFactory.cs b/src/Features/LanguageServer/Protocol/CSharpVisualBasicLanguageServerFactory.cs index 5e2276385b282..797509201331c 100644 --- a/src/Features/LanguageServer/Protocol/CSharpVisualBasicLanguageServerFactory.cs +++ b/src/Features/LanguageServer/Protocol/CSharpVisualBasicLanguageServerFactory.cs @@ -3,9 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Composition; -using System.IO; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.Handler; diff --git a/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.MarkdownContentBuilder.cs b/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.MarkdownContentBuilder.cs index b72b3e00097fa..03bf62eacb2e4 100644 --- a/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.MarkdownContentBuilder.cs +++ b/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.MarkdownContentBuilder.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.LanguageServer; diff --git a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs index 6e8e167de9c82..6348b6ae6be5e 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.OrganizeImports; using Microsoft.CodeAnalysis.RemoveUnnecessaryImports; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.FixAllDiagnosticProvider.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.FixAllDiagnosticProvider.cs index 1d82aa9383dad..9d82ea0fa633e 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.FixAllDiagnosticProvider.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.FixAllDiagnosticProvider.cs @@ -2,10 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.ProjectCodeFixProvider.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.ProjectCodeFixProvider.cs index fde0bc07d9891..b2c78656b3497 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.ProjectCodeFixProvider.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.ProjectCodeFixProvider.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; -using System.Linq; using Microsoft.CodeAnalysis.Diagnostics; namespace Microsoft.CodeAnalysis.CodeFixes diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs index e0c55f84e1acf..609d36eb9ee08 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CodeFixes diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs index be32623daf749..69aa85d102140 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Runtime.CompilerServices; @@ -18,7 +17,6 @@ using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.CodeAnalysis.Text; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Diagnostics { diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs index 321e5cb7ee1f2..d5de93548ef16 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.LanguageService; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Telemetry; using Microsoft.CodeAnalysis.Text; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs index 0afc2829fd4ba..3be6f73e60c14 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Workspaces.Diagnostics; using Roslyn.Utilities; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs index fd15d29e0bff6..4abe7eb44d1e0 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Linq; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs index 172fb7357b49e..1f45073d32495 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Diagnostics; using System.Threading; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs index fe01283879f67..6e0b2fc05ab45 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs @@ -7,10 +7,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Host; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2 diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs index 9a2f24933bc04..c7e696eb8d421 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Roslyn.Utilities; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs index 1ddadcfbd2bf1..c42de66646961 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.CodeAnalysis.Workspaces.Diagnostics; using Roslyn.Utilities; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.ProjectAndCompilationWithAnalyzers.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.ProjectAndCompilationWithAnalyzers.cs index 0e9dfb571229b..dd86515b9604f 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.ProjectAndCompilationWithAnalyzers.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.ProjectAndCompilationWithAnalyzers.cs @@ -2,20 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.ErrorReporting; -using Microsoft.CodeAnalysis.Internal.Log; -using Microsoft.CodeAnalysis.PooledObjects; -using Microsoft.CodeAnalysis.Text; -using Roslyn.Utilities; - namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2 { internal partial class DiagnosticIncrementalAnalyzer diff --git a/src/Features/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs b/src/Features/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs index 9a607836aa66c..955b3b7eb142d 100644 --- a/src/Features/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs +++ b/src/Features/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs @@ -7,7 +7,6 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Notification; namespace Microsoft.CodeAnalysis.FindUsages { diff --git a/src/Features/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs b/src/Features/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs index bb07b3685be4a..50fd4952d3793 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; -using System.Xml.Serialization; using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.CodeStyle; diff --git a/src/Features/LanguageServer/Protocol/Features/Options/DocumentationCommentOptionsStorage.cs b/src/Features/LanguageServer/Protocol/Features/Options/DocumentationCommentOptionsStorage.cs index 514a457c471a0..ef07ceee6afd4 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/DocumentationCommentOptionsStorage.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/DocumentationCommentOptionsStorage.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Options; diff --git a/src/Features/LanguageServer/Protocol/Features/Options/GlobalCodeActionOptionsProvider.cs b/src/Features/LanguageServer/Protocol/Features/Options/GlobalCodeActionOptionsProvider.cs index efa334e23c319..5217e63350ad3 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/GlobalCodeActionOptionsProvider.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/GlobalCodeActionOptionsProvider.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.AddImport; diff --git a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs index 3b6ffa92508a1..d89464da63ae2 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs @@ -4,7 +4,6 @@ using System; using System.Composition; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; diff --git a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeFixSuggestedAction.cs b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeFixSuggestedAction.cs index 3d6fc0a911d31..6fe985eff906c 100644 --- a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeFixSuggestedAction.cs +++ b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeFixSuggestedAction.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeFixesAndRefactorings; using Microsoft.CodeAnalysis.UnifiedSuggestions.UnifiedSuggestedActions; diff --git a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeRefactoringSuggestedAction.cs b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeRefactoringSuggestedAction.cs index 11f6993cb7301..c6806df2a42b2 100644 --- a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeRefactoringSuggestedAction.cs +++ b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedFixAllCodeRefactoringSuggestedAction.cs @@ -4,7 +4,6 @@ using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixesAndRefactorings; -using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.UnifiedSuggestions.UnifiedSuggestedActions; namespace Microsoft.CodeAnalysis.UnifiedSuggestions diff --git a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedSuggestedAction.cs b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedSuggestedAction.cs index a0c207fefe169..1e85c481f5a77 100644 --- a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedSuggestedAction.cs +++ b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActions/UnifiedSuggestedAction.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using Microsoft.CodeAnalysis.CodeActions; namespace Microsoft.CodeAnalysis.UnifiedSuggestions diff --git a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs index 44136ac1f6479..0b8ff43d64255 100644 --- a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs +++ b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading; @@ -16,7 +15,6 @@ using Microsoft.CodeAnalysis.UnifiedSuggestions; using Roslyn.LanguageServer.Protocol; using Roslyn.Utilities; -using StreamJsonRpc; using CodeAction = Microsoft.CodeAnalysis.CodeActions.CodeAction; using LSP = Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs index 0e0ac5a264fec..c13a4e7e1d649 100644 --- a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs @@ -11,10 +11,8 @@ using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions; -using Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint; using Microsoft.CodeAnalysis.Options; using Roslyn.LanguageServer.Protocol; -using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler; diff --git a/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensHandler.cs b/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensHandler.cs index 9bb72371dbfa3..116e30bea6158 100644 --- a/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensHandler.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Linq; -using System.Reflection.Metadata; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeLens; @@ -18,7 +17,6 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using LSP = Roslyn.LanguageServer.Protocol; using Microsoft.CodeAnalysis.Text; -using StreamJsonRpc; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.CodeLens; diff --git a/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs b/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs index 930bf05308462..39d3299223f3c 100644 --- a/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs @@ -2,13 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeLens; using Newtonsoft.Json.Linq; using Roslyn.Utilities; -using StreamJsonRpc; using Microsoft.CodeAnalysis.Shared.Extensions; using LSP = Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionListCache.cs b/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionListCache.cs index eae62bc03704a..4c739a05c89e0 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionListCache.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionListCache.cs @@ -4,7 +4,6 @@ using Microsoft.CodeAnalysis.Completion; using static Microsoft.CodeAnalysis.LanguageServer.Handler.Completion.CompletionListCache; -using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Completion { diff --git a/src/Features/LanguageServer/Protocol/Handler/Completion/ILspCompletionResultCreationService.cs b/src/Features/LanguageServer/Protocol/Handler/Completion/ILspCompletionResultCreationService.cs index 755d8e8f90813..5fec8b6b20c28 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Completion/ILspCompletionResultCreationService.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Completion/ILspCompletionResultCreationService.cs @@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.LanguageService; -using Microsoft.CodeAnalysis.Text; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Completion diff --git a/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs index 83948cec1e616..9734dafe3a332 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs @@ -2,12 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindSymbols; -using Microsoft.CodeAnalysis.GoToDefinition; using Microsoft.CodeAnalysis.MetadataAsSource; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Options; diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs index 94bb3f537e1c9..000568c965123 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.SolutionCrawler; -using Microsoft.CommonLanguageServerProtocol.Framework; using Roslyn.LanguageServer.Protocol; using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs index 7e3d6e4619791..ab6ada210db7c 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs @@ -9,6 +9,9 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.DiagnosticSources; using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.SolutionCrawler; +using Microsoft.CodeAnalysis.TaskList; using Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics; diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/DocumentPullDiagnosticHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/DocumentPullDiagnosticHandler.cs index 16ee2f87d2bf2..050cfe582e16e 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/DocumentPullDiagnosticHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/DocumentPullDiagnosticHandler.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.DiagnosticSources; using Microsoft.CodeAnalysis.Options; diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/PullDiagnosticConstants.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/PullDiagnosticConstants.cs index 0384599ba952f..2a0b22abfaf86 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/PullDiagnosticConstants.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/PullDiagnosticConstants.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Immutable; - namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics; internal static class PullDiagnosticConstants diff --git a/src/Features/LanguageServer/Protocol/Handler/DocumentChanges/DidOpenHandler.cs b/src/Features/LanguageServer/Protocol/Handler/DocumentChanges/DidOpenHandler.cs index 54a811861cab1..b75b6c9793e95 100644 --- a/src/Features/LanguageServer/Protocol/Handler/DocumentChanges/DidOpenHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/DocumentChanges/DidOpenHandler.cs @@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; -using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges diff --git a/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs b/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs index 806e79597b426..a9db06c55f7c1 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; -using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler diff --git a/src/Features/LanguageServer/Protocol/Handler/Formatting/FormatDocumentOnTypeHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Formatting/FormatDocumentOnTypeHandler.cs index 0c60cfe6e1fa8..a3762bb7fe1ad 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Formatting/FormatDocumentOnTypeHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Formatting/FormatDocumentOnTypeHandler.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Collections.Immutable; using System.Composition; using System.Linq; using System.Threading; @@ -15,9 +13,7 @@ using Microsoft.CodeAnalysis.Indentation; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; -using Microsoft.CodeAnalysis.Text; using Roslyn.LanguageServer.Protocol; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler { diff --git a/src/Features/LanguageServer/Protocol/Handler/IDocumentChangeTracker.cs b/src/Features/LanguageServer/Protocol/Handler/IDocumentChangeTracker.cs index 275c707cdb142..ff2410d5277d7 100644 --- a/src/Features/LanguageServer/Protocol/Handler/IDocumentChangeTracker.cs +++ b/src/Features/LanguageServer/Protocol/Handler/IDocumentChangeTracker.cs @@ -5,10 +5,8 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Features.Workspaces; using Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges; using Microsoft.CodeAnalysis.Text; -using Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler; diff --git a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintCache.cs b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintCache.cs index 44c6877e471a6..c15f24183032d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintCache.cs +++ b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintCache.cs @@ -4,7 +4,6 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis.InlineHints; -using Roslyn.LanguageServer.Protocol; using static Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintCache; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint; diff --git a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs index 8da7e981f854a..08025830a4bca 100644 --- a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host.Mef; @@ -14,7 +13,6 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; using Roslyn.LanguageServer.Protocol; using LSP = Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintRefreshQueueFactory.cs b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintRefreshQueueFactory.cs index 232a9858c26ac..361bbc4f432e7 100644 --- a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintRefreshQueueFactory.cs +++ b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintRefreshQueueFactory.cs @@ -5,7 +5,6 @@ using System; using System.Composition; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; diff --git a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintResolveHandler.cs b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintResolveHandler.cs index 75cf236aee41c..d0e81cc719cfe 100644 --- a/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintResolveHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintResolveHandler.cs @@ -3,13 +3,9 @@ // See the LICENSE file in the project root for more information. using System; -using System.Drawing; -using System.Reflection.Metadata; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.InlineHints; -using Microsoft.CodeAnalysis.LanguageServer.Handler.CodeLens; using Roslyn.LanguageServer.Protocol; using Newtonsoft.Json.Linq; using Roslyn.Utilities; diff --git a/src/Features/LanguageServer/Protocol/Handler/LspErrorCodes.cs b/src/Features/LanguageServer/Protocol/Handler/LspErrorCodes.cs index 8a4c55e4ca7bb..af0a848d1d9ac 100644 --- a/src/Features/LanguageServer/Protocol/Handler/LspErrorCodes.cs +++ b/src/Features/LanguageServer/Protocol/Handler/LspErrorCodes.cs @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; - namespace Microsoft.CodeAnalysis.LanguageServer.Handler; /// diff --git a/src/Features/LanguageServer/Protocol/Handler/PullHandlers/VersionedPullCache`1.cs b/src/Features/LanguageServer/Protocol/Handler/PullHandlers/VersionedPullCache`1.cs index c4fdd4c88e8d2..c9ca5e63f60ef 100644 --- a/src/Features/LanguageServer/Protocol/Handler/PullHandlers/VersionedPullCache`1.cs +++ b/src/Features/LanguageServer/Protocol/Handler/PullHandlers/VersionedPullCache`1.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index 8e24d9425f109..bdfdaf086746d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -4,7 +4,6 @@ using System; using System.Composition; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Classification; diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 80e447be3956f..343299bec39e4 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.Handler diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs index 9e57963e23ef3..c562f50912455 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Classification; diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs b/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs index f0610290edbde..a9426705cc246 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.ErrorReporting; -using Microsoft.CodeAnalysis.Features.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; using Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs index 899203510b20d..4ee36deb369e7 100644 --- a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Options; diff --git a/src/Features/LanguageServer/Protocol/Handler/SpellCheck/DocumentSpellCheckHandler.cs b/src/Features/LanguageServer/Protocol/Handler/SpellCheck/DocumentSpellCheckHandler.cs index 541ffc8888b7b..b294d4998aa67 100644 --- a/src/Features/LanguageServer/Protocol/Handler/SpellCheck/DocumentSpellCheckHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/SpellCheck/DocumentSpellCheckHandler.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Threading; using Roslyn.LanguageServer.Protocol; diff --git a/src/Features/LanguageServer/Protocol/LspServices/ExportCSharpVisualBasicLspServiceFactoryAttribute.cs b/src/Features/LanguageServer/Protocol/LspServices/ExportCSharpVisualBasicLspServiceFactoryAttribute.cs index 641e7f1953f1d..e833c82c7047f 100644 --- a/src/Features/LanguageServer/Protocol/LspServices/ExportCSharpVisualBasicLspServiceFactoryAttribute.cs +++ b/src/Features/LanguageServer/Protocol/LspServices/ExportCSharpVisualBasicLspServiceFactoryAttribute.cs @@ -3,10 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Immutable; using System.Composition; -using System.Linq; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler; diff --git a/src/Features/LanguageServer/Protocol/LspServices/RoslynLspServiceProvider.cs b/src/Features/LanguageServer/Protocol/LspServices/RoslynLspServiceProvider.cs index 28e824ca250fd..4319937d232ab 100644 --- a/src/Features/LanguageServer/Protocol/LspServices/RoslynLspServiceProvider.cs +++ b/src/Features/LanguageServer/Protocol/LspServices/RoslynLspServiceProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Composition; -using System.Text; using Microsoft.CodeAnalysis.Host.Mef; namespace Microsoft.CodeAnalysis.LanguageServer; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs index 7e4930168f914..2ede34011caaf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from a server to a client for the workspace/applyEdit request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ApplyWorkspaceEditParams { /// /// Gets or sets the label associated with this edit. /// - [DataMember(Name = "label")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("label")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Label { get; @@ -29,7 +27,7 @@ public string? Label /// /// Gets or sets the edit to be applied to the workspace. /// - [DataMember(Name = "edit")] + [JsonPropertyName("edit")] public WorkspaceEdit Edit { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs b/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs index 080ce8850873f..0fb22929337ba 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs @@ -4,21 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the response sent for a workspace/applyEdit request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] + internal class ApplyWorkspaceEditResponse { /// /// Gets or sets a value indicating whether edits were applied or not. /// - [DataMember(Name = "applied")] + [JsonPropertyName("applied")] public bool Applied { get; @@ -28,8 +27,8 @@ public bool Applied /// /// Gets or sets a string with textual description for why the edit was not applied. /// - [DataMember(Name = "failureReason")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("failureReason")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? FailureReason { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/ClientCapabilities.cs index aa135aefed881..ba9367aea66dd 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ClientCapabilities.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents client capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ClientCapabilities { /// /// Gets or sets the workspace capabilities. /// - [DataMember(Name = "workspace")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("workspace")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public WorkspaceClientCapabilities? Workspace { get; @@ -29,8 +27,8 @@ public WorkspaceClientCapabilities? Workspace /// /// Gets or sets the text document capabilities. /// - [DataMember(Name = "textDocument")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("textDocument")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextDocumentClientCapabilities? TextDocument { get; @@ -40,8 +38,8 @@ public TextDocumentClientCapabilities? TextDocument /// /// Gets or sets the experimental capabilities. /// - [DataMember(Name = "experimental")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("experimental")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Experimental { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeAction.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeAction.cs index 86df1605432f0..9ac8ab11410e9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeAction.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeAction.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A class representing a change that can be performed in code. A CodeAction must either set @@ -14,13 +13,12 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeAction { /// /// Gets or sets the human readable title for this code action. /// - [DataMember(Name = "title")] + [JsonPropertyName("title")] public string Title { get; @@ -30,8 +28,8 @@ public string Title /// /// Gets or sets the kind of code action this instance represents. /// - [DataMember(Name = "kind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("kind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionKind? Kind { get; @@ -41,8 +39,8 @@ public CodeActionKind? Kind /// /// Gets or sets the diagnostics that this code action resolves. /// - [DataMember(Name = "diagnostics")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("diagnostics")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Diagnostic[]? Diagnostics { get; @@ -52,8 +50,8 @@ public Diagnostic[]? Diagnostics /// /// Gets or sets the workspace edit that this code action performs. /// - [DataMember(Name = "edit")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("edit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public WorkspaceEdit? Edit { get; @@ -63,8 +61,8 @@ public WorkspaceEdit? Edit /// /// Gets or sets the command that this code action executes. /// - [DataMember(Name = "command")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("command")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Command? Command { get; @@ -74,8 +72,8 @@ public Command? Command /// /// Gets or sets the data that will be resend to the server if the code action is selected to be resolved. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionContext.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionContext.cs index 2ccf570a49f2d..e40c24c7a3bd6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionContext.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing diagnostic information about the context of a code action /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionContext { /// /// Gets or sets an array of diagnostics relevant to a code action. /// - [DataMember(Name = "diagnostics")] + [JsonPropertyName("diagnostics")] public Diagnostic[] Diagnostics { get; @@ -28,8 +26,8 @@ public Diagnostic[] Diagnostics /// /// Gets or sets an array of code action kinds to filter for. /// - [DataMember(Name = "only")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("only")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionKind[]? Only { get; @@ -39,8 +37,8 @@ public CodeActionKind[]? Only /// /// Gets or sets the indicating how the code action was triggered.. /// - [DataMember(Name = "triggerKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("triggerKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionTriggerKind? TriggerKind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionKind.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionKind.cs index 264756a446c2c..c6c8663e284b2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionKind.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the kind of a code action. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct CodeActionKind(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs index 1ec354679a037..03806a7c4c696 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class containing the set of code action kinds that are supported. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionKindSetting { /// /// Gets or sets the code actions kinds the client supports. /// - [DataMember(Name = "valueSet")] + [JsonPropertyName("valueSet")] public CodeActionKind[] ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs index 92e1cc4a4f9b7..adc2cf397db90 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing support for code action literals. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionLiteralSetting { /// /// Gets or sets a value indicating what code action kinds are supported. /// - [DataMember(Name = "codeActionKind")] + [JsonPropertyName("codeActionKind")] public CodeActionKindSetting CodeActionKind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionOptions.cs index 3b32c4f3ec6bf..e63a4852b80e8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionOptions.cs @@ -4,15 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the registration options for code actions support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionOptions : IWorkDoneProgressOptions { /// @@ -22,8 +20,8 @@ internal class CodeActionOptions : IWorkDoneProgressOptions /// The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server /// may list out every specific kind they provide. /// - [DataMember(Name = "codeActionKinds")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeActionKinds")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionKind[]? CodeActionKinds { get; @@ -33,16 +31,16 @@ public CodeActionKind[]? CodeActionKinds /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } /// /// Gets or sets a value indicating whether the server provides support to resolve /// additional information for a code action. /// - [DataMember(Name = "resolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionParams.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionParams.cs index 67f546f31ba48..70e9f70d93c4a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for the textDocument/codeAction request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionParams : ITextDocumentParams { /// /// Gets or sets the document identifier indicating where the command was invoked. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the range in the document for which the command was invoked. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -37,7 +36,7 @@ public Range Range /// /// Gets or sets the additional diagnostic information about the code action context. /// - [DataMember(Name = "context")] + [JsonPropertyName("context")] public CodeActionContext Context { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs index 6649a9adf92c9..1d1280be4d074 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing settings for codeAction/resolve support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionResolveSupportSetting { /// /// Gets or sets a value indicating the properties that a client can resolve lazily. /// - [DataMember(Name = "properties")] + [JsonPropertyName("properties")] public string[] Properties { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionSetting.cs index 4af0f9f18dd66..eba4e7a023559 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing settings for code action support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeActionSetting : DynamicRegistrationSetting { /// /// Gets or sets a value indicating the client supports code action literals. /// - [DataMember(Name = "codeActionLiteralSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeActionLiteralSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionLiteralSetting? CodeActionLiteralSupport { get; @@ -31,8 +29,8 @@ public CodeActionLiteralSetting? CodeActionLiteralSupport /// additional code action properties via a separate `codeAction/resolve` /// request. /// - [DataMember(Name = "resolveSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resolveSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionResolveSupportSetting? ResolveSupport { get; @@ -44,8 +42,8 @@ public CodeActionResolveSupportSetting? ResolveSupport /// property which is preserved between a `textDocument/codeAction` and a /// `codeAction/resolve` request. /// - [DataMember(Name = "dataSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("dataSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DataSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs index 14413d38f3ead..ed48b55932d33 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum which represents the various reason why code actions were requested. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum CodeActionTriggerKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeDescription.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeDescription.cs index b91705db37fb0..d7c414285753e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeDescription.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeDescription.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a description for an error code. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeDescription : IEquatable { /// /// Gets or sets URI to open with more information about the diagnostic error. /// - [DataMember(Name = "href")] + [JsonPropertyName("href")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Href { diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeLens.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeLens.cs index c88d783e26953..4bec557ca0a10 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeLens.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeLens.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A class representing a code lens command that should be shown alongside source code. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeLens { /// /// Gets or sets the range that the code lens applies to. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -28,8 +26,8 @@ public Range Range /// /// Gets or sets the command associated with this code lens. /// - [DataMember(Name = "command")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("command")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Command? Command { get; @@ -39,8 +37,8 @@ public Command? Command /// /// Gets or sets the data that should be preserved between a textDocument/codeLens request and a codeLens/resolve request. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeLensOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeLensOptions.cs index eddb78e41bf39..22ac4b4cbfb1c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeLensOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeLensOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for code lens support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeLensOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether or not the code lens support has a resolve provider. /// - [DataMember(Name = "resolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider { get; @@ -29,8 +27,8 @@ public bool ResolveProvider /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeLensParams.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeLensParams.cs index d58fea7b19dec..a2ee3f149fbc2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeLensParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeLensParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for a textDocument/codeLens request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeLensParams : ITextDocumentParams { /// /// Gets or sets the document identifier to fetch code lens results for. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs index 76543e6b1a334..444bf3390dabe 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Newtonsoft.Json; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; namespace Roslyn.LanguageServer.Protocol { @@ -12,14 +11,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CodeLensWorkspaceSetting { /// /// Gets or sets a value indicating whether the client supports a refresh request sent from the server to the client. /// - [DataMember(Name = "refreshSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Color.cs b/src/Features/LanguageServer/Protocol/Protocol/Color.cs index bda5111332f02..319d60cf17462 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Color.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Color.cs @@ -4,14 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents a color. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Color { /// @@ -20,7 +19,7 @@ internal class Color /// /// Value should be clamped to [0,1]. /// - [DataMember(Name = "red")] + [JsonPropertyName("red")] public decimal Red { get; set; } /// @@ -29,7 +28,7 @@ internal class Color /// /// Value should be clamped to [0,1]. /// - [DataMember(Name = "green")] + [JsonPropertyName("green")] public decimal Green { get; set; } /// @@ -38,7 +37,7 @@ internal class Color /// /// Value should be clamped to [0,1]. /// - [DataMember(Name = "blue")] + [JsonPropertyName("blue")] public decimal Blue { get; set; } /// @@ -47,7 +46,7 @@ internal class Color /// /// Value should be clamped to [0,1]. /// - [DataMember(Name = "alpha")] + [JsonPropertyName("alpha")] public decimal Alpha { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/ColorInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/ColorInformation.cs index e2cf2f0433fad..a55e45f655455 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ColorInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ColorInformation.cs @@ -4,26 +4,25 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents color information. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ColorInformation { /// /// Gets or sets the text range representing the color. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; set; } /// /// Gets or sets the color. /// - [DataMember(Name = "color")] + [JsonPropertyName("color")] public Color Color { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Command.cs b/src/Features/LanguageServer/Protocol/Protocol/Command.cs index d3effcdb1b3ae..eefac1539a6f7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Command.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Command.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a reference to a command /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Command { /// /// Gets or sets the title of the command. /// - [DataMember(Name = "title")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("title")] + [JsonRequired] public string Title { get; @@ -29,8 +27,8 @@ public string Title /// /// Gets or sets the identifier associated with the command. /// - [DataMember(Name = "command")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("command")] + [JsonRequired] public string CommandIdentifier { get; @@ -40,8 +38,8 @@ public string CommandIdentifier /// /// Gets or sets the arguments that the command should be invoked with. /// - [DataMember(Name = "arguments")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("arguments")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object[]? Arguments { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionContext.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionContext.cs index 609242748d6b3..6c674e6b35b65 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionContext.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing additional information about the content in which a completion request is triggered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionContext { /// /// Gets or sets the indicating how the completion was triggered. /// - [DataMember(Name = "triggerKind")] + [JsonPropertyName("triggerKind")] public CompletionTriggerKind TriggerKind { get; @@ -28,8 +26,8 @@ public CompletionTriggerKind TriggerKind /// /// Gets or sets the character that triggered code completion. /// - [DataMember(Name = "triggerCharacter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("triggerCharacter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? TriggerCharacter { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItem.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItem.cs index f416ae767d3d1..d795c27940feb 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItem.cs @@ -6,21 +6,20 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents an IntelliSense completion item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItem { /// /// Gets or sets the label value, i.e. display text to users. /// - [DataMember(Name = "label", IsRequired = true)] + [JsonPropertyName("label")] + [JsonRequired] public string Label { get; @@ -30,8 +29,8 @@ public string Label /// /// Gets or sets additional details for the label. /// - [DataMember(Name = "labelDetails")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("labelDetails")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemLabelDetails? LabelDetails { get; @@ -41,11 +40,11 @@ public CompletionItemLabelDetails? LabelDetails /// /// Gets or sets the completion kind. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] [DefaultValue(CompletionItemKind.None)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public CompletionItemKind Kind { get; @@ -55,8 +54,8 @@ public CompletionItemKind Kind /// /// Tags for this completion item. /// - [DataMember(Name = "tags")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public CompletionItemTag[]? Tags { get; @@ -66,8 +65,8 @@ public CompletionItemTag[]? Tags /// /// Gets or sets the completion detail. /// - [DataMember(Name = "detail")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("detail")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Detail { get; @@ -77,8 +76,8 @@ public string? Detail /// /// Gets or sets the documentation comment. /// - [DataMember(Name = "documentation")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("documentation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public SumType? Documentation { get; @@ -88,8 +87,8 @@ public SumType? Documentation /// /// Gets or sets a value indicating whether this should be the selected item when showing. /// - [DataMember(Name = "preselect")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("preselect")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Preselect { get; @@ -99,8 +98,8 @@ public bool Preselect /// /// Gets or sets the custom sort text. /// - [DataMember(Name = "sortText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("sortText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? SortText { get; @@ -110,8 +109,8 @@ public string? SortText /// /// Gets or sets the custom filter text. /// - [DataMember(Name = "filterText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("filterText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? FilterText { get; @@ -121,8 +120,8 @@ public string? FilterText /// /// Gets or sets the insert text. /// - [DataMember(Name = "insertText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("insertText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? InsertText { get; @@ -132,10 +131,10 @@ public string? InsertText /// /// Gets or sets the insert text format. /// - [DataMember(Name = "insertTextFormat")] + [JsonPropertyName("insertTextFormat")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [DefaultValue(InsertTextFormat.Plaintext)] public InsertTextFormat InsertTextFormat { @@ -146,8 +145,8 @@ public InsertTextFormat InsertTextFormat /// /// Gets or sets the text edit. /// - [DataMember(Name = "textEdit")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("textEdit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? TextEdit { get; @@ -157,8 +156,8 @@ public SumType? TextEdit /// /// Gets or sets the text edit text. /// - [DataMember(Name = "textEditText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("textEditText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? TextEditText { get; @@ -171,8 +170,8 @@ public string? TextEditText /// /// Additional text edits must not interfere with the main text edit. /// - [DataMember(Name = "additionalTextEdits")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("additionalTextEdits")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextEdit[]? AdditionalTextEdits { get; @@ -184,8 +183,8 @@ public TextEdit[]? AdditionalTextEdits /// If present, this will override . /// If absent, will be used instead. /// - [DataMember(Name = "commitCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("commitCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? CommitCharacters { get; @@ -198,8 +197,8 @@ public string[]? CommitCharacters /// /// This feature is not supported in VS. /// - [DataMember(Name = "command")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("command")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Command? Command { get; @@ -209,8 +208,8 @@ public Command? Command /// /// Gets or sets any additional data that links the unresolve completion item and the resolved completion item. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs index 2322270f54e5d..b80c3219ce3fa 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the initialization setting for completion item kind /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItemKindSetting { /// /// Gets or sets the values that the client supports. /// - [DataMember(Name = "valueSet")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("valueSet")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemKind[]? ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs index 43b290c77361b..9bac8f809f335 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using Newtonsoft.Json; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Additional details for a completion item label. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItemLabelDetails { /// /// Gets or sets an optional string which is rendered less prominently directly after label, without any spacing. /// - [DataMember(Name = "detail")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("detail")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Detail { get; @@ -29,8 +27,8 @@ public string? Detail /// /// Gets or sets an optional string which is rendered less prominently after detail. /// - [DataMember(Name = "description")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("description")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Description { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs index 9686561c69c7b..11d0c8cd77ad1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents completion item capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItemOptions { /// /// Gets or sets a value indicating The server has support for completion item label details /// - [DataMember(Name = "labelDetailsSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("labelDetailsSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LabelDetailsSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs index 58c655a5256c5..e5ca68bae6da4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for completion item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItemSetting { /// /// Gets or sets a value indicating whether completion items can contain snippets. /// - [DataMember(Name = "snippetSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("snippetSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SnippetSupport { get; @@ -29,8 +27,8 @@ public bool SnippetSupport /// /// Gets or sets a value indicating whether the client supports commit characters. /// - [DataMember(Name = "commitCharactersSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("commitCharactersSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool CommitCharactersSupport { get; @@ -40,8 +38,8 @@ public bool CommitCharactersSupport /// /// Gets or sets the content formats supported for documentation. /// - [DataMember(Name = "documentationFormat")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentationFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public MarkupKind[]? DocumentationFormat { get; @@ -51,8 +49,8 @@ public MarkupKind[]? DocumentationFormat /// /// Gets or sets the a value indicating whether the client supports the deprecated property on a completion item. /// - [DataMember(Name = "deprecatedSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("deprecatedSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DeprecatedSupport { get; @@ -62,8 +60,8 @@ public bool DeprecatedSupport /// /// Gets or sets the a value indicating whether the client supports the preselect property on a completion item. /// - [DataMember(Name = "preselectSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("preselectSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PreselectSupport { get; @@ -73,8 +71,8 @@ public bool PreselectSupport /// /// Gets or sets the a value indicating whether the client supports the tag property on a completion item. /// - [DataMember(Name = "tagSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("tagSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemTagSupportSetting? TagSupport { get; @@ -84,8 +82,8 @@ public CompletionItemTagSupportSetting? TagSupport /// /// Gets or sets the a value indicating whether the client supports insert replace edit. /// - [DataMember(Name = "insertReplaceSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("insertReplaceSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool InsertReplaceSupport { get; @@ -95,8 +93,8 @@ public bool InsertReplaceSupport /// /// Gets or sets the a value indicating which properties a client can resolve lazily on a completion item. /// - [DataMember(Name = "resolveSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resolveSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ResolveSupportSetting? ResolveSupport { get; @@ -106,8 +104,8 @@ public ResolveSupportSetting? ResolveSupport /// /// Gets or sets the a value indicating whether the client supports the `insertTextMode` property on a completion item to override the whitespace handling mode as defined by the client. /// - [DataMember(Name = "insertTextModeSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("insertTextModeSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextModeSupportSetting? InsertTextModeSupport { get; @@ -117,8 +115,8 @@ public InsertTextModeSupportSetting? InsertTextModeSupport /// /// Gets or sets the a value indicating whether the client supports completion item label details. /// - [DataMember(Name = "labelDetailsSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("labelDetailsSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LabelDetailsSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs index 94b64986cff53..0b79975a7393a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for the tag property on a completion item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionItemTagSupportSetting { /// /// Gets or sets a value indicating the tags supported by the client. /// - [DataMember(Name = "valueSet", IsRequired = true)] + [JsonPropertyName("valueSet")] + [JsonRequired] public CompletionItemTag[] ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionList.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionList.cs index 6189603e856f0..122fcb04d4e64 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionList.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionList.cs @@ -4,23 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a completion list. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionList { /// /// Gets or sets a value indicating whether Items is the complete list of items or not. If incomplete is true, then /// filtering should ask the server again for completion item. /// - [DataMember(Name = "isIncomplete")] + [JsonPropertyName("isIncomplete")] public bool IsIncomplete { get; @@ -30,7 +27,7 @@ public bool IsIncomplete /// /// Gets or sets the list of completion items. /// - [DataMember(Name = "items")] + [JsonPropertyName("items")] public CompletionItem[] Items { get; @@ -40,8 +37,8 @@ public CompletionItem[] Items /// /// Gets or sets the completion list item defaults. /// - [DataMember(Name = "itemDefaults")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("itemDefaults")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionListItemDefaults? ItemDefaults { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs index 9c30582f3790a..4487a31a0f843 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents default properties associated with the entire completion list. /// - [DataContract] internal class CompletionListItemDefaults { /// /// Gets or sets the default commit character set. /// - [DataMember(Name = "commitCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("commitCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? CommitCharacters { get; @@ -27,8 +25,8 @@ public string[]? CommitCharacters /// /// Gets or sets the default edit range. /// - [DataMember(Name = "editRange")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("editRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? EditRange { get; @@ -38,8 +36,8 @@ public SumType? EditRange /// /// Gets or sets the default . /// - [DataMember(Name = "insertTextFormat")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("insertTextFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextFormat? InsertTextFormat { get; @@ -49,8 +47,8 @@ public InsertTextFormat? InsertTextFormat /// /// Gets or sets the default . /// - [DataMember(Name = "insertTextMode")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("insertTextMode")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextMode? InsertTextMode { get; @@ -60,8 +58,8 @@ public InsertTextMode? InsertTextMode /// /// Gets or sets the default completion item data. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionListSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionListSetting.cs index 6ae332b4c314b..ee4a5d56d6e8e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionListSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionListSetting.cs @@ -4,22 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents capabilites for the completion list type. /// - [DataContract] internal class CompletionListSetting { /// /// Gets or sets a value containing the supported property names of the object. /// If omitted, no properties are supported. /// - [DataMember(Name = "itemDefaults")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("itemDefaults")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? ItemDefaults { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionOptions.cs index 95c31bb7af59b..bdfa14e9507da 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents completion capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionOptions : IWorkDoneProgressOptions { /// /// Gets or sets the trigger characters. /// - [DataMember(Name = "triggerCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("triggerCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? TriggerCharacters { get; @@ -29,8 +27,8 @@ public string[]? TriggerCharacters /// /// Gets or sets a value indicating all the possible commit characters associated with the language server. /// - [DataMember(Name = "allCommitCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("allCommitCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? AllCommitCharacters { get; @@ -40,8 +38,8 @@ public string[]? AllCommitCharacters /// /// Gets or sets a value indicating whether server provides completion item resolve capabilities. /// - [DataMember(Name = "resolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider { get; @@ -51,15 +49,15 @@ public bool ResolveProvider /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } /// /// Gets or sets completion item setting. /// - [DataMember(Name = "completionItem")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completionItem")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemOptions? CompletionItemOptions { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionParams.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionParams.cs index 0756a75604049..0c1626b6c3395 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionParams.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters for the textDocument/completion request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionParams : TextDocumentPositionParams, IPartialResultParams?> { /// /// Gets or sets the completion context. /// - [DataMember(Name = "context")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("context")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionContext? Context { get; @@ -30,8 +28,8 @@ public CompletionContext? Context /// /// Gets or sets the value of the PartialResultToken instance. /// - [DataMember(Name = Methods.PartialResultTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress?>? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionSetting.cs index d05a2bcac679e..30a5228668a92 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for completion. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CompletionSetting : DynamicRegistrationSetting { /// /// Gets or sets completion item setting. /// - [DataMember(Name = "completionItem")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completionItem")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemSetting? CompletionItem { get; @@ -29,8 +27,8 @@ public CompletionItemSetting? CompletionItem /// /// Gets or sets specific settings. /// - [DataMember(Name = "completionItemKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completionItemKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemKindSetting? CompletionItemKind { get; @@ -40,8 +38,8 @@ public CompletionItemKindSetting? CompletionItemKind /// /// Gets or sets a value indicating whether the client supports sending additional context. /// - [DataMember(Name = "contextSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("contextSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ContextSupport { get; @@ -51,8 +49,8 @@ public bool ContextSupport /// /// Gets or sets a value indicating client's default when the completion item doesn't provide an `insertTextMode` property. /// - [DataMember(Name = "insertTextMode")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("insertTextMode")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextMode? InsertTextMode { get; @@ -62,8 +60,8 @@ public InsertTextMode? InsertTextMode /// /// Gets or sets a value indicating whether the client supports capabilities on the completion list. /// - [DataMember(Name = "completionList")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completionList")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionListSetting? CompletionListSetting { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs b/src/Features/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs index c6e0289f2196f..4154beeb6fa7f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum which represents the various ways in which completion can be triggered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum CompletionTriggerKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/ConfigurationItem.cs b/src/Features/LanguageServer/Protocol/Protocol/ConfigurationItem.cs index 28bf61c08039e..51c7596a161c8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ConfigurationItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ConfigurationItem.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents an configuration item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ConfigurationItem { /// /// Gets or sets the scope to get the configuration section for. /// - [DataMember(Name = "scopeUri")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("scopeUri")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonConverter(typeof(DocumentUriConverter))] public Uri? ScopeUri { @@ -31,8 +29,8 @@ public Uri? ScopeUri /// /// Gets or sets the requested configuration section. /// - [DataMember(Name = "section")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("section")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Section { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ConfigurationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ConfigurationParams.cs index c4547e2f08587..3cfc4fd4a19cf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ConfigurationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ConfigurationParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters for the workspace/configuration request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ConfigurationParams { /// /// Gets or sets the ConfigurationItems being requested. /// - [DataMember(Name = "items")] + [JsonPropertyName("items")] public ConfigurationItem[] Items { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/DocumentUriConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/DocumentUriConverter.cs index 1da728f7de61d..4a91a4cacbde4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/DocumentUriConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/DocumentUriConverter.cs @@ -2,59 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using System.Globalization; - using Microsoft.CodeAnalysis.LanguageServer; - using Microsoft.CommonLanguageServerProtocol.Framework; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - - /// - /// TODO: document. - /// - internal class DocumentUriConverter : JsonConverter - { - /// - public override bool CanConvert(Type objectType) - { - return true; - } - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - reader = reader ?? throw new ArgumentNullException(nameof(reader)); - if (reader.TokenType == JsonToken.String) - { - var token = JToken.ReadFrom(reader); - var uri = new Uri(token.ToObject()); +using System; +using System.Text.Json; +using System.Text.Json.Serialization; - return uri; - } - else if (reader.TokenType == JsonToken.Null) - { - return null; - } +namespace Roslyn.LanguageServer.Protocol; - throw new JsonSerializationException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.DocumentUriSerializationError, reader.Value)); - } - - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); +/// +/// TODO: document. +/// +internal class DocumentUriConverter : JsonConverter +{ + public override Uri Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => new(reader.GetString()); - if (value is Uri uri) - { - var token = JToken.FromObject(uri.AbsoluteUri); - token.WriteTo(writer); - } - else - { - throw new ArgumentException($"{nameof(value)} must be of type {nameof(Uri)}"); - } - } - } + public override void Write(Utf8JsonWriter writer, Uri value, JsonSerializerOptions options) + => writer.WriteStringValue(value.AbsoluteUri); } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/JsonConverterCollectionUtilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/JsonConverterCollectionUtilities.cs deleted file mode 100644 index 207ed168f25e6..0000000000000 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/JsonConverterCollectionUtilities.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using Newtonsoft.Json; - - /// - /// Class containing extension method to thread-safely manage operations. - /// - internal static class JsonConverterCollectionUtilities - { - /// - /// Lock used for modifications to Converters collection. - /// - public static readonly object ConvertersLock = new object(); - } -} diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/NaturalObjectConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/NaturalObjectConverter.cs new file mode 100644 index 0000000000000..c69b5f8bfbeb8 --- /dev/null +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/NaturalObjectConverter.cs @@ -0,0 +1,71 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +// copied from https://github.com/dotnet/runtime/issues/98038 to match newtonsoft behavior +internal class NaturalObjectConverter : JsonConverter +{ + public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => ReadObjectCore(ref reader); + + public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options) + { + var runtimeType = value.GetType(); + if (runtimeType == typeof(object)) + { + writer.WriteStartObject(); + writer.WriteEndObject(); + } + else + { + JsonSerializer.Serialize(writer, value, runtimeType, options); + } + } + + private static object? ReadObjectCore(ref Utf8JsonReader reader) + { + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + + case JsonTokenType.False or JsonTokenType.True: + return reader.GetBoolean(); + + case JsonTokenType.Number: + if (reader.TryGetInt32(out var intValue)) + { + return intValue; + } + if (reader.TryGetInt64(out var longValue)) + { + return longValue; + } + + return reader.GetDouble(); + + case JsonTokenType.String: + return reader.GetString(); + + case JsonTokenType.StartArray: + var list = new List(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) + { + var element = ReadObjectCore(ref reader); + list.Add(element); + } + return list; + + case JsonTokenType.StartObject: + return JsonSerializer.Deserialize(ref reader); + + default: + throw new JsonException(); + } + } +} \ No newline at end of file diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/ParameterInformationConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/ParameterInformationConverter.cs index ca7ba65725eb1..ff7e382b22a64 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/ParameterInformationConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/ParameterInformationConverter.cs @@ -2,64 +2,56 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; - /// - /// JsonConverter to correctly deserialize int arrays in the Label param of ParameterInformation. - /// - internal class ParameterInformationConverter : JsonConverter +/// +/// JsonConverter to correctly deserialize int arrays in the Label param of ParameterInformation. +/// +internal class ParameterInformationConverter : JsonConverter +{ + public override ParameterInformation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - /// - public override bool CanWrite => false; + using var document = JsonDocument.ParseValue(ref reader); + var root = document.RootElement; - /// - public override bool CanConvert(Type objectType) - { - return true; - } + var parameter = new ParameterInformation(); - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + if (root.TryGetProperty("label", out var labelElement)) { - var token = JToken.Load(reader); - - var label = ((JObject)token).Property("label", StringComparison.Ordinal); - var documentation = ((JObject)token).Property("documentation", StringComparison.Ordinal); - - var parameter = new ParameterInformation(); - - if (label != null) + if (labelElement.ValueKind == JsonValueKind.Array) { - var value = label.Value; - if (value is JArray arr) - { - var tuple = new Tuple(arr[0].Value(), arr[1].Value()); - parameter.Label = tuple; - } - else - { - // If label is not an array we can serialize it normally - parameter.Label = value.ToObject>>(); - } + parameter.Label = new Tuple(labelElement[0].GetInt32(), labelElement[1].GetInt32()); } - - if (documentation != null) + else { - var value = documentation.Value; - parameter.Documentation = value.ToObject?>(); + parameter.Label = labelElement.Deserialize>>(options); } + } - return parameter; + if (root.TryGetProperty("documentation", out var documentationElement)) + { + parameter.Documentation = documentationElement.Deserialize>(options); } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + return parameter; + } + + public override void Write(Utf8JsonWriter writer, ParameterInformation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WritePropertyName("label"); + JsonSerializer.Serialize(writer, value.Label, options); + + if (value.Documentation != null) { - throw new NotImplementedException(); + writer.WritePropertyName("documentation"); + JsonSerializer.Serialize(writer, value.Documentation, options); } + + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/StringEnumConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/StringEnumConverter.cs index 64d2ae3d53d6e..0fab79be3e263 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/StringEnumConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/StringEnumConverter.cs @@ -2,22 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; using System.ComponentModel; using System.Globalization; using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; using Microsoft.CodeAnalysis.LanguageServer; -using Microsoft.CommonLanguageServerProtocol.Framework; -using Newtonsoft.Json; +namespace Roslyn.LanguageServer.Protocol; /// /// JsonConverter for serializing and deserializing string-based enums. /// /// The actual type implementing . internal class StringEnumConverter - : JsonConverter + : JsonConverter where TStringEnumType : IStringEnum { private static readonly Func CreateEnum; @@ -36,46 +35,30 @@ static StringEnumConverter() CreateEnum = Expression.Lambda>(body, param).Compile(); } - /// - public override bool CanConvert(Type objectType) => objectType == typeof(TStringEnumType); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override TStringEnumType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - reader = reader ?? throw new ArgumentNullException(nameof(reader)); - - if (reader.TokenType == JsonToken.String) + if (reader.TokenType == JsonTokenType.String) { - return CreateEnum((string)reader.Value!); + return CreateEnum(reader.GetString()!); } - else if (reader.TokenType == JsonToken.Null) + else if (reader.TokenType == JsonTokenType.Null) { - return default(TStringEnumType); + return default; } - throw new JsonSerializationException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.StringEnumSerializationError, reader.Value)); + throw new JsonException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.StringEnumSerializationError, reader.GetString())); } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, TStringEnumType value, JsonSerializerOptions options) { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); - - if (value is TStringEnumType kind) - { - writer.WriteValue(kind.Value); - } - else - { - throw new ArgumentException($"{nameof(value)} must be of type {typeof(TStringEnumType).FullName}"); - } + writer.WriteStringValue(value.Value); } /// /// Type converter from to . /// This is required to support . /// - internal class TypeConverter + public class TypeConverter : System.ComponentModel.TypeConverter { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs index 303bc1801deca..d8fb1d10670a9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs @@ -2,269 +2,296 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.CodeAnalysis.LanguageServer; + +namespace Roslyn.LanguageServer.Protocol; +internal class SumConverter : JsonConverterFactory { - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using Microsoft.CodeAnalysis.LanguageServer; - using Microsoft.CommonLanguageServerProtocol.Framework; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - - /// - /// Converter to translate to and from SumTypes. - /// - internal class SumConverter : JsonConverter + public override bool CanConvert(Type typeToConvert) { - private static readonly ConcurrentDictionary SumTypeCache = new ConcurrentDictionary(); + return typeof(ISumType).IsAssignableFrom(typeToConvert); + } - /// - public override bool CanConvert(Type objectType) - { - return typeof(ISumType).IsAssignableFrom(objectType); - } + public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) + { + var converterType = typeof(SumConverter<>).MakeGenericType(typeToConvert); + return (JsonConverter)Activator.CreateInstance(converterType)!; + } - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - reader = reader ?? throw new ArgumentNullException(nameof(reader)); - serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); + internal class SumTypeInfoCache + { + // netstandard1.0 doesn't support Array.Empty +#pragma warning disable CA1825 // Avoid zero-length array allocations. + private static readonly IReadOnlyList EmptyUnionInfos = new UnionTypeInfo[0]; +#pragma warning restore CA1825 // Avoid zero-length array allocations. - // Even if CanConvert only returns true for ISumType, ReadJson is invoked for Nullable> as well - if (reader.TokenType == JsonToken.Null) - { - if (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return null; - } - else - { - // We shouldn't really ever have a non-Nullable SumType being received as null but, if we do, return an "empty" SumType - return Activator.CreateInstance(objectType); - } - } + private readonly IReadOnlyList allUnionTypeInfos; - // objectType will be one of the various SumType variants. In order for this converter to work with all SumTypes it has to use reflection. - // This method works by attempting to deserialize the json into each of the type parameters to a SumType and stops at the first success. - var sumTypeInfoCache = SumTypeCache.GetOrAdd(objectType, (t) => new SumTypeInfoCache(t)); + private readonly IReadOnlyList primitiveUnionTypeInfos; - JToken? token = null; - var applicableUnionTypeInfos = sumTypeInfoCache.GetApplicableInfos(reader.TokenType); + private readonly IReadOnlyList arrayUnionTypeInfos; - for (var i = 0; i < applicableUnionTypeInfos.Count; i++) - { - var unionTypeInfo = applicableUnionTypeInfos[i]; + private readonly IReadOnlyList objectUnionTypeInfos; - if (!IsTokenCompatibleWithType(reader, unionTypeInfo)) - { - continue; - } + public SumTypeInfoCache(Type sumTypeType) + { + var allUnionTypeInfosSet = new List(); + List? primitiveUnionTypeInfosSet = null; + List? arrayUnionTypeInfosSet = null; + List? objectUnionTypeInfosSet = null; - try - { - object? sumValue; - if (token == null && i + 1 == applicableUnionTypeInfos.Count) - { - // We're at the very last entry, we don't need to maintain the JsonReader, can read directly from the JsonReader to avoid the inbetween JObject type. - sumValue = serializer.Deserialize(reader, unionTypeInfo.Type); - } - else - { - if (token == null) - { - token = JToken.ReadFrom(reader); - } + // If the SumType is a nullable extract the underlying type and re-assign + sumTypeType = NormalizeToNonNullable(sumTypeType); - if (unionTypeInfo.KindAttribute is not null && - (token is not JObject jObject || jObject[unionTypeInfo.KindAttribute.KindPropertyName]?.ToString() != unionTypeInfo.KindAttribute.Kind)) - { - continue; - } + var typeInfo = sumTypeType.GetTypeInfo(); + var parameterTypes = typeInfo.GenericTypeArguments; + foreach (var parameterType in parameterTypes) + { + var parameterTypeInfo = NormalizeToNonNullable(parameterType).GetTypeInfo(); + var declaredConstructor = typeInfo.GetConstructor(new Type[] { parameterType }) ?? + throw new ArgumentException(nameof(sumTypeType), "All constructor parameter types must be represented in the generic type arguments of the SumType"); - sumValue = token.ToObject(unionTypeInfo.Type, serializer); - } + var kindAttribute = parameterType.GetCustomAttribute(); + var unionTypeInfo = new UnionTypeInfo(parameterType, declaredConstructor, kindAttribute); + allUnionTypeInfosSet.Add(unionTypeInfo); - object?[] args = [sumValue]; - var sum = unionTypeInfo.Constructor.Invoke(args); - return sum; + if (parameterTypeInfo.IsPrimitive || + parameterTypeInfo == typeof(string) || + typeof(IStringEnum).IsAssignableFrom(parameterTypeInfo)) + { + primitiveUnionTypeInfosSet ??= new List(); + primitiveUnionTypeInfosSet.Add(unionTypeInfo); } - catch + else if (parameterTypeInfo.IsArray) { - continue; + arrayUnionTypeInfosSet ??= new List(); + arrayUnionTypeInfosSet.Add(unionTypeInfo); + } + else + { + objectUnionTypeInfosSet ??= new List(); + objectUnionTypeInfosSet.Add(unionTypeInfo); } } - throw new JsonSerializationException(LanguageServerProtocolResources.NoSumTypeMatch); - } - - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); - - if (value is null) + this.allUnionTypeInfos = allUnionTypeInfosSet; + this.primitiveUnionTypeInfos = primitiveUnionTypeInfosSet ?? EmptyUnionInfos; + this.arrayUnionTypeInfos = arrayUnionTypeInfosSet ?? EmptyUnionInfos; + if ((objectUnionTypeInfosSet?.Count ?? 0) > 1) { - writer.WriteNull(); + // If some types are tagged with a KindAttribute, make sure they are first in the list in order to avoid the wrong type being deserialized + this.objectUnionTypeInfos = objectUnionTypeInfosSet.Where(t => t.KindAttribute is not null).Concat( + objectUnionTypeInfosSet.Where(t => t.KindAttribute is null)).ToList(); } else { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); - - var sumValue = ((ISumType)value!).Value; - - if (sumValue != null) - { - var token = JToken.FromObject(sumValue); - token.WriteTo(writer); - } + this.objectUnionTypeInfos = objectUnionTypeInfosSet ?? EmptyUnionInfos; } } - private static bool IsTokenCompatibleWithType(JsonReader reader, SumTypeInfoCache.UnionTypeInfo unionTypeInfo) + public IReadOnlyList GetApplicableInfos(JsonTokenType startingTokenType) { - var isCompatible = true; - switch (reader.TokenType) + return startingTokenType switch { - case JsonToken.Float: - isCompatible = unionTypeInfo.Type == typeof(double) || - unionTypeInfo.Type == typeof(float); - break; - case JsonToken.Boolean: - isCompatible = unionTypeInfo.Type == typeof(bool); - break; - case JsonToken.Integer: - isCompatible = unionTypeInfo.Type == typeof(int) || - unionTypeInfo.Type == typeof(uint) || - unionTypeInfo.Type == typeof(long) || - unionTypeInfo.Type == typeof(ulong) || - unionTypeInfo.Type == typeof(short) || - unionTypeInfo.Type == typeof(ushort) || - unionTypeInfo.Type == typeof(byte) || - unionTypeInfo.Type == typeof(sbyte) || - unionTypeInfo.Type == typeof(double) || - unionTypeInfo.Type == typeof(float); - break; - case JsonToken.String: - isCompatible = unionTypeInfo.Type == typeof(string) || - typeof(IStringEnum).IsAssignableFrom(unionTypeInfo.Type); - break; - } - - return isCompatible; + JsonTokenType.StartArray + => this.arrayUnionTypeInfos, + JsonTokenType.Number or + JsonTokenType.String or + JsonTokenType.True or + JsonTokenType.False + => this.primitiveUnionTypeInfos, + JsonTokenType.StartObject + => this.objectUnionTypeInfos, + _ => this.allUnionTypeInfos, + }; } - private class SumTypeInfoCache + private static Type NormalizeToNonNullable(Type sumTypeType) { - // netstandard1.0 doesn't support Array.Empty -#pragma warning disable CA1825 // Avoid zero-length array allocations. - private static readonly IReadOnlyList EmptyUnionInfos = new UnionTypeInfo[0]; -#pragma warning restore CA1825 // Avoid zero-length array allocations. + return Nullable.GetUnderlyingType(sumTypeType) ?? sumTypeType; + } - private readonly IReadOnlyList allUnionTypeInfos; + public class UnionTypeInfo + { + // System.Text.Json can pre-compile the generic SumType<> constructor call so we don't need to do it through reflection every time. + internal delegate T StjReader(ref Utf8JsonReader reader, JsonSerializerOptions options); + + private static readonly Type[] expressionLambdaMethodTypes = new[] { typeof(Type), typeof(Expression), typeof(ParameterExpression[]) }; + private static readonly MethodInfo expressionLambdaMethod = typeof(Expression) + .GetMethods() + .Where(mi => + !mi.IsGenericMethod && + mi.Name == "Lambda" && + mi.GetParameters() + .Select(p => p.ParameterType) + .SequenceEqual(expressionLambdaMethodTypes)) + .Single(); + + private static readonly Type[] jsonSerializerDeserializeMethodTypes = new[] { typeof(Utf8JsonReader).MakeByRefType(), typeof(JsonSerializerOptions) }; + private static readonly MethodInfo jsonSerializerDeserializeMethod = typeof(JsonSerializer) + .GetMethods() + .Where(mi => + mi.IsGenericMethod && + mi.Name == "Deserialize" && + mi.GetParameters() + .Select(p => p.ParameterType) + .SequenceEqual(jsonSerializerDeserializeMethodTypes)) + .Single(); + + public UnionTypeInfo(Type type, ConstructorInfo constructor, KindAttribute? kindAttribute) + { + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.Constructor = constructor ?? throw new ArgumentNullException(nameof(constructor)); + this.KindAttribute = kindAttribute; + + var param1 = Expression.Parameter(typeof(Utf8JsonReader).MakeByRefType(), "reader"); + var param2 = Expression.Parameter(typeof(JsonSerializerOptions), "options"); + var body = Expression.New( + constructor, + Expression.Call( + jsonSerializerDeserializeMethod.MakeGenericMethod(type), + param1, + param2)); + var expression = (LambdaExpression)expressionLambdaMethod.Invoke(null, new object[] { typeof(StjReader<>).MakeGenericType(constructor.DeclaringType), body, new[] { param1, param2 } })!; + + StjReaderFunction = expression.Compile(); + } - private readonly IReadOnlyList primitiveUnionTypeInfos; + public Type Type { get; } - private readonly IReadOnlyList arrayUnionTypeInfos; + public ConstructorInfo Constructor { get; } - private readonly IReadOnlyList objectUnionTypeInfos; + public KindAttribute? KindAttribute { get; } - public SumTypeInfoCache(Type sumTypeType) - { - var allUnionTypeInfosSet = new List(); - List? primitiveUnionTypeInfosSet = null; - List? arrayUnionTypeInfosSet = null; - List? objectUnionTypeInfosSet = null; + public object StjReaderFunction { get; } + } + } +} - // If the SumType is a nullable extract the underlying type and re-assign - sumTypeType = NormalizeToNonNullable(sumTypeType); +internal class SumConverter : JsonConverter + where T : struct, ISumType +{ + private static readonly ConcurrentDictionary SumTypeCache = new ConcurrentDictionary(); - var typeInfo = sumTypeType.GetTypeInfo(); - var parameterTypes = typeInfo.GenericTypeArguments; - foreach (var parameterType in parameterTypes) - { - var parameterTypeInfo = NormalizeToNonNullable(parameterType).GetTypeInfo(); - var declaredConstructor = typeInfo.GetConstructor([parameterType]) ?? - throw new ArgumentException(nameof(sumTypeType), "All constructor parameter types must be represented in the generic type arguments of the SumType"); + /// + public override T Read(ref Utf8JsonReader reader, Type objectType, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) + { + // We shouldn't really ever have a non-Nullable SumType being received as null but, if we do, return an "empty" SumType + return (T)Activator.CreateInstance(objectType)!; + } - var kindAttribute = parameterType.GetCustomAttribute(); - var unionTypeInfo = new UnionTypeInfo(parameterType, declaredConstructor, kindAttribute); - allUnionTypeInfosSet.Add(unionTypeInfo); + // objectType will be one of the various SumType variants. In order for this converter to work with all SumTypes it has to use reflection. + // This method works by attempting to deserialize the json into each of the type parameters to a SumType and stops at the first success. + var sumTypeInfoCache = SumTypeCache.GetOrAdd(objectType, (t) => new SumConverter.SumTypeInfoCache(t)); - if (parameterTypeInfo.IsPrimitive || - parameterTypeInfo == typeof(string) || - typeof(IStringEnum).IsAssignableFrom(parameterTypeInfo)) - { - primitiveUnionTypeInfosSet ??= []; - primitiveUnionTypeInfosSet.Add(unionTypeInfo); - } - else if (parameterTypeInfo.IsArray) - { - arrayUnionTypeInfosSet ??= []; - arrayUnionTypeInfosSet.Add(unionTypeInfo); - } - else + var applicableUnionTypeInfos = sumTypeInfoCache.GetApplicableInfos(reader.TokenType); + if (applicableUnionTypeInfos.Count > 0) + { + var backupReader = reader; + if (applicableUnionTypeInfos[0].KindAttribute is { } kindAttribute) + { + using var document = JsonDocument.ParseValue(ref reader); + reader = backupReader; + if (document.RootElement.TryGetProperty(kindAttribute.KindPropertyName, out var value)) + { + var kind = value.GetString(); + for (var i = 0; i < applicableUnionTypeInfos.Count; i++) { - objectUnionTypeInfosSet ??= []; - objectUnionTypeInfosSet.Add(unionTypeInfo); + var unionTypeInfo = applicableUnionTypeInfos[i]; + if (unionTypeInfo.KindAttribute == null) + { + throw new JsonException(LanguageServerProtocolResources.NoSumTypeMatch); + } + + if (unionTypeInfo.KindAttribute.Kind == kind) + { + var result = ((SumConverter.SumTypeInfoCache.UnionTypeInfo.StjReader)unionTypeInfo.StjReaderFunction).Invoke(ref reader, options); + return result; + } } } + } + + for (var i = 0; i < applicableUnionTypeInfos.Count; i++) + { + var unionTypeInfo = applicableUnionTypeInfos[i]; - this.allUnionTypeInfos = allUnionTypeInfosSet; - this.primitiveUnionTypeInfos = primitiveUnionTypeInfosSet ?? EmptyUnionInfos; - this.arrayUnionTypeInfos = arrayUnionTypeInfosSet ?? EmptyUnionInfos; - if ((objectUnionTypeInfosSet?.Count ?? 0) > 1) + if (!IsTokenCompatibleWithType(ref reader, unionTypeInfo)) { - // If some types are tagged with a KindAttribute, make sure they are first in the list in order to avoid the wrong type being deserialized - this.objectUnionTypeInfos = objectUnionTypeInfosSet.Where(t => t.KindAttribute is not null).Concat( - objectUnionTypeInfosSet.Where(t => t.KindAttribute is null)).ToList(); + continue; } - else + + if (unionTypeInfo.KindAttribute != null) { - this.objectUnionTypeInfos = objectUnionTypeInfosSet ?? EmptyUnionInfos; + continue; } - } - public IReadOnlyList GetApplicableInfos(JsonToken startingTokenType) - { - return startingTokenType switch + try { - JsonToken.StartArray - => this.arrayUnionTypeInfos, - JsonToken.Integer or - JsonToken.Float or - JsonToken.Bytes or - JsonToken.String or - JsonToken.Boolean - => this.primitiveUnionTypeInfos, - JsonToken.StartObject - => this.objectUnionTypeInfos, - _ => this.allUnionTypeInfos, - }; + var result = ((SumConverter.SumTypeInfoCache.UnionTypeInfo.StjReader)unionTypeInfo.StjReaderFunction).Invoke(ref reader, options); + return result; + } + catch + { + reader = backupReader; + continue; + } } + } - private static Type NormalizeToNonNullable(Type sumTypeType) - { - return Nullable.GetUnderlyingType(sumTypeType) ?? sumTypeType; - } + throw new JsonException(LanguageServerProtocolResources.NoSumTypeMatch); + } - internal class UnionTypeInfo - { - public UnionTypeInfo(Type type, ConstructorInfo constructor, KindAttribute? kindAttribute) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Constructor = constructor ?? throw new ArgumentNullException(nameof(constructor)); - this.KindAttribute = kindAttribute; - } + /// + public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + { + writer = writer ?? throw new ArgumentNullException(nameof(writer)); - public Type Type { get; } + var sumValue = value.Value; - public ConstructorInfo Constructor { get; } + if (sumValue != null) + { + JsonSerializer.Serialize(writer, sumValue, options); + } + } - public KindAttribute? KindAttribute { get; } - } + private static bool IsTokenCompatibleWithType(ref Utf8JsonReader reader, SumConverter.SumTypeInfoCache.UnionTypeInfo unionTypeInfo) + { + var isCompatible = true; + switch (reader.TokenType) + { + case JsonTokenType.True: + case JsonTokenType.False: + isCompatible = unionTypeInfo.Type == typeof(bool); + break; + case JsonTokenType.Number: + isCompatible = unionTypeInfo.Type == typeof(int) || + unionTypeInfo.Type == typeof(uint) || + unionTypeInfo.Type == typeof(long) || + unionTypeInfo.Type == typeof(ulong) || + unionTypeInfo.Type == typeof(short) || + unionTypeInfo.Type == typeof(ushort) || + unionTypeInfo.Type == typeof(byte) || + unionTypeInfo.Type == typeof(sbyte) || + unionTypeInfo.Type == typeof(double) || + unionTypeInfo.Type == typeof(float); + break; + case JsonTokenType.String: + isCompatible = unionTypeInfo.Type == typeof(string) || + typeof(IStringEnum).IsAssignableFrom(unionTypeInfo.Type); + break; } + + return isCompatible; } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Converters/TextDocumentSyncConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Converters/TextDocumentSyncConverter.cs index 68bb6efadad73..64e236febb743 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Converters/TextDocumentSyncConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Converters/TextDocumentSyncConverter.cs @@ -2,99 +2,48 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol +using System; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.CodeAnalysis.LanguageServer; + +namespace Roslyn.LanguageServer.Protocol; +internal class TextDocumentSyncConverter : JsonConverter { - using System; - using System.Globalization; - using Microsoft.CodeAnalysis.LanguageServer; - using Microsoft.CommonLanguageServerProtocol.Framework; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - - /// - /// Converter which offers custom serialization for enum to a object. - /// - /// - /// This is to support backwards compatibility for the protocol. - /// - internal class TextDocumentSyncConverter : JsonConverter + public override TextDocumentSyncOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - /// - public override bool CanConvert(Type objectType) + if (reader.TokenType == JsonTokenType.Number) { - return true; - } - - /// - /// Deserializes a json value to a object. - /// - /// Reader from which to read json value. - /// Type of the json value. - /// Existing value. - /// Default serializer. - /// A which matches the json value. - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - reader = reader ?? throw new ArgumentNullException(nameof(reader)); - if (reader.TokenType is JsonToken.Float or JsonToken.Integer) - { - // This conversion is modeled after what VS Code does, see https://github.com/Microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L1234 - var textDocSync = new TextDocumentSyncOptions - { - OpenClose = true, - Change = (TextDocumentSyncKind)int.Parse(reader.Value!.ToString(), NumberStyles.Integer, CultureInfo.CurrentCulture), - Save = new SaveOptions - { - IncludeText = false, - }, - }; - - return textDocSync; - } - else if (reader.TokenType == JsonToken.String) - { - return JsonConvert.DeserializeObject(reader.Value!.ToString()); - } - else if (reader.TokenType == JsonToken.StartObject) + // This conversion is modeled after what VS Code does, see https://github.com/microsoft/vscode-languageserver-node/blob/21f4f0af6bf1623483c3e65f36e550bfdb6245a6/client/src/common/client.ts#L1248 + var textDocSync = new TextDocumentSyncOptions { - var token = JToken.ReadFrom(reader); - return token.ToObject(); - } - else if (reader.TokenType == JsonToken.Null) - { - // This conversion is modeled after what VS Code does, see https://github.com/Microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L1234 - var textDocSync = new TextDocumentSyncOptions + OpenClose = true, + Change = (TextDocumentSyncKind)reader.GetInt32(), + Save = new SaveOptions { - OpenClose = true, - Change = TextDocumentSyncKind.None, - Save = new SaveOptions - { - IncludeText = false, - }, - }; - - return textDocSync; - } + IncludeText = false, + }, + }; - throw new JsonSerializationException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.TextDocumentSyncSerializationError, reader.Value)); + return textDocSync; } - - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + else if (reader.TokenType == JsonTokenType.String) + { + var value = reader.GetString()!; + return JsonSerializer.Deserialize(value)!; + } + else if (reader.TokenType == JsonTokenType.StartObject) { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); + return JsonSerializer.Deserialize(ref reader, options)!; + } - if (value is null) - { - writer.WriteNull(); - } - else - { - writer = writer ?? throw new ArgumentNullException(nameof(writer)); + throw new JsonException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.TextDocumentSyncSerializationError, reader.GetString())); + } - var token = JToken.FromObject(value); - token.WriteTo(writer); - } - } + /// + public override void Write(Utf8JsonWriter writer, TextDocumentSyncOptions value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, options); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/CreateFile.cs b/src/Features/LanguageServer/Protocol/Protocol/CreateFile.cs index 8cc16ae3379ff..723850708e18b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CreateFile.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CreateFile.cs @@ -5,29 +5,28 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a create file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [Kind("create")] internal class CreateFile { /// /// Gets the kind value. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Member can't be static since it's part of the protocol")] public string Kind => "create"; /// /// Gets or sets the resource to create. /// - [DataMember(Name = "uri", IsRequired = true)] + [JsonPropertyName("uri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -38,8 +37,8 @@ public Uri Uri /// /// Gets or sets the additional options. /// - [DataMember(Name = "options")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("options")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CreateFileOptions? Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/CreateFileOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/CreateFileOptions.cs index 68fcf7c8e30c5..c8215d3a14223 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/CreateFileOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/CreateFileOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for a create file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class CreateFileOptions { /// /// Gets or sets a value indicating whether the creation should overwrite the file if it already exists. (Overwrite wins over ignoreIfExists). /// - [DataMember(Name = "overwrite")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("overwrite")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Overwrite { get; @@ -29,8 +27,8 @@ public bool Overwrite /// /// Gets or sets a value indicating whether the action should be ignored if the file already exists. /// - [DataMember(Name = "ignoreIfExists")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("ignoreIfExists")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IgnoreIfExists { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs b/src/Features/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs index abcd66aa84d61..d221861d3f169 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs @@ -4,23 +4,21 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a possible result value of the 'textDocument/prepareRename' request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DefaultBehaviorPrepareRename { /// /// Gets or sets a value indicating whether the rename position is valid and the client should use its /// default behavior to compute the rename range. /// - [DataMember(Name = "defaultBehavior")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("defaultBehavior")] + [JsonRequired] public bool DefaultBehavior { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DefinitionOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DefinitionOptions.cs index 2469f7a97db8e..b906658d84875 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DefinitionOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DefinitionOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DefinitionOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DeleteFile.cs b/src/Features/LanguageServer/Protocol/Protocol/DeleteFile.cs index dcc6eed78e854..919093f482981 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DeleteFile.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DeleteFile.cs @@ -5,29 +5,28 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a delete file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [Kind("delete")] internal class DeleteFile { /// /// Gets the kind value. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Member can't be static since it's part of the protocol")] public string Kind => "delete"; /// /// Gets or sets the file to delete. /// - [DataMember(Name = "uri", IsRequired = true)] + [JsonPropertyName("uri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -38,8 +37,8 @@ public Uri Uri /// /// Gets or sets the additional options. /// - [DataMember(Name = "options")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("options")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DeleteFileOptions? Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DeleteFileOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DeleteFileOptions.cs index 5e1c8edd9e884..8764e43d01657 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DeleteFileOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DeleteFileOptions.cs @@ -4,23 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for a create file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DeleteFileOptions { /// /// Gets or sets a value indicating whether the delete operation should be applied recursively if a folder is denoted. (Overwrite wins over ignoreIfNotExists). /// - [DataMember(Name = "recursive")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("recursive")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Recursive { get; @@ -30,8 +27,8 @@ public bool Recursive /// /// Gets or sets a value indicating whether the action should be ignored if the file doesn't exists. /// - [DataMember(Name = "ignoreIfNotExists")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("ignoreIfNotExists")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IgnoreIfNotExists { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Diagnostic.cs b/src/Features/LanguageServer/Protocol/Protocol/Diagnostic.cs index d664f263d5a7b..57def31e7cee4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Diagnostic.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Diagnostic.cs @@ -6,21 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Linq; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a source code diagnostic message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Diagnostic : IEquatable { /// /// Gets or sets the source code range. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -30,8 +28,8 @@ public Range Range /// /// Gets or sets the diagnostic severity. /// - [DataMember(Name = "severity")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("severity")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticSeverity? Severity { get; @@ -44,8 +42,8 @@ public DiagnosticSeverity? Severity /// /// The value can be an , . /// - [DataMember(Name = "code")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("code")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Code { get; @@ -55,8 +53,8 @@ public SumType? Code /// /// Gets or sets an optional value that describes the error code. /// - [DataMember(Name = "codeDescription")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeDescription")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeDescription? CodeDescription { get; @@ -67,8 +65,8 @@ public CodeDescription? CodeDescription /// Gets or sets a human-readable string describing the source of this /// diagnostic, e.g. 'typescript' or 'super lint'. It usually appears in the user interface. /// - [DataMember(Name = "source")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("source")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Source { get; @@ -78,7 +76,7 @@ public string? Source /// /// Gets or sets the diagnostic's message. /// - [DataMember(Name = "message")] + [JsonPropertyName("message")] public string Message { get; @@ -88,8 +86,8 @@ public string Message /// /// Gets or sets the diagnostic's tags. /// - [DataMember(Name = "tags")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticTag[]? Tags { get; @@ -99,8 +97,8 @@ public DiagnosticTag[]? Tags /// /// Gets or sets the diagnostic related information /// - [DataMember(Name = "relatedInformation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("relatedInformation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticRelatedInformation[]? RelatedInformation { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs index e464c6eb9a8a8..4d51c1b96d201 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs @@ -4,29 +4,27 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Server capabilities for pull diagnostics. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DiagnosticOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } /// /// Gets or sets the identifier in which the diagnostics are bucketed by the client. /// - [DataMember(Name = "identifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("identifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Identifier { get; @@ -36,7 +34,7 @@ public string? Identifier /// /// Gets or sets a value indicating whether the language has inter file dependencies. /// - [DataMember(Name = "interFileDependencies")] + [JsonPropertyName("interFileDependencies")] public bool InterFileDependencies { get; @@ -46,7 +44,7 @@ public bool InterFileDependencies /// /// Gets or sets a value indicating whether the server provides support for workspace diagnostics as well. /// - [DataMember(Name = "workspaceDiagnostics")] + [JsonPropertyName("workspaceDiagnostics")] public bool WorkspaceDiagnostics { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs index 549fe02ed56cf..710b99742f84e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; /// /// Diagnostic registration options. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DiagnosticRegistrationOptions : DiagnosticOptions, IStaticRegistrationOptions, ITextDocumentRegistrationOptions { /// /// Gets or sets the document filters for this registration option. /// - [DataMember(Name = "documentSelector")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("documentSelector")] public DocumentFilter[]? DocumentSelector { get; @@ -29,8 +27,8 @@ public DocumentFilter[]? DocumentSelector /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "id")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Id { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs index e62e8058f8cf7..cc3099afe6976 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs @@ -4,7 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents a related message and source code location for a diagnostic. @@ -13,19 +13,18 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DiagnosticRelatedInformation { /// /// Gets or sets the location for the related information. /// - [DataMember(Name = "location")] + [JsonPropertyName("location")] public Location Location { get; set; } /// /// Gets or sets the message for the related information. /// - [DataMember(Name = "message")] + [JsonPropertyName("message")] public string Message { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs index 9840373f3f4c5..0ee406d772ae8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; /// /// Class representing the cancellation data returned from a diagnostic request. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DiagnosticServerCancellationData { /// /// Gets or sets a value indicating whether the client should re-trigger the request. /// - [DataMember(Name = "retriggerRequest")] + [JsonPropertyName("retriggerRequest")] public bool RetriggerRequest { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs index 75c0827e25bf6..b5d623d11f2c9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Client settings for pull diagnostics. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DiagnosticSetting : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether the client supports related documents for document diagnostic pulls. /// - [DataMember(Name = "relatedDocumentSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("relatedDocumentSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RelatedDocumentSupport { get; set; } } \ No newline at end of file diff --git a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs index 1c1640598d134..5aee040d2afc3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing the workspace diagnostic client capabilities. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DiagnosticWorkspaceSetting { /// /// Gets or sets a value indicating whether the client supports a refresh request sent from the server to the client. /// - [DataMember(Name = "refreshSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } } \ No newline at end of file diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs index a9816d3926583..102c94551b080 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter sent with workspace/didChangeConfiguration requests. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidChangeConfigurationParams { /// /// Gets or sets the settings that are applicable to the language server. /// - [DataMember(Name = "settings")] + [JsonPropertyName("settings")] public object Settings { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs index 0a4f9c3934a02..78ac42a0491d8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with textDocument/didChange message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidChangeTextDocumentParams : ITextDocumentParams { /// /// Gets or sets the document that changed. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public VersionedTextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public VersionedTextDocumentIdentifier TextDocument /// /// Gets or sets the content changes. /// - [DataMember(Name = "contentChanges")] + [JsonPropertyName("contentChanges")] public TextDocumentContentChangeEvent[] ContentChanges { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs index 75e21d2e8de99..e090da167da4e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with workspace/didChangeWatchedFiles message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidChangeWatchedFilesParams { /// /// Gets or sets of the collection of file change events. /// - [DataMember(Name = "changes")] + [JsonPropertyName("changes")] public FileEvent[] Changes { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs index f2e1dccc784a4..15a1ccb176d6e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with textDocument/didClose message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidCloseTextDocumentParams : ITextDocumentParams { /// /// Gets or sets the text document identifier. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs index 2d32742a3c94f..ff6ecfacc3ccb 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with textDocument/didOpen message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidOpenTextDocumentParams { /// /// Gets or sets the which represents the text document that was opened. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentItem TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs index aab858ce354e8..b0c24f6e168c2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with a textDocument/didSave message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DidSaveTextDocumentParams : ITextDocumentParams { /// /// Gets or sets the which represents the text document that was saved. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -28,8 +26,8 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the which represents the content of the text document when it was saved. /// - [DataMember(Name = "text")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("text")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Text { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs index dbad3759bf15b..96cf410caca2e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentColorOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentColorParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentColorParams.cs index 7f364f077b7cb..6e5b7506a718b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentColorParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentColorParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/documentColor request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentColorParams : ITextDocumentParams { /// /// Gets or sets the to provide links for. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs index 55cd0c4f38eb7..348274675e055 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol; using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing the document diagnostic request parameters /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DocumentDiagnosticParams : ITextDocumentParams, IPartialResultParams> { /// @@ -23,8 +21,8 @@ internal class DocumentDiagnosticParams : ITextDocumentParams, IPartialResultPar /// Note that the first literal send needs to be either the or /// followed by n literals. /// - [DataMember(Name = Methods.PartialResultTokenName, IsRequired = false)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress>? PartialResultToken { get; @@ -34,7 +32,7 @@ public IProgress /// Gets or sets the to provide diagnostics for. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -44,8 +42,8 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the identifier for which the client is requesting diagnostics for. /// - [DataMember(Name = "identifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("identifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Identifier { get; @@ -55,8 +53,8 @@ public string? Identifier /// /// Gets or sets the result id of a previous diagnostics response if provided. /// - [DataMember(Name = "previousResultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("previousResultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? PreviousResultId { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs index 936ad48f1dbde..9e2c17cb63aef 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs @@ -6,20 +6,19 @@ namespace Roslyn.LanguageServer.Protocol; using System; using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; /// /// Class representing a partial document diagnostic report for a set of related documents. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class DocumentDiagnosticReportPartialResult { /// /// Gets or sets the map of related document diagnostic reports. /// - [DataMember(Name = "relatedDocuments")] + [JsonPropertyName("relatedDocuments")] public Dictionary> RelatedDocuments { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentFilter.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentFilter.cs index d06ad65ed2e9a..da8ed8d6512a1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentFilter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentFilter.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a filter over certain types of documents /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentFilter { /// /// Gets or sets a language id for the filter (e.g. 'typescript'). /// - [DataMember(Name = "language")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("language")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Language { get; @@ -29,8 +27,8 @@ public string? Language /// /// Gets or sets a Uri scheme (e.g. 'file' or 'untitled'). /// - [DataMember(Name = "scheme")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("scheme")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Scheme { get; @@ -40,8 +38,8 @@ public string? Scheme /// /// Gets or sets a glob pattern (e.g. '*.cs'). /// - [DataMember(Name = "pattern")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("pattern")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Pattern { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs index 24f1e6f2008e9..144e53f17087c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the document formatting options for server capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentFormattingOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs index 766dc19e1843e..35f814d3ff9b9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with textDocument/formatting message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentFormattingParams : ITextDocumentParams { /// /// Gets or sets the identifier for the text document to be formatted. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the formatting options. /// - [DataMember(Name = "options")] + [JsonPropertyName("options")] public FormattingOptions Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlight.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlight.cs index 692bc31ab9b6f..ee7ab022fea0f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlight.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlight.cs @@ -6,21 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the response from a textDocument/documentHighlight request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentHighlight { /// /// Gets or sets the range that the highlight applies to. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -30,11 +28,11 @@ public Range Range /// /// Gets or sets the kind of highlight. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] [DefaultValue(DocumentHighlightKind.Text)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public DocumentHighlightKind Kind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightKind.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightKind.cs index 60375fb94cb92..7ec465f1fc335 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum representing the different types of document highlight. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum DocumentHighlightKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs index 40333c450d29b..c01c7eb95adb7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentHighlightOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs index 65107dad7c797..9fed8bdcc35fe 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs @@ -5,8 +5,7 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/documentHighlight request. @@ -20,8 +19,8 @@ internal class DocumentHighlightParams /// /// Gets or sets the value of the PartialResultToken instance. /// - [DataMember(Name = "partialResultToken")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("partialResultToken")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentLink.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentLink.cs index 91e3d65073174..a4fe991aef507 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentLink.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentLink.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the response of a textDocument/documentLink request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentLink { /// /// Gets or sets the range the link applies to. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -29,9 +27,9 @@ public Range Range /// /// Gets or sets the uri that the link points to. /// - [DataMember(Name = "target")] + [JsonPropertyName("target")] [JsonConverter(typeof(DocumentUriConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Uri? Target { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs index 42625d49b51a9..c01515f8ae949 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the document link options for server capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentLinkOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether or not the server supports resolve providers. /// - [DataMember(Name = "resolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider { get; @@ -29,8 +27,8 @@ public bool ResolveProvider /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs index 58aaf921ffbc4..780a15fceded5 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/documentLink request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentLinkParams : ITextDocumentParams { /// /// Gets or sets the to provide links for. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs index c358c3dc1b7be..13105e53003d7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for on type formatting. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentOnTypeFormattingOptions { /// /// Gets or sets the first trigger character. /// - [DataMember(Name = "firstTriggerCharacter")] + [JsonPropertyName("firstTriggerCharacter")] public string FirstTriggerCharacter { get; @@ -28,8 +26,8 @@ public string FirstTriggerCharacter /// /// Gets or sets additional trigger characters. /// - [DataMember(Name = "moreTriggerCharacter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("moreTriggerCharacter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? MoreTriggerCharacter { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs index eda0db4a326e2..919c36c1275ae 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/onTypeFormatting request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentOnTypeFormattingParams : TextDocumentPositionParams { /// /// Gets or sets the character that was typed. /// - [DataMember(Name = "ch")] + [JsonPropertyName("ch")] public string Character { get; @@ -27,7 +26,7 @@ public string Character /// /// Gets or sets the for the request. /// - [DataMember(Name = "options")] + [JsonPropertyName("options")] public FormattingOptions Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs index 8dc450883122a..1c4cbe2ce2c7c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the document range formatting options for server capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentRangeFormattingOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs index 103881f93ef17..104830b737a1b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that is sent with textDocument/rangeFormatting message. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentRangeFormattingParams : ITextDocumentParams { /// /// Gets or sets the identifier for the text document to be formatted. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the selection range to be formatted. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -37,7 +36,7 @@ public Range Range /// /// Gets or sets the formatting options. /// - [DataMember(Name = "options")] + [JsonPropertyName("options")] public FormattingOptions Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbol.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbol.cs index bb1f719958c7b..e9110e2f82bc0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbol.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbol.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be @@ -14,13 +13,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentSymbol { /// /// Gets or sets the name of this symbol. /// - [DataMember(IsRequired = true, Name = "name")] + [JsonPropertyName("name")] + [JsonRequired] public string Name { get; @@ -30,8 +29,8 @@ public string Name /// /// Gets or sets more detail for this symbol, e.g the signature of a function. /// - [DataMember(Name = "detail")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("detail")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Detail { get; @@ -41,7 +40,7 @@ public string? Detail /// /// Gets or sets the of this symbol. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] public SymbolKind Kind { get; @@ -51,8 +50,8 @@ public SymbolKind Kind /// /// Gets or sets a value indicating whether this symbol is deprecated. /// - [DataMember(Name = "deprecated")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("deprecated")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Deprecated { get; @@ -64,7 +63,8 @@ public bool Deprecated /// like comments.This information is typically used to determine if the clients cursor is /// inside the symbol to reveal in the symbol in the UI. /// - [DataMember(IsRequired = true, Name = "range")] + [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; @@ -75,7 +75,8 @@ public Range Range /// Gets or sets the range that should be selected and revealed when this symbol is being picked, e.g the name of a function. /// Must be contained by the `range`. /// - [DataMember(IsRequired = true, Name = "selectionRange")] + [JsonPropertyName("selectionRange")] + [JsonRequired] public Range SelectionRange { get; @@ -85,8 +86,8 @@ public Range SelectionRange /// /// Gets or sets the children of this symbol, e.g. properties of a class. /// - [DataMember(Name = "children")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("children")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentSymbol[]? Children { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs index 2ea84c8ca9ca6..9298ac3d94632 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentSymbolOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs index 3ba1eaa41230b..b12f359aec536 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the parameter sent with textDocument/documentSymbol requests. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentSymbolParams : ITextDocumentParams { /// /// Gets or sets the text document. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs index f1df03c9304ef..6b4274a7d9fdc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the initialization setting for document symbols. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class DocumentSymbolSetting : DynamicRegistrationSetting { /// /// Gets or sets the capabilities. /// - [DataMember(Name = "symbolKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("symbolKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SymbolKindSetting? SymbolKind { get; @@ -29,8 +27,8 @@ public SymbolKindSetting? SymbolKind /// /// Gets or sets a value indicating whether the document has hierarchical symbol support. /// - [DataMember(Name = "hierarchicalDocumentSymbolSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("hierarchicalDocumentSymbolSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool HierarchicalDocumentSymbolSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs index 095b552f61176..9bc210064c78f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs @@ -4,13 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a setting that can be dynamically registered. /// - [DataContract] internal class DynamicRegistrationSetting { /// @@ -32,8 +30,8 @@ public DynamicRegistrationSetting(bool value) /// /// Gets or sets a value indicating whether setting can be dynamically registered. /// - [DataMember(Name = "dynamicRegistration")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("dynamicRegistration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DynamicRegistration { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs index 6cdae0d11cafc..d79e56516f134 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for execute command support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ExecuteCommandOptions : IWorkDoneProgressOptions { /// /// Gets or sets the commands that are to be executed on the server. /// - [DataMember(Name = "commands")] + [JsonPropertyName("commands")] public string[] Commands { get; @@ -28,8 +26,8 @@ public string[] Commands /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs index d9c934063e7ba..6269066a2ad07 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from client to server for the workspace/executeCommand request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ExecuteCommandParams { /// /// Gets or sets the command identifier associated with the command handler. /// - [DataMember(Name = "command")] + [JsonPropertyName("command")] public string Command { get; @@ -28,8 +26,8 @@ public string Command /// /// Gets or sets the arguments that the command should be invoked with. /// - [DataMember(Name = "arguments")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("arguments")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object[]? Arguments { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionConverter.cs index 70f3ed31e8acb..dd53e04c4e9f6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionConverter.cs @@ -5,7 +5,8 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using Newtonsoft.Json; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Converter used to serialize and deserialize classes extending types defined in the @@ -14,28 +15,46 @@ namespace Roslyn.LanguageServer.Protocol /// Base class that is specified in the /// Microsoft.VisualStudio.LanguageServer.Protocol package. /// Extension class that extends TBase. - internal class VSExtensionConverter : JsonConverter - where TExtension : TBase + internal class VSExtensionConverter : JsonConverter + where TExtension : TBase { - /// - public override bool CanWrite => false; + private JsonSerializerOptions? _trimmedOptions; - /// - public override bool CanConvert(Type objectType) + public override TBase? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - return objectType == typeof(TBase); + return JsonSerializer.Deserialize(ref reader, options); } - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, TBase value, JsonSerializerOptions options) { - return serializer.Deserialize(reader); + // System.Text.Json doesn't serialize properties from derived classes by default, and there's no 'readonly' converters + // like Newtonsoft has. + if (value is TExtension extension) + { + JsonSerializer.Serialize(writer, extension, options); + } + else + { + // There's no ability to fallback to a 'default' serialization, so we clone our options + // and exclude this converter from it to prevent a stack overflow. + JsonSerializer.Serialize(writer, (object)value!, DropConverter(options)); + } } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + private JsonSerializerOptions DropConverter(JsonSerializerOptions options) { - throw new NotImplementedException(); + if (_trimmedOptions != null) + { + return _trimmedOptions; + } + + lock (this) + { + options = new System.Text.Json.JsonSerializerOptions(options); + options.Converters.Remove(this); + _trimmedOptions = options; + return options; + } } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs index 51ce11b3bf2bc..0cd191528ca56 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs @@ -2,56 +2,56 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; +/// +/// Utility functions to simplify working with the Visual Studio extensions to the Language Server Protocol. +/// +internal static class VSExtensionUtilities +{ /// - /// Utility functions to simplify working with the Visual Studio extensions to the Language Server Protocol. + /// Adds to the allowing to + /// deserialize the JSON stream into objects which include Visual Studio specific extensions. + /// + /// For example, it allows to correctly deserialize the entries of a + /// 'codeAction/resolve' request into objects even if + /// is defined as an array of . /// - internal static class VSExtensionUtilities + internal static void AddVSExtensionConverters(this JsonSerializerOptions options) { - /// - /// Adds to the allowing to - /// deserialize the JSON stream into objects which include Visual Studio specific extensions. - /// - /// For example, it allows to correctly deserialize the entries of a - /// 'codeAction/resolve' request into objects even if - /// is defined as an array of . - /// - /// - /// If is used in parallel to the execution of this method, - /// its access needs to be synchronized with this method call, to guarantee that the - /// collection is not modified when is in use. - /// - /// Instance of to be configured. - public static void AddVSExtensionConverters(this JsonSerializer serializer) - { - // Reading the number of converters before we start adding new ones - var existingConvertersCount = serializer.Converters.Count; + AddConverters(options.Converters); + } - TryAddConverter(); - TryAddConverter(); - TryAddConverter(); - TryAddConverter(); - TryAddConverter(); + private static void AddConverters(IList converters) + { + // Reading the number of converters before we start adding new ones + var existingConvertersCount = converters.Count; + + TryAddConverter(); + TryAddConverter(); + TryAddConverter(); + TryAddConverter(); + TryAddConverter(); - void TryAddConverter() - where TExtension : TBase + void TryAddConverter() + where TExtension : TBase + { + for (var i = 0; i < existingConvertersCount; i++) { - for (var i = 0; i < existingConvertersCount; i++) + var existingConverterType = converters[i].GetType(); + if (existingConverterType.IsGenericType && + (existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) || existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>)) && + existingConverterType.GenericTypeArguments[0] == typeof(TBase)) { - var existingConverterType = serializer.Converters[i].GetType(); - if (existingConverterType.IsGenericType && - existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) && - existingConverterType.GenericTypeArguments[0] == typeof(TBase)) - { - return; - } + return; } - - serializer.Converters.Add(new VSExtensionConverter()); } + + converters.Add(new VSExtensionConverter()); } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnostic.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnostic.cs index 4ac6e47c0a682..aa14da1ed5762 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnostic.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnostic.cs @@ -4,65 +4,63 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// extends providing additional properties used by Visual Studio. /// - [DataContract] internal class VSDiagnostic : Diagnostic { /// /// Gets or sets the project and context (e.g. Win32, MacOS, etc.) in which the diagnostic was generated. /// - [DataMember(Name = "_vs_projects")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projects")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSDiagnosticProjectInformation[]? Projects { get; set; } /// /// Gets or sets an expanded description of the diagnostic. /// - [DataMember(Name = "_vs_expandedMessage")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_expandedMessage")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ExpandedMessage { get; set; } /// /// Gets or sets a message shown when the user hovers over an error. If , then /// is used (use to prevent a tool tip from being shown). /// - [DataMember(Name = "_vs_toolTip")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_toolTip")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ToolTip { get; set; } /// /// Gets or sets a non-human-readable identier allowing consolidation of multiple equivalent diagnostics /// (e.g. the same syntax error from builds targeting different platforms). /// - [DataMember(Name = "_vs_identifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_identifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Identifier { get; set; } /// /// Gets or sets a string describing the diagnostic types (e.g. Security, Performance, Style, etc.). /// - [DataMember(Name = "_vs_diagnosticType")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_diagnosticType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? DiagnosticType { get; set; } /// /// Gets or sets a rank associated with this diagnostic, used for the default sort. /// will be used if no rank is specified. /// - [DataMember(Name = "_vs_diagnosticRank")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_diagnosticRank")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSDiagnosticRank? DiagnosticRank { get; set; } /// /// Gets or sets an ID used to associate this diagnostic with a corresponding line in the output window. /// - [DataMember(Name = "_vs_outputId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_outputId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? OutputId { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnosticProjectInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnosticProjectInformation.cs index c2a84f512d6eb..7cfc6d2346dc2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnosticProjectInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSDiagnosticProjectInformation.cs @@ -4,35 +4,33 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// represents the project and context in which the is generated. /// - [DataContract] internal class VSDiagnosticProjectInformation { /// /// Gets or sets a human-readable identifier for the project in which the diagnostic was generated. /// - [DataMember(Name = "_vs_projectName")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projectName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ProjectName { get; set; } /// /// Gets or sets a human-readable identifier for the build context (e.g. Win32 or MacOS) /// in which the diagnostic was generated. /// - [DataMember(Name = "_vs_context")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_context")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Context { get; set; } /// /// Gets or sets the unique identifier for the project in which the diagnostic was generated. /// - [DataMember(Name = "_vs_projectIdentifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projectIdentifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ProjectIdentifier { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSGetProjectContextsParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSGetProjectContextsParams.cs index f02ebbc2bf112..e357fe57b13ae 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSGetProjectContextsParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSGetProjectContextsParams.cs @@ -4,19 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// represents the parameter that is sent /// with the 'textDocument/_vs_getProjectContexts' request. /// - [DataContract] internal class VSGetProjectContextsParams { /// /// Gets or sets the document for which project contexts are queried. /// - [DataMember(Name = "_vs_textDocument")] + [JsonPropertyName("_vs_textDocument")] public TextDocumentItem TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSImageId.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSImageId.cs index ed16c06838842..87a5115add07d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSImageId.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSImageId.cs @@ -5,7 +5,7 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// represents the unique identifier for a Visual Studio image asset. @@ -13,13 +13,12 @@ namespace Roslyn.LanguageServer.Protocol /// A list of valid image ids can be retrieved from the KnownMonikers class /// from the Visual Studio SDK. /// - [DataContract] internal class VSImageId : IEquatable { /// /// Gets or sets the component of the unique identifier. /// - [DataMember(Name = "_vs_guid")] + [JsonPropertyName("_vs_guid")] public Guid Guid { get; @@ -29,7 +28,7 @@ public Guid Guid /// /// Gets or sets the integer component of the unique identifier. /// - [DataMember(Name = "_vs_id")] + [JsonPropertyName("_vs_id")] public int Id { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSLocation.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSLocation.cs index a34ea77a25296..1a68fa04259ca 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSLocation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSLocation.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// extends providing additional properties used by Visual Studio. /// - [DataContract] internal class VSLocation : Location { /// /// Gets or sets the project name to be displayed to user. /// - [DataMember(Name = "_vs_projectName")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projectName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ProjectName { get; set; } /// @@ -25,8 +23,8 @@ internal class VSLocation : Location /// In case the actual path on disk would be confusing for users, this should be a friendly display name. /// This doesn't have to correspond to a real file path, but must be parsable by the method. /// - [DataMember(Name = "_vs_displayPath")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_displayPath")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? DisplayPath { get; set; } } } \ No newline at end of file diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContext.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContext.cs index de37989753381..528a49257dea7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContext.cs @@ -5,18 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// represents a project context. /// - [DataContract] internal class VSProjectContext : IEquatable { /// /// Gets or sets the label for the project context. /// - [DataMember(Name = "_vs_label", IsRequired = true)] + [JsonPropertyName("_vs_label")] + [JsonRequired] public string Label { get; @@ -26,7 +26,8 @@ public string Label /// /// Gets or sets the unique identifier of the project context. /// - [DataMember(Name = "_vs_id", IsRequired = true)] + [JsonPropertyName("_vs_id")] + [JsonRequired] public string Id { get; @@ -36,7 +37,7 @@ public string Id /// /// Gets or sets the context kind of the project context which is used to determine its associated icon. /// - [DataMember(Name = "_vs_kind")] + [JsonPropertyName("_vs_kind")] public VSProjectKind Kind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContextList.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContextList.cs index 4c1ee69a0bbff..2cca38acf08ac 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContextList.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectContextList.cs @@ -4,19 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// represents the response to the /// 'textDocument/_vs_getProjectContexts' request. /// - [DataContract] internal class VSProjectContextList { /// /// Gets or sets the document contexts associated with a text document. /// - [DataMember(Name = "_vs_projectContexts")] + [JsonPropertyName("_vs_projectContexts")] public VSProjectContext[] ProjectContexts { get; @@ -26,7 +25,7 @@ public VSProjectContext[] ProjectContexts /// /// Gets or sets the index of the default entry of the array. /// - [DataMember(Name = "_vs_defaultIndex")] + [JsonPropertyName("_vs_defaultIndex")] public int DefaultIndex { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectKind.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectKind.cs index 6a541c5bce361..467374d98fdce 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSProjectKind.cs @@ -4,12 +4,9 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// represents the various kinds of contexts. /// - [DataContract] internal enum VSProjectKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSServerCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSServerCapabilities.cs index 3cd00971b4a28..0605c8afbba7f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSServerCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSServerCapabilities.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// extends allowing to provide /// additional capabilities supported by Visual Studio. /// - [DataContract] internal class VSServerCapabilities : ServerCapabilities { /// /// Gets or sets a value indicating whether the server supports the /// 'textDocument/_vs_getProjectContexts' request. /// - [DataMember(Name = "_vs_projectContextProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_projectContextProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ProjectContextProvider { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs index 62b8b120be35e..84d77d40b6219 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs @@ -4,34 +4,32 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// extends providing additional properties used by Visual Studio. /// - [DataContract] internal class VSSymbolInformation : SymbolInformation { /// /// Gets or sets the icon associated with the symbol. If specified, this icon is used instead of . /// - [DataMember(Name = "_vs_icon")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_icon")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSImageId? Icon { get; set; } /// /// Gets or sets the description of the symbol. /// - [DataMember(Name = "_vs_description")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_description")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Description { get; set; } /// /// Gets or sets the hint text for the symbol. /// - [DataMember(Name = "_vs_hintText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_hintText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? HintText { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSTextDocumentIdentifier.cs b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSTextDocumentIdentifier.cs index 2cffba1c8d1d8..519e178848056 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSTextDocumentIdentifier.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Extensions/VSTextDocumentIdentifier.cs @@ -5,20 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// extends providing additional properties used by Visual Studio. /// - [DataContract] internal class VSTextDocumentIdentifier : TextDocumentIdentifier, IEquatable { /// /// Gets or sets the project context of the text document. /// - [DataMember(Name = "_vs_projectContext")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projectContext")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSProjectContext? ProjectContext { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FileEvent.cs b/src/Features/LanguageServer/Protocol/Protocol/FileEvent.cs index 7d437e7bd1acb..6133abc68ec98 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FileEvent.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FileEvent.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a file change event. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FileEvent { /// /// Gets or sets the URI of the file. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -30,7 +28,7 @@ public Uri Uri /// /// Gets or sets the file change type. /// - [DataMember(Name = "type")] + [JsonPropertyName("type")] public FileChangeType FileChangeType { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRange.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRange.cs index a45d49f3f9d5f..78f0c975a205d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRange.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRange.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a folding range in a document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FoldingRange { /// /// Gets or sets the start line value. /// - [DataMember(Name = "startLine")] + [JsonPropertyName("startLine")] public int StartLine { get; @@ -28,8 +26,8 @@ public int StartLine /// /// Gets or sets the start character value. /// - [DataMember(Name = "startCharacter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("startCharacter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? StartCharacter { get; @@ -39,7 +37,7 @@ public int? StartCharacter /// /// Gets or sets the end line value. /// - [DataMember(Name = "endLine")] + [JsonPropertyName("endLine")] public int EndLine { get; @@ -49,8 +47,8 @@ public int EndLine /// /// Gets or sets the end character value. /// - [DataMember(Name = "endCharacter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("endCharacter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? EndCharacter { get; @@ -60,8 +58,8 @@ public int? EndCharacter /// /// Gets or sets the folding range kind. /// - [DataMember(Name = "kind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("kind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public FoldingRangeKind? Kind { get; @@ -71,8 +69,8 @@ public FoldingRangeKind? Kind /// /// Gets or sets the collapsedText. /// - [DataMember(Name = "collapsedText")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("collapsedText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? CollapsedText { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs index 05e12df4907f0..bf807c451becf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing various code action kinds. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct FoldingRangeKind(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeOptions.cs index c68fcaaa0a074..273d431e6da95 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the folding range provider options for initialization. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FoldingRangeOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs index ac57b23d4f24c..fed7123c0cb67 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the folding range request parameter. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FoldingRangeParams : ITextDocumentParams { /// /// Gets or sets the text document associated with the folding range request. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs index f4c10c48e1f26..e57fde0b348aa 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the folding range setting for initialization. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FoldingRangeSetting : DynamicRegistrationSetting { /// /// Gets or sets the range limit for folding ranges. /// - [DataMember(Name = "rangeLimit")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("rangeLimit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? RangeLimit { get; @@ -29,8 +27,8 @@ public int? RangeLimit /// /// Gets or sets a value indicating whether if client only supports entire line folding only. /// - [DataMember(Name = "lineFoldingOnly")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("lineFoldingOnly")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LineFoldingOnly { get; @@ -40,8 +38,8 @@ public bool LineFoldingOnly /// /// Gets or sets a value indicating the specific options for the folding range. /// - [DataMember(Name = "foldingRange")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("foldingRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public FoldingRangeSettingOptions? FoldingRange { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs index f1a1fe75e4584..35b524fd67379 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the specific options for the folding range. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FoldingRangeSettingOptions : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether if client supports collapsedText on folding ranges. /// - [DataMember(Name = "collapsedText")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("collapsedText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool CollapsedText { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FormattingOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/FormattingOptions.cs index e1787620e30f5..c7385acedce78 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FormattingOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FormattingOptions.cs @@ -5,22 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents formatting options. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class FormattingOptions { /// /// Gets or sets the number of spaces to be inserted per tab. /// - [DataMember(Name = "tabSize")] + [JsonPropertyName("tabSize")] public int TabSize { get; @@ -30,7 +27,7 @@ public int TabSize /// /// Gets or sets a value indicating whether tabs should be spaces. /// - [DataMember(Name = "insertSpaces")] + [JsonPropertyName("insertSpaces")] public bool InsertSpaces { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/FullDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/FullDocumentDiagnosticReport.cs index ab55018017cb3..17eaadd82514a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/FullDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/FullDocumentDiagnosticReport.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a diagnostic report with a full set of problems. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Full)] internal class FullDocumentDiagnosticReport { /// /// Gets the kind of this report. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] #pragma warning disable CA1822 // Mark members as static public string Kind => DocumentDiagnosticReportKind.Full; #pragma warning restore CA1822 // Mark members as static @@ -27,8 +25,8 @@ internal class FullDocumentDiagnosticReport /// /// Gets or sets the optional result id. /// - [DataMember(Name = "resultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ResultId { get; @@ -38,7 +36,7 @@ public string? ResultId /// /// Gets or sets the diagnostics in this report. /// - [DataMember(Name = "items")] + [JsonPropertyName("items")] public Diagnostic[] Items { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Hover.cs b/src/Features/LanguageServer/Protocol/Protocol/Hover.cs index 339ca873bcc6d..27c8399906956 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Hover.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Hover.cs @@ -4,15 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the data returned by a textDocument/hover request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Hover { /// @@ -21,7 +19,7 @@ internal class Hover /// If the object is not an array it can be of type , , or . /// // This is nullable because in VS we allow null when VSInternalHover.RawContent is specified instead of Contents - [DataMember(Name = "contents")] + [JsonPropertyName("contents")] public SumType[], MarkupContent>? Contents { get; @@ -31,8 +29,8 @@ public SumType[], MarkupCont /// /// Gets or sets the range over which the hover applies. /// - [DataMember(Name = "range")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Range? Range { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/HoverOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/HoverOptions.cs index 0d5001c8105d4..51c8a83658f0d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/HoverOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/HoverOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the server hover support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class HoverOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/HoverSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/HoverSetting.cs index f1d195fb0a6d8..e19b54f371fe0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/HoverSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/HoverSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the initialization setting for hover. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class HoverSetting : DynamicRegistrationSetting { /// /// Gets or sets the values supported. /// - [DataMember(Name = "contentFormat")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("contentFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public MarkupKind[]? ContentFormat { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ImplementationOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/ImplementationOptions.cs index 8a4cc0363a9bd..afd33c2190764 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ImplementationOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ImplementationOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ImplementationOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/InitializeError.cs b/src/Features/LanguageServer/Protocol/Protocol/InitializeError.cs index 756906f6d62c7..070add9aecfd7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InitializeError.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InitializeError.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the error type sent when the initialize request fails. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InitializeError { /// /// Gets or sets a value indicating whether or not to retry. /// - [DataMember(Name = "retry")] + [JsonPropertyName("retry")] public bool Retry { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InitializeErrorCode.cs b/src/Features/LanguageServer/Protocol/Protocol/InitializeErrorCode.cs index 3f412b17040a5..63a3ed253409c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InitializeErrorCode.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InitializeErrorCode.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum representing the possible reasons for an initialization error. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum InitializeErrorCode { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/InitializeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/InitializeParams.cs index a3f76104ae979..c0f68e4f7ad23 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InitializeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InitializeParams.cs @@ -6,22 +6,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Class which represents the parameter sent with an initialize method request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InitializeParams { /// /// Gets or sets the ID of the process which launched the language server. /// - [DataMember(Name = "processId")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("processId")] public int? ProcessId { get; @@ -35,8 +33,8 @@ public int? ProcessId /// Uses IETF language tags as the value's syntax. /// (See https://en.wikipedia.org/wiki/IETF_language_tag) /// - [DataMember(Name = "locale")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("locale")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Locale { get; @@ -46,8 +44,8 @@ public string? Locale /// /// Gets or sets the workspace root path. /// - [DataMember(Name = "rootPath")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("rootPath")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [Obsolete("Deprecated in favour of RootUri")] public string? RootPath { @@ -61,8 +59,7 @@ public string? RootPath /// /// This should be a string representation of an URI. /// - [DataMember(Name = "rootUri")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("rootUri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri? RootUri { @@ -73,8 +70,8 @@ public Uri? RootUri /// /// Gets or sets the initialization options as specified by the client. /// - [DataMember(Name = "initializationOptions")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("initializationOptions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? InitializationOptions { get; @@ -84,7 +81,7 @@ public object? InitializationOptions /// /// Gets or sets the capabilities supported by the client. /// - [DataMember(Name = "capabilities")] + [JsonPropertyName("capabilities")] public ClientCapabilities Capabilities { get; @@ -94,9 +91,9 @@ public ClientCapabilities Capabilities /// /// Gets or sets the initial trace setting. /// - [DataMember(Name = "trace")] + [JsonPropertyName("trace")] [DefaultValue(typeof(TraceSetting), "off")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public TraceSetting Trace { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InitializeResult.cs b/src/Features/LanguageServer/Protocol/Protocol/InitializeResult.cs index 8970f738ee2b2..b3cf86842bdfd 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InitializeResult.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InitializeResult.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents the result returned by the initialize request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InitializeResult { /// /// Gets or sets the server capabilities. /// - [DataMember(Name = "capabilities")] + [JsonPropertyName("capabilities")] public ServerCapabilities Capabilities { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHint.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHint.cs index e710324261479..3b934f479d901 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHint.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHint.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A class representing inlay hints that appear next to parameters or types. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHint { /// /// Gets or sets the position that the inlay hint applies to. /// - [DataMember(Name = "position")] + [JsonPropertyName("position")] public Position Position { get; @@ -28,7 +26,7 @@ public Position Position /// /// Gets or sets the label associated with this inlay hint. /// - [DataMember(Name = "label")] + [JsonPropertyName("label")] public SumType Label { get; @@ -38,8 +36,8 @@ public SumType Label /// /// Gets or sets the InlayHintKind associated with this inlay hint. /// - [DataMember(Name = "kind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("kind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintKind? Kind { get; @@ -49,8 +47,8 @@ public InlayHintKind? Kind /// /// Gets or sets the TextEdits associated with this inlay hint. /// - [DataMember(Name = "textEdits")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("textEdits")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextEdit[]? TextEdits { get; @@ -60,8 +58,8 @@ public TextEdit[]? TextEdits /// /// Gets or sets the tooltip of this inlay hint. /// - [DataMember(Name = "tooltip")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("tooltip")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? ToolTip { get; @@ -71,8 +69,8 @@ public SumType? ToolTip /// /// Gets or sets the padding before this inlay hint. /// - [DataMember(Name = "paddingLeft")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("paddingLeft")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PaddingLeft { get; @@ -82,8 +80,8 @@ public bool PaddingLeft /// /// Gets or sets the padding after this inlay hint. /// - [DataMember(Name = "paddingRight")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("paddingRight")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PaddingRight { get; @@ -93,8 +91,8 @@ public bool PaddingRight /// /// Gets or sets the data that should be preserved between a textDocument/inlayHint request and a inlayHint/resolve request. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintKind.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintKind.cs index 26b3d742d0007..9e8ccb1548903 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum values for inlay hint kinds. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum InlayHintKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs index f3ae678a2f27f..1946a23322ced 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using Newtonsoft.Json; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// A class representing inlay hint label parts. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintLabelPart { /// /// Gets or sets the value associated with this label part. /// - [DataMember(Name = "value")] + [JsonPropertyName("value")] public string Value { get; @@ -28,8 +26,8 @@ public string Value /// /// Gets or sets the tooltip of this label part. /// - [DataMember(Name = "tooltip")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("tooltip")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public SumType? ToolTip { get; @@ -39,8 +37,8 @@ public SumType? ToolTip /// /// Gets or sets the location of this label part. /// - [DataMember(Name = "location")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("location")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Location? Location { get; @@ -50,8 +48,8 @@ public Location? Location /// /// Gets or sets the command of this label part. /// - [DataMember(Name = "command")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("command")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Command? Command { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintOptions.cs index b86910b8786b0..ce9e1c5aef33a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintOptions.cs @@ -4,29 +4,27 @@ namespace Roslyn.LanguageServer.Protocol { - using Newtonsoft.Json; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Server capabilities for inlay hints. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } /// /// Gets or sets a value indicating whether or not the inlay hints support has a resolve provider. /// - [DataMember(Name = "resolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintParams.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintParams.cs index 84556a6ec5a3f..9761b7c09c83d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for a textDocument/inlayHint request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintParams : ITextDocumentParams { /// /// Gets or sets the document identifier to fetch inlay hints results for. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the range to fetch inlay hints results for. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs index 5825a4c023ac5..9df07a8275017 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using Newtonsoft.Json; - using System.Runtime.Serialization; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Inlay hint registration options. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintRegistrationOptions : InlayHintOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions { /// /// Gets or sets the document filters for this registration option. /// - [DataMember(Name = "documentSelector")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("documentSelector")] public DocumentFilter[]? DocumentSelector { get; @@ -29,8 +27,8 @@ public DocumentFilter[]? DocumentSelector /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "id")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Id { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs index 560985840651c..25d1c6a154cc3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing settings for inlayHint/resolve support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintResolveSupportSetting { /// /// Gets or sets a value indicating the properties that a client can resolve lazily. /// - [DataMember(Name = "properties")] + [JsonPropertyName("properties")] public string[] Properties { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintSetting.cs index edce450da136b..d6f8008ba47b6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintSetting.cs @@ -4,23 +4,21 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing settings for inlay hint support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintSetting : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether the client supports /// resolving lazily on an inlay hint. /// - [DataMember(Name = "resolveSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resolveSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintResolveSupportSetting? ResolveSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs index 5060f0e640602..7308f9b3d2ec5 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Newtonsoft.Json; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; namespace Roslyn.LanguageServer.Protocol { @@ -12,14 +11,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InlayHintWorkspaceSetting { /// /// Gets or sets a value indicating whether the client supports a refresh request sent from the server to the client. /// - [DataMember(Name = "refreshSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs b/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs index 9f34cd35362cd..44c06ee7f3aef 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// A special text edit to provide an insert and a replace operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InsertReplaceEdit { /// /// Gets or sets the string to be inserted. /// - [DataMember(Name = "newText", IsRequired = true)] + [JsonPropertyName("newText")] + [JsonRequired] public string NewText { get; @@ -27,7 +27,8 @@ public string NewText /// /// Gets or sets the range range if the insert is requested /// - [DataMember(Name = "insert", IsRequired = true)] + [JsonPropertyName("insert")] + [JsonRequired] public Range Insert { get; @@ -37,7 +38,8 @@ public Range Insert /// /// Gets or sets the range range if the replace is requested /// - [DataMember(Name = "replace", IsRequired = true)] + [JsonPropertyName("replace")] + [JsonRequired] public Range Replace { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceRange.cs b/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceRange.cs index 2ffbf04d520c6..26fc9e2c6efaf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceRange.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InsertReplaceRange.cs @@ -4,18 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents default range of InsertReplaceEdit for the entire completion list /// - [DataContract] internal class InsertReplaceRange { /// /// Gets or sets the insert range. /// - [DataMember(Name = "insert", IsRequired = true)] + [JsonPropertyName("insert")] + [JsonRequired] public Range Insert { get; @@ -25,7 +25,8 @@ public Range Insert /// /// Gets or sets the replace edit range. /// - [DataMember(Name = "replace", IsRequired = true)] + [JsonPropertyName("replace")] + [JsonRequired] public Range Replace { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs index 3de5c8aa688cb..7b7e24c261a79 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for the tag property on a completion item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class InsertTextModeSupportSetting { /// /// Gets or sets a value indicating the client supports the `insertTextMode` property on a completion item to override the whitespace handling mode as defined by the client. /// - [DataMember(Name = "valueSet", IsRequired = true)] + [JsonPropertyName("valueSet")] + [JsonRequired] public InsertTextMode[] ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextElementConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextElementConverter.cs index c7a88f7485e0f..13545c7af9359 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextElementConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextElementConverter.cs @@ -2,83 +2,71 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; -using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; using Roslyn.Text.Adornments; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -/// -/// JsonConverter for serializing and deserializing . -/// -internal class ClassifiedTextElementConverter : JsonConverter +namespace Roslyn.LanguageServer.Protocol; +internal class ClassifiedTextElementConverter : JsonConverter { - /// - /// A reusable instance of the . - /// public static readonly ClassifiedTextElementConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) => objectType == typeof(ClassifiedTextElement); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override ClassifiedTextElement Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) - { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) + List objects = new(); + + while (reader.Read()) { - var data = JObject.Load(reader); - var typeProperty = data[ObjectContentConverter.TypeProperty]; - if (typeProperty is not null && typeProperty.ToString() != nameof(ClassifiedTextElement)) + if (reader.TokenType == JsonTokenType.EndObject) { - throw new JsonSerializationException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ClassifiedTextElement)}"); + return new ClassifiedTextElement(objects); } - var runTokens = data[nameof(ClassifiedTextElement.Runs)]?.ToArray() ?? - throw new JsonSerializationException($"Missing {nameof(ClassifiedTextElement.Runs)} property"); - var runs = new ClassifiedTextRun[runTokens.Length]; - for (var i = 0; i < runTokens.Length; i++) + if (reader.TokenType == JsonTokenType.PropertyName) { - var runTokenReader = runTokens[i].CreateReader(); - runTokenReader.Read(); - runs[i] = (ClassifiedTextRun)ClassifiedTextRunConverter.Instance.ReadJson(runTokenReader, typeof(ClassifiedTextRun), null, serializer)!; - } + var propertyName = reader.GetString(); + reader.Read(); + switch (propertyName) + { + case nameof(ClassifiedTextElement.Runs): + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndArray) + break; - return new ClassifiedTextElement(runs); - } - else - { - throw new JsonSerializationException("Expected start object or null tokens"); + objects.Add(ClassifiedTextRunConverter.Instance.Read(ref reader, typeof(ClassifiedTextRun), options)!); + } + + break; + case ObjectContentConverter.TypeProperty: + if (reader.GetString() != nameof(ClassifiedTextElement)) + throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ClassifiedTextElement)}"); + break; + default: + reader.Skip(); + break; + } + } } + + throw new JsonException(); } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ClassifiedTextElement value, JsonSerializerOptions options) { - if (value is not ClassifiedTextElement classifiedTextElement) + writer.WriteStartObject(); + writer.WritePropertyName(nameof(ClassifiedTextElement.Runs)); + writer.WriteStartArray(); + foreach (var run in value.Runs) { - writer.WriteNull(); + ClassifiedTextRunConverter.Instance.Write(writer, run, options); } - else - { - writer.WriteStartObject(); - writer.WritePropertyName(nameof(ClassifiedTextElement.Runs)); - writer.WriteStartArray(); - foreach (var run in classifiedTextElement.Runs) - { - ClassifiedTextRunConverter.Instance.WriteJson(writer, run, serializer); - } - writer.WriteEndArray(); - writer.WritePropertyName(ObjectContentConverter.TypeProperty); - writer.WriteValue(nameof(ClassifiedTextElement)); - writer.WriteEndObject(); - } + writer.WriteEndArray(); + writer.WritePropertyName(ObjectContentConverter.TypeProperty); + writer.WriteStringValue(nameof(ClassifiedTextElement)); + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextRunConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextRunConverter.cs index b4becb32c4bef..1b7fe24c3cce7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextRunConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ClassifiedTextRunConverter.cs @@ -2,91 +2,58 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; +using System.Text.Json; +using System.Text.Json.Serialization; using Roslyn.Text.Adornments; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -/// -/// JsonConverter for serializing and deserializing . -/// -internal class ClassifiedTextRunConverter : JsonConverter +namespace Roslyn.LanguageServer.Protocol; +internal class ClassifiedTextRunConverter : JsonConverter { - /// - /// A reusable instance of the . - /// public static readonly ClassifiedTextRunConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) - => objectType == typeof(ClassifiedTextRun); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override ClassifiedTextRun? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) + if (reader.TokenType == JsonTokenType.StartObject) { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) - { - var data = JObject.Load(reader); - var typeProperty = data[ObjectContentConverter.TypeProperty]; - if (typeProperty is not null && typeProperty.ToString() != nameof(ClassifiedTextRun)) + var data = JsonDocument.ParseValue(ref reader).RootElement; + if (data.TryGetProperty(ObjectContentConverter.TypeProperty, out var typeProperty) && typeProperty.GetString() != nameof(ClassifiedTextRun)) { - throw new JsonSerializationException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ClassifiedTextRun)}"); + throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ClassifiedTextRun)}"); } - var classificationTypeName = data[nameof(ClassifiedTextRun.ClassificationTypeName)]?.Value(); - var text = data[nameof(ClassifiedTextRun.Text)]?.Value(); - var markerTagType = data[nameof(ClassifiedTextRun.MarkerTagType)]?.Value(); - var style = (ClassifiedTextRunStyle)(data[nameof(ClassifiedTextRun.Style)]?.Value() ?? 0); - return new ClassifiedTextRun(classificationTypeName!, text!, style, markerTagType); + var classificationTypeName = data.GetProperty(nameof(ClassifiedTextRun.ClassificationTypeName)).GetString(); + var text = data.GetProperty(nameof(ClassifiedTextRun.Text)).GetString(); + var markerTagType = data.GetProperty(nameof(ClassifiedTextRun.MarkerTagType)).GetString(); + var style = (ClassifiedTextRunStyle)(data.GetProperty(nameof(ClassifiedTextRun.Style)).GetInt32()); + return new ClassifiedTextRun(classificationTypeName, text, style, markerTagType); } else { - throw new JsonSerializationException("Expected start object or null tokens"); + throw new JsonException("Expected start object or null tokens"); } } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ClassifiedTextRun value, JsonSerializerOptions options) { - if (value is not ClassifiedTextRun classifiedTextRun) + writer.WriteStartObject(); + writer.WriteString(nameof(ClassifiedTextRun.ClassificationTypeName), value.ClassificationTypeName); + writer.WriteString(nameof(ClassifiedTextRun.Text), value.Text); + writer.WriteString(nameof(ClassifiedTextRun.MarkerTagType), value.MarkerTagType); + writer.WriteNumber(nameof(ClassifiedTextRun.Style), (int)value.Style); + writer.WriteNull(nameof(ClassifiedTextRun.Tooltip)); + if (value.Tooltip is not null) { - writer.WriteNull(); + throw new JsonException(); } - else - { - writer.WriteStartObject(); - writer.WritePropertyName(nameof(ClassifiedTextRun.ClassificationTypeName)); - writer.WriteValue(classifiedTextRun.ClassificationTypeName); - writer.WritePropertyName(nameof(ClassifiedTextRun.Text)); - writer.WriteValue(classifiedTextRun.Text); - writer.WritePropertyName(nameof(ClassifiedTextRun.MarkerTagType)); - writer.WriteValue(classifiedTextRun.MarkerTagType); - writer.WritePropertyName(nameof(ClassifiedTextRun.Style)); - writer.WriteValue(classifiedTextRun.Style); - writer.WritePropertyName(nameof(ClassifiedTextRun.Tooltip)); - writer.WriteNull(); - if (classifiedTextRun.Tooltip is not null) - { - throw new JsonSerializationException(); - } - writer.WritePropertyName(nameof(ClassifiedTextRun.NavigationAction)); - writer.WriteNull(); - if (classifiedTextRun.NavigationAction is not null) - { - throw new JsonSerializationException(); - } - - writer.WritePropertyName(ObjectContentConverter.TypeProperty); - writer.WriteValue(nameof(ClassifiedTextRun)); - writer.WriteEndObject(); + writer.WriteNull(nameof(ClassifiedTextRun.NavigationAction)); + if (value.NavigationAction is not null) + { + throw new JsonException(); } + + writer.WriteString(ObjectContentConverter.TypeProperty, nameof(ClassifiedTextRun)); + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ContainerElementConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ContainerElementConverter.cs index d1778d40c9251..4d501e5f6c53b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ContainerElementConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ContainerElementConverter.cs @@ -2,86 +2,81 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; -using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; using Roslyn.Text.Adornments; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +namespace Roslyn.LanguageServer.Protocol; /// -/// JsonConverter for serializing and deserializing . +/// System.Text.Json.JsonConverter for serializing and deserializing . /// -internal class ContainerElementConverter : JsonConverter +internal class ContainerElementConverter : JsonConverter { - /// - /// A reusable instance of the . - /// public static readonly ContainerElementConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) => objectType == typeof(ContainerElement); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override ContainerElement Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) - { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) + if (reader.TokenType == JsonTokenType.StartObject) { - var data = JObject.Load(reader); - var typeProperty = data[ObjectContentConverter.TypeProperty]; - if (typeProperty is not null && typeProperty.ToString() != nameof(ContainerElement)) - { - throw new JsonSerializationException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ContainerElement)}"); - } + ContainerElementStyle? style = default; + List objects = new(); - var elementTokens = data[nameof(ContainerElement.Elements)]?.ToArray() ?? - throw new JsonSerializationException($"Missing {nameof(ContainerElement.Elements)} property"); - var elements = new object?[elementTokens.Length]; - for (var i = 0; i < elementTokens.Length; i++) + while (reader.Read()) { - var elementTokenReader = elementTokens[i].CreateReader(); - elementTokenReader.Read(); - elements[i] = ObjectContentConverter.Instance.ReadJson(elementTokenReader, typeof(object), null, serializer); - } + if (reader.TokenType == JsonTokenType.EndObject) + { + return new ContainerElement(style ?? throw new JsonException(), objects); + } - var style = (ContainerElementStyle)(data[nameof(ContainerElement.Style)]?.Value() ?? throw new JsonSerializationException()); - return new ContainerElement(style, elements); - } - else - { - throw new JsonSerializationException("Expected start object or null tokens"); + if (reader.TokenType == JsonTokenType.PropertyName) + { + var propertyName = reader.GetString(); + reader.Read(); + switch (propertyName) + { + case nameof(ContainerElement.Elements): + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndArray) + break; + + objects.Add(ObjectContentConverter.Instance.Read(ref reader, typeof(object), options)!); + } + + break; + case nameof(ContainerElement.Style): + style = (ContainerElementStyle)reader.GetInt32(); + break; + case ObjectContentConverter.TypeProperty: + if (reader.GetString() != nameof(ContainerElement)) + throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ContainerElement)}"); + break; + default: + reader.Skip(); + break; + } + } + } } + + throw new JsonException(); } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ContainerElement value, JsonSerializerOptions options) { - if (value is not ContainerElement containerElement) + writer.WriteStartObject(); + writer.WritePropertyName(nameof(ContainerElement.Elements)); + writer.WriteStartArray(); + foreach (var run in value.Elements) { - writer.WriteNull(); - } - else - { - writer.WriteStartObject(); - writer.WritePropertyName(nameof(ContainerElement.Elements)); - writer.WriteStartArray(); - foreach (var run in containerElement.Elements) - { - ObjectContentConverter.Instance.WriteJson(writer, run, serializer); - } - - writer.WriteEndArray(); - writer.WritePropertyName(nameof(ContainerElement.Style)); - writer.WriteValue(containerElement.Style); - writer.WritePropertyName(ObjectContentConverter.TypeProperty); - writer.WriteValue(nameof(ContainerElement)); - writer.WriteEndObject(); + ObjectContentConverter.Instance.Write(writer, run, options); } + writer.WriteEndArray(); + writer.WriteNumber(nameof(ContainerElement.Style), (int)value.Style); + writer.WritePropertyName(ObjectContentConverter.TypeProperty); + writer.WriteStringValue(nameof(ContainerElement)); + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/DropProgressConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/DropProgressConverter.cs deleted file mode 100644 index 868de33bddf28..0000000000000 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/DropProgressConverter.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using System.Linq; - using Newtonsoft.Json; - - /// - /// Converter used to deserialize objects dropping any property. - /// - internal class DropProgressConverter : JsonConverter - { - /// - public override bool CanWrite => true; - - /// - /// Static method to get a containing a . - /// - /// object containing a . - public static JsonSerializer CreateSerializer() - { - var serializer = new JsonSerializer(); - serializer.Converters.Add(new DropProgressConverter()); - return serializer; - } - - /// - public override bool CanConvert(Type objectType) - { - var isIProgressOfT = objectType.IsConstructedGenericType && objectType.GetGenericTypeDefinition().Equals(typeof(IProgress<>)); - var implementsIProgressOfT = objectType.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(typeof(IProgress<>))); - - return isIProgressOfT || implementsIProgressOfT; - } - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - // We deserialize all IProgress objects as null. - return null; - } - - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - writer.WriteNull(); - } - } -} diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageElementConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageElementConverter.cs index cb8d549fe6f65..38c46fcb547a0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageElementConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageElementConverter.cs @@ -2,73 +2,66 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; +using System.Text.Json; +using System.Text.Json.Serialization; using Roslyn.Core.Imaging; using Roslyn.Text.Adornments; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -/// -/// JsonConverter for serializing and deserializing . -/// -internal class ImageElementConverter : JsonConverter +namespace Roslyn.LanguageServer.Protocol; +internal class ImageElementConverter : JsonConverter { - /// - /// A reusable instance of the . - /// public static readonly ImageElementConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) => objectType == typeof(ImageElement); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override ImageElement Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) + if (reader.TokenType == JsonTokenType.StartObject) { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) - { - var data = JObject.Load(reader); - var typeProperty = data[ObjectContentConverter.TypeProperty]; - if (typeProperty is not null && typeProperty.ToString() != nameof(ImageElement)) + ImageId? imageId = default; + string? automationName = default; + + while (reader.Read()) { - throw new JsonSerializationException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageElement)}"); - } + if (reader.TokenType == JsonTokenType.EndObject) + { + imageId ??= imageId ?? throw new JsonException(); + return automationName is null ? new ImageElement(imageId.Value) : new ImageElement(imageId.Value, automationName); + } - var imageTokenReader = data[nameof(ImageElement.ImageId)]?.CreateReader() ?? throw new JsonSerializationException(); - imageTokenReader.Read(); - var imageId = (ImageId)ImageIdConverter.Instance.ReadJson(imageTokenReader, typeof(ImageId), null, serializer)!; - var automationName = data[nameof(ImageElement.AutomationName)]?.Value(); - return automationName is null ? new ImageElement(imageId) : new ImageElement(imageId, automationName); - } - else - { - throw new JsonSerializationException("Expected start object or null tokens"); + if (reader.TokenType == JsonTokenType.PropertyName) + { + var propertyName = reader.GetString(); + reader.Read(); + switch (propertyName) + { + case nameof(ImageElement.ImageId): + imageId = ImageIdConverter.Instance.Read(ref reader, typeof(ImageId), options); + break; + case nameof(ImageElement.AutomationName): + automationName = reader.GetString(); + break; + case ObjectContentConverter.TypeProperty: + if (reader.GetString() != nameof(ImageElement)) + throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageElement)}"); + break; + default: + reader.Skip(); + break; + } + } + } } + + throw new JsonException("Expected start object or null tokens"); } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ImageElement value, JsonSerializerOptions options) { - if (value is not ImageElement imageElement) - { - writer.WriteNull(); - } - else - { - writer.WriteStartObject(); - writer.WritePropertyName(nameof(ImageElement.ImageId)); - ImageIdConverter.Instance.WriteJson(writer, imageElement.ImageId, serializer); - writer.WritePropertyName(nameof(ImageElement.AutomationName)); - writer.WriteValue(imageElement.AutomationName); - writer.WritePropertyName(ObjectContentConverter.TypeProperty); - writer.WriteValue(nameof(ImageElement)); - writer.WriteEndObject(); - } + writer.WriteStartObject(); + writer.WritePropertyName(nameof(ImageElement.ImageId)); + ImageIdConverter.Instance.Write(writer, value.ImageId, options); + writer.WriteString(nameof(ImageElement.AutomationName), value.AutomationName); + writer.WriteString(ObjectContentConverter.TypeProperty, nameof(ImageElement)); + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageIdConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageIdConverter.cs index 825d98d413ea5..80fba1a12ca49 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageIdConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ImageIdConverter.cs @@ -2,71 +2,43 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol; - using System; +using System.Text.Json; +using System.Text.Json.Serialization; using Roslyn.Core.Imaging; -using Roslyn.Text.Adornments; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -/// -/// JsonConverter for serializing and deserializing . -/// -internal class ImageIdConverter : JsonConverter +namespace Roslyn.LanguageServer.Protocol; +internal class ImageIdConverter : JsonConverter { - /// - /// A reusable instance of the . - /// public static readonly ImageIdConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) => objectType == typeof(ImageId); - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override ImageId Read(ref Utf8JsonReader reader, Type objectType, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) - { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) + if (reader.TokenType == JsonTokenType.StartObject) { - var data = JObject.Load(reader); - var typeProperty = data[ObjectContentConverter.TypeProperty]; - if (typeProperty is not null && typeProperty.ToString() != nameof(ImageId)) + using var document = JsonDocument.ParseValue(ref reader); + var root = document.RootElement; + if (root.TryGetProperty(ObjectContentConverter.TypeProperty, out var typeProperty) && typeProperty.GetString() != nameof(ImageId)) { - throw new JsonSerializationException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageId)}"); + throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageId)}"); } - var guid = data[nameof(ImageId.Guid)]?.Value() ?? throw new JsonSerializationException(); - var id = data[nameof(ImageId.Id)]?.Value() ?? throw new JsonSerializationException(); + var guid = root.GetProperty(nameof(ImageId.Guid)).GetString() ?? throw new JsonException(); + var id = root.GetProperty(nameof(ImageId.Id)).GetInt32(); return new ImageId(new Guid(guid), id); } else { - throw new JsonSerializationException("Expected start object or null tokens"); + throw new JsonException("Expected start object or null tokens"); } } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ImageId value, JsonSerializerOptions options) { - if (value is not ImageId imageId) - { - writer.WriteNull(); - } - else - { - writer.WriteStartObject(); - writer.WritePropertyName(nameof(ImageId.Guid)); - writer.WriteValue(imageId.Guid); - writer.WritePropertyName(nameof(ImageId.Id)); - writer.WriteValue(imageId.Id); - writer.WritePropertyName(ObjectContentConverter.TypeProperty); - writer.WriteValue(nameof(ImageId)); - writer.WriteEndObject(); - } + writer.WriteStartObject(); + writer.WriteString(nameof(ImageId.Guid), value.Guid.ToString()); + writer.WriteNumber(nameof(ImageId.Id), value.Id); + writer.WriteString(ObjectContentConverter.TypeProperty, nameof(ImageId)); + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ObjectContentConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ObjectContentConverter.cs index 26e0886a0ee51..428088de62230 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ObjectContentConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/ObjectContentConverter.cs @@ -2,115 +2,117 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using Roslyn.Core.Imaging; - using Roslyn.Text.Adornments; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Roslyn.Core.Imaging; +using Roslyn.Text.Adornments; + +namespace Roslyn.LanguageServer.Protocol; +/// +/// Object Content converter used to serialize and deserialize Text and Adornements from VS. +/// +/// This converts the following types: +/// +/// , +/// , +/// , +/// , +/// . +/// +/// Every other type is serialized as a string using the method. +/// +internal class ObjectContentConverter : JsonConverter +{ /// - /// Object Content converter used to serialize and deserialize Text and Adornements from VS. - /// - /// This converts the following types: - /// - /// , - /// , - /// , - /// , - /// . - /// - /// Every other type is serialized as a string using the method. + /// The property name used to save the .NET Type name of the serialized object. /// - internal class ObjectContentConverter : JsonConverter - { - /// - /// The property name used to save the .NET Type name of the serialized object. - /// - public const string TypeProperty = "_vs_type"; + public const string TypeProperty = "_vs_type"; - /// - /// A reusable instance of the . - /// - public static readonly ObjectContentConverter Instance = new ObjectContentConverter(); + /// + /// A reusable instance of the . + /// + public static readonly ObjectContentConverter Instance = new(); - /// - public override bool CanConvert(Type objectType) + public override object? Read(ref Utf8JsonReader reader, Type objectType, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) { - return objectType == typeof(object); + reader.Read(); + return null; } - - /// - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + else if (reader.TokenType == JsonTokenType.StartObject) { - if (reader.TokenType == JsonToken.Null) - { - reader.Read(); - return null; - } - else if (reader.TokenType == JsonToken.StartObject) + var clonedReader = reader; + using (var jsonDocument = JsonDocument.ParseValue(ref reader)) { - var data = JObject.Load(reader); - var type = data[TypeProperty]?.ToString() ?? throw new JsonSerializationException(); + var data = jsonDocument.RootElement; + var type = data.GetProperty(TypeProperty).GetString() ?? throw new JsonException(); - var tokenReader = data.CreateReader(); - tokenReader.Read(); switch (type) { case nameof(ImageId): - return ImageIdConverter.Instance.ReadJson(tokenReader, typeof(ImageId), null, serializer); + return ImageIdConverter.Instance.Read(ref clonedReader, typeof(ImageId), options); case nameof(ImageElement): - return ImageElementConverter.Instance.ReadJson(tokenReader, typeof(ImageElement), null, serializer); + return ImageElementConverter.Instance.Read(ref clonedReader, typeof(ImageElement), options); case nameof(ContainerElement): - return ContainerElementConverter.Instance.ReadJson(tokenReader, typeof(ContainerElementConverter), null, serializer); + return ContainerElementConverter.Instance.Read(ref clonedReader, typeof(ContainerElementConverter), options); case nameof(ClassifiedTextElement): - return ClassifiedTextElementConverter.Instance.ReadJson(tokenReader, typeof(ClassifiedTextElementConverter), null, serializer); + return ClassifiedTextElementConverter.Instance.Read(ref clonedReader, typeof(ClassifiedTextElementConverter), options); case nameof(ClassifiedTextRun): - return ClassifiedTextRunConverter.Instance.ReadJson(tokenReader, typeof(ClassifiedTextRunConverter), null, serializer); + return ClassifiedTextRunConverter.Instance.Read(ref clonedReader, typeof(ClassifiedTextRunConverter), options); default: return data; } } - else - { - return serializer.Deserialize(reader); - } } + else if (reader.TokenType == JsonTokenType.String) + { + return reader.GetString(); + } + else if (reader.TokenType == JsonTokenType.Number) + { + return reader.GetInt32(); + } + else + { + return JsonSerializer.Deserialize(ref reader, objectType, options); + } + } - /// - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + /// + public override void Write(Utf8JsonWriter writer, object? value, JsonSerializerOptions options) + { + if (value is null) { - if (value is null) - { - writer.WriteNull(); - return; - } + writer.WriteNullValue(); + return; + } - switch (value) - { - case ImageId: - ImageIdConverter.Instance.WriteJson(writer, value, serializer); - break; - case ImageElement: - ImageElementConverter.Instance.WriteJson(writer, value, serializer); - break; - case ContainerElement: - ContainerElementConverter.Instance.WriteJson(writer, value, serializer); - break; - case ClassifiedTextElement: - ClassifiedTextElementConverter.Instance.WriteJson(writer, value, serializer); - break; - case ClassifiedTextRun: - ClassifiedTextRunConverter.Instance.WriteJson(writer, value, serializer); - break; - default: - // According to the docs of ContainerElement point to https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.adornments.iviewelementfactoryservice - // which states that Editor supports ClassifiedTextElement, ContainerElement, ImageElement and that other objects would be presented using ToString unless an extender - // exports a IViewElementFactory for that type. So I will simply serialize unknown objects as strings. - writer.WriteValue(value.ToString()); - break; - } + switch (value) + { + case ImageId: + ImageIdConverter.Instance.Write(writer, (ImageId)value, options); + break; + case ImageElement: + ImageElementConverter.Instance.Write(writer, (ImageElement)value, options); + break; + case ContainerElement: + ContainerElementConverter.Instance.Write(writer, (ContainerElement)value, options); + break; + case ClassifiedTextElement: + ClassifiedTextElementConverter.Instance.Write(writer, (ClassifiedTextElement)value, options); + break; + case ClassifiedTextRun: + ClassifiedTextRunConverter.Instance.Write(writer, (ClassifiedTextRun)value, options); + break; + default: + // According to the docs of ContainerElement point to https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.adornments.iviewelementfactoryservice + // which states that Editor supports ClassifiedTextElement, ContainerElement, ImageElement and that other objects would be presented using ToString unless an extender + // exports a IViewElementFactory for that type. So I will simply serialize unknown objects as strings. + writer.WriteStringValue(value.ToString()); + break; } } -} \ No newline at end of file +} diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/RegexConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/RegexConverter.cs index 1bd71cd566617..881fa953b1fc1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/RegexConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/RegexConverter.cs @@ -2,48 +2,26 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using System.Text.RegularExpressions; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.RegularExpressions; - using Newtonsoft.Json; +namespace Roslyn.LanguageServer.Protocol; - /// - /// Similar to https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform?path=/src/Productivity/TextMate/Core/LanguageConfiguration/Impl/FastRegexConverter.cs - /// to allow us to only compile the regex option once. - /// - internal class RegexConverter : JsonConverter +/// +/// Similar to https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform?path=/src/Productivity/TextMate/Core/LanguageConfiguration/Impl/FastRegexConverter.cs +/// to allow us to only compile the regex option once. +/// +internal class RegexConverter : JsonConverter +{ + public override Regex? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - public override bool CanConvert(Type objectType) - { - // nameof is faster than typeof, so below is a fast path. - return objectType.Name == nameof(Regex) && objectType == typeof(Regex); - } - - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - // Create a custom deserializer for regex as the default provided by newtonsoft doesn't - // specify the Compiled option. - var regexText = reader.Value as string; - if (string.IsNullOrEmpty(regexText)) - { - return null; - } - - return new Regex(regexText, RegexOptions.Compiled | RegexOptions.ECMAScript, matchTimeout: TimeSpan.FromMilliseconds(1000)); - } + return new Regex(reader.GetString(), RegexOptions.Compiled | RegexOptions.ECMAScript, matchTimeout: TimeSpan.FromMilliseconds(1000)); + } - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - if (value is Regex valueAsRegex) - { - writer.WriteValue(valueAsRegex.ToString()); - } - else - { - throw new ArgumentException($"{nameof(value)} must be of type {nameof(Regex)}"); - } - } + public override void Write(Utf8JsonWriter writer, Regex value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString()); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSCodeInternalExtensionUtilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSCodeInternalExtensionUtilities.cs index a1d482e7a480a..23dc024eca0ee 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSCodeInternalExtensionUtilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSCodeInternalExtensionUtilities.cs @@ -4,7 +4,9 @@ namespace Roslyn.LanguageServer.Protocol { - using Newtonsoft.Json; + using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Utilities to aid work with VS Code LSP Extensions. @@ -15,37 +17,31 @@ internal static class VSCodeInternalExtensionUtilities /// Adds necessary to deserialize /// JSON stream into objects which include VS Code-specific extensions. /// - /// - /// If is used in parallel to execution of this method, - /// its access needs to be synchronized with this method call, to guarantee that - /// collection is not modified when in use. - /// - /// Instance of which is guaranteed to not work in parallel to this method call. - public static void AddVSCodeInternalExtensionConverters(this JsonSerializer serializer) + public static void AddVSCodeInternalExtensionConverters(this JsonSerializerOptions options) { // Reading the number of converters before we start adding new ones - var existingConvertersCount = serializer.Converters.Count; + var existingConvertersCount = options.Converters.Count; - AddOrReplaceConverter(); - AddOrReplaceConverter(); + AddOrReplaceConverter(options.Converters); + AddOrReplaceConverter(options.Converters); - void AddOrReplaceConverter() - where TExtension : TBase + void AddOrReplaceConverter(IList converters) + where TExtension : TBase { for (var i = 0; i < existingConvertersCount; i++) { - var existingConverterType = serializer.Converters[i].GetType(); + var existingConverterType = converters[i].GetType(); if (existingConverterType.IsGenericType && - existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) && + (existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) || existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>)) && existingConverterType.GenericTypeArguments[0] == typeof(TBase)) { - serializer.Converters.RemoveAt(i); + converters.RemoveAt(i); existingConvertersCount--; break; } } - serializer.Converters.Add(new VSExtensionConverter()); + converters.Add(new VSExtensionConverter()); } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs index dea7f8218f125..15e162c6c13eb 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs @@ -2,72 +2,69 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; +/// +/// Utilities to aid work with the LSP Extensions. +/// +internal static class VSInternalExtensionUtilities +{ /// - /// Utilities to aid work with the LSP Extensions. + /// Adds necessary to deserialize + /// JSON stream into objects which include VS-specific extensions. /// - internal static class VSInternalExtensionUtilities + internal static void AddVSInternalExtensionConverters(this JsonSerializerOptions options) { - /// - /// Adds necessary to deserialize - /// JSON stream into objects which include VS-specific extensions. - /// - /// - /// If is used in parallel to execution of this method, - /// its access needs to be synchronized with this method call, to guarantee that - /// collection is not modified when in use. - /// - /// Instance of which is guaranteed to not work in parallel to this method call. - public static void AddVSInternalExtensionConverters(this JsonSerializer serializer) - { - VSExtensionUtilities.AddVSExtensionConverters(serializer); + VSExtensionUtilities.AddVSExtensionConverters(options); + AddConverters(options.Converters); + } - // Reading the number of converters before we start adding new ones - var existingConvertersCount = serializer.Converters.Count; + private static void AddConverters(IList converters) + { + // Reading the number of converters before we start adding new ones + var existingConvertersCount = converters.Count; - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); - AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); + AddOrReplaceConverter(); - void AddOrReplaceConverter() - where TExtension : TBase + void AddOrReplaceConverter() + where TExtension : TBase + { + for (var i = 0; i < existingConvertersCount; i++) { - for (var i = 0; i < existingConvertersCount; i++) + var existingConverterType = converters[i].GetType(); + if (existingConverterType.IsGenericType && + (existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) || existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>)) && + existingConverterType.GenericTypeArguments[0] == typeof(TBase)) { - var existingConverterType = serializer.Converters[i].GetType(); - if (existingConverterType.IsGenericType && - existingConverterType.GetGenericTypeDefinition() == typeof(VSExtensionConverter<,>) && - existingConverterType.GenericTypeArguments[0] == typeof(TBase)) - { - serializer.Converters.RemoveAt(i); - existingConvertersCount--; - break; - } + converters.RemoveAt(i); + existingConvertersCount--; + break; } - - serializer.Converters.Add(new VSExtensionConverter()); } + + converters.Add(new VSExtensionConverter()); } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticKind.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticKind.cs index 2e2756573aa8e..3ac8099a356ec 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticKind.cs @@ -5,14 +5,11 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the kind of a diagnostic. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct VSInternalDiagnosticKind(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticOptions.cs index 5ae9280872f06..1bf9a1d635dc5 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticOptions.cs @@ -4,13 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Server provided options for pull diagnostic requests. /// - [DataContract] internal record class VSInternalDiagnosticOptions : IWorkDoneProgressOptions { /// @@ -20,29 +18,29 @@ internal record class VSInternalDiagnosticOptions : IWorkDoneProgressOptions /// VS client will then use the information to do any merging logic in the Error List. /// Maps to . /// - [DataMember(Name = "_vs_buildOnlyDiagnosticIds")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_buildOnlyDiagnosticIds")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? BuildOnlyDiagnosticIds { get; init; } /// /// Gets or sets a list of diagnostic kinds used to query diagnostics in each context. /// - [DataMember(Name = "_vs_diagnosticKinds")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_diagnosticKinds")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDiagnosticKind[]? DiagnosticKinds { get; init; } /// /// Gets or sets a value indicating whether the server provides support for sending diagnostics requests for all project contexts. /// - [DataMember(Name = "_vs_supportsMultipleContextDiagnostics")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsMultipleContextDiagnostics")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsMultipleContextsDiagnostics { get; init; } /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "_vs_workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticParams.cs index 40e808078218a..d45d258d1091c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticParams.cs @@ -4,27 +4,25 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a diagnostic pull request parameter used. /// - [DataContract] internal class VSInternalDiagnosticParams { /// /// Gets or sets the document for which diagnostics are desired. /// - [DataMember(Name = "_vs_textDocument", IsRequired = true)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier? TextDocument { get; set; } /// /// Gets or sets a value indicating what kind of diagnostic this request is querying for. /// - [DataMember(Name = "_vs_queryingDiagnosticKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_queryingDiagnosticKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDiagnosticKind? QueryingDiagnosticKind { get; set; } /// @@ -46,8 +44,8 @@ internal class VSInternalDiagnosticParams /// document, then all reports are expected to have the same /// previousResultId. /// - [DataMember(Name = "_vs_previousResultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_previousResultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? PreviousResultId { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticReport.cs index 29b96efd3f442..71421912abc11 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDiagnosticReport.cs @@ -5,13 +5,11 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a diagnostic pull request report. /// - [DataContract] internal class VSInternalDiagnosticReport { /// @@ -21,8 +19,8 @@ internal class VSInternalDiagnosticReport /// diagnostics.The server can use this result ID to avoid resending /// diagnostics that had previously been sent. /// - [DataMember(Name = "_vs_resultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_resultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ResultId { get; set; } /// @@ -32,8 +30,8 @@ internal class VSInternalDiagnosticReport /// /// Is null if no changes in the diagnostics. Is empty if there is no diagnostic. /// - [DataMember(Name = "_vs_diagnostics")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_diagnostics")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Diagnostic[]? Diagnostics { get; set; } /// @@ -43,8 +41,8 @@ internal class VSInternalDiagnosticReport /// entries tagged with will /// be hidden in the editor. /// - [DataMember(Name = "_vs_identifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_identifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Identifier { get; set; } /// @@ -53,8 +51,8 @@ internal class VSInternalDiagnosticReport /// /// Diagnostics in a superseded report will be hidden if they have the PotentialDuplicate VSDiagnosticTag. /// - [DataMember(Name = "_vs_supersedes")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_supersedes")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Supersedes { get; set; } /// @@ -63,15 +61,15 @@ internal class VSInternalDiagnosticReport /// outputId and the (outputKey, outputId) uniquely identify /// a line of text in the output window). /// - [DataMember(Name = "_vs_outputKey")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_outputKey")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Guid? OutputKey { get; set; } /// /// Gets or sets the document version. /// - [DataMember(Name = "_vs_version")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Version { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs index 8b61f2fbf6438..2a136bb3fab29 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs @@ -5,27 +5,25 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a diagnostic pull request for a specific document. /// - [DataContract] internal class VSInternalDocumentDiagnosticsParams : VSInternalDiagnosticParams, IPartialResultParams { /// /// Gets or sets an optional token that a server can use to report work done progress. /// - [DataMember(Name = Methods.WorkDoneTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? WorkDoneToken { get; set; } /// /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. /// - [DataMember(Name = Methods.PartialResultTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticReport.cs index b4841e7c41664..a14f42cf55b4e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticReport.cs @@ -4,18 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing a diagnostic pull request result for all documents. /// - [DataContract] internal class VSInternalWorkspaceDiagnosticReport : VSInternalDiagnosticReport { /// /// Gets or sets the document for which diagnostics is returned. /// - [DataMember(Name = "_vs_textDocument", IsRequired = true)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier? TextDocument { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs index 1ddf9bd496914..61d145c73c8bc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs @@ -5,41 +5,39 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a diagnostic pull request for all documents. /// - [DataContract] internal class VSInternalWorkspaceDiagnosticsParams : IPartialResultParams { /// /// Gets or sets the current state of the documents the client already has received. /// - [DataMember(Name = "_vs_previousResults")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_previousResults")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDiagnosticParams[]? PreviousResults { get; set; } /// /// Gets or sets an optional token that a server can use to report work done progress. /// - [DataMember(Name = Methods.WorkDoneTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? WorkDoneToken { get; set; } /// /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. /// - [DataMember(Name = Methods.PartialResultTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; set; } /// /// Gets or sets a value indicating what kind of diagnostic this request is querying for. /// - [DataMember(Name = "_vs_queryingDiagnosticKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_queryingDiagnosticKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDiagnosticKind? QueryingDiagnosticKind { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionList.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionList.cs index f99efeba0bbea..2c08c682897e0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionList.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionList.cs @@ -4,13 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A subclass of the VS LSP protocol extension that has a fast serialization path. /// - [DataContract] [JsonConverter(typeof(OptimizedVSCompletionListJsonConverter))] internal sealed class OptimizedVSCompletionList : VSInternalCompletionList { diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs index 2dbe0839d6d76..5288dde922493 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs @@ -2,272 +2,250 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using Roslyn.Core.Imaging; - using Newtonsoft.Json; - - internal class OptimizedVSCompletionListJsonConverter : JsonConverter - { - public static readonly OptimizedVSCompletionListJsonConverter Instance = new OptimizedVSCompletionListJsonConverter(); - private static readonly ConcurrentDictionary IconRawJson = new ConcurrentDictionary(); +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Roslyn.Core.Imaging; - public override bool CanRead => false; +namespace Roslyn.LanguageServer.Protocol; - public override bool CanConvert(Type objectType) => typeof(OptimizedVSCompletionList) == objectType; +internal class OptimizedVSCompletionListJsonConverter : JsonConverter +{ + public static readonly OptimizedVSCompletionListJsonConverter Instance = new(); + private static readonly ConcurrentDictionary IconRawJson = new ConcurrentDictionary(); - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) => throw new NotImplementedException(); + public override OptimizedVSCompletionList Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException(); - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, OptimizedVSCompletionList value, JsonSerializerOptions options) + { + if (value is null) { - if (value is null) - { - writer.WriteNull(); - return; - } + writer.WriteNullValue(); + return; + } - var completionList = (VSInternalCompletionList)value; + var completionList = (VSInternalCompletionList)value; - writer.WriteStartObject(); + writer.WriteStartObject(); - if (completionList.SuggestionMode) - { - writer.WritePropertyName(VSInternalCompletionList.SuggestionModeSerializedName); - writer.WriteValue(completionList.SuggestionMode); - } - else - { - // Default is "false" so no need to serialize - } + if (completionList.SuggestionMode) + { + writer.WriteBoolean(VSInternalCompletionList.SuggestionModeSerializedName, completionList.SuggestionMode); + } + else + { + // Default is "false" so no need to serialize + } - if (completionList.ContinueCharacters != null && completionList.ContinueCharacters.Length > 0) - { - writer.WritePropertyName(VSInternalCompletionList.ContinueCharactersSerializedName); - serializer.Serialize(writer, completionList.ContinueCharacters); - } + if (completionList.ContinueCharacters != null && completionList.ContinueCharacters.Length > 0) + { + writer.WritePropertyName(VSInternalCompletionList.ContinueCharactersSerializedName); + JsonSerializer.Serialize(writer, completionList.ContinueCharacters, options); + } - if (completionList.Data != null) - { - writer.WritePropertyName(VSInternalCompletionList.DataSerializedName); - serializer.Serialize(writer, completionList.Data); - } + if (completionList.Data != null) + { + writer.WritePropertyName(VSInternalCompletionList.DataSerializedName); + JsonSerializer.Serialize(writer, completionList.Data, options); + } - if (completionList.CommitCharacters != null) - { - writer.WritePropertyName(VSInternalCompletionList.CommitCharactersSerializedName); - serializer.Serialize(writer, completionList.CommitCharacters); - } + if (completionList.CommitCharacters != null) + { + writer.WritePropertyName(VSInternalCompletionList.CommitCharactersSerializedName); + JsonSerializer.Serialize(writer, completionList.CommitCharacters, options); + } - if (completionList.IsIncomplete) - { - writer.WritePropertyName("isIncomplete"); - writer.WriteValue(completionList.IsIncomplete); - } - else - { - // Default is "false" so no need to serialize - } + if (completionList.IsIncomplete) + { + writer.WriteBoolean("isIncomplete", completionList.IsIncomplete); + } + else + { + // Default is "false" so no need to serialize + } - writer.WritePropertyName("items"); - if (completionList.Items == null || completionList.Items.Length == 0) - { - writer.WriteRawValue("[]"); - } - else - { - writer.WriteStartArray(); + writer.WritePropertyName("items"); + if (completionList.Items == null || completionList.Items.Length == 0) + { + writer.WriteRawValue("[]"); + } + else + { + writer.WriteStartArray(); - var itemRawJsonCache = new Dictionary(capacity: 1); + var itemRawJsonCache = new Dictionary(capacity: 1); - foreach (var completionItem in completionList.Items) + foreach (var completionItem in completionList.Items) + { + if (completionItem == null) { - if (completionItem == null) - { - continue; - } - - WriteCompletionItem(writer, completionItem, serializer, itemRawJsonCache); + continue; } - writer.WriteEndArray(); - } - - if (completionList.ItemDefaults != null) - { - writer.WritePropertyName("itemDefaults"); - serializer.Serialize(writer, completionList.ItemDefaults); + WriteCompletionItem(writer, completionItem, options, itemRawJsonCache); } - writer.WriteEndObject(); + writer.WriteEndArray(); } - private static void WriteCompletionItem(JsonWriter writer, CompletionItem completionItem, JsonSerializer serializer, Dictionary itemRawJsonCache) + if (completionList.ItemDefaults != null) { - writer.WriteStartObject(); + writer.WritePropertyName("itemDefaults"); + JsonSerializer.Serialize(writer, completionList.ItemDefaults, options); + } + + writer.WriteEndObject(); + } + + private static void WriteCompletionItem(Utf8JsonWriter writer, CompletionItem completionItem, JsonSerializerOptions options, Dictionary itemRawJsonCache) + { + writer.WriteStartObject(); - if (completionItem is VSInternalCompletionItem vsCompletionItem) + if (completionItem is VSInternalCompletionItem vsCompletionItem) + { + if (vsCompletionItem.Icon != null) { - if (vsCompletionItem.Icon != null) + if (!IconRawJson.TryGetValue(vsCompletionItem.Icon.ImageId, out var jsonString)) { - if (!IconRawJson.TryGetValue(vsCompletionItem.Icon.ImageId, out var jsonString)) - { - jsonString = JsonConvert.SerializeObject(vsCompletionItem.Icon, Formatting.None, ImageElementConverter.Instance); - IconRawJson.TryAdd(vsCompletionItem.Icon.ImageId, jsonString); - } - - writer.WritePropertyName(VSInternalCompletionItem.IconSerializedName); - writer.WriteRawValue(jsonString); + jsonString = JsonSerializer.Serialize(vsCompletionItem.Icon, options); + IconRawJson.TryAdd(vsCompletionItem.Icon.ImageId, jsonString); } + writer.WritePropertyName(VSInternalCompletionItem.IconSerializedName); + writer.WriteRawValue(jsonString); + } - if (vsCompletionItem.Description != null) - { - writer.WritePropertyName(VSInternalCompletionItem.DescriptionSerializedName); - ClassifiedTextElementConverter.Instance.WriteJson(writer, vsCompletionItem.Description, serializer); - } + if (vsCompletionItem.Description != null) + { + writer.WritePropertyName(VSInternalCompletionItem.DescriptionSerializedName); + JsonSerializer.Serialize(writer, vsCompletionItem.Description, options); + } - if (vsCompletionItem.VsCommitCharacters?.Value is string[] basicCommitCharacters - && basicCommitCharacters.Length > 0) - { - if (!itemRawJsonCache.TryGetValue(basicCommitCharacters, out var jsonString)) - { - jsonString = JsonConvert.SerializeObject(basicCommitCharacters); - itemRawJsonCache.Add(basicCommitCharacters, jsonString); - } - - writer.WritePropertyName(VSInternalCompletionItem.VsCommitCharactersSerializedName); - writer.WriteRawValue(jsonString); - } - else if (vsCompletionItem.VsCommitCharacters?.Value is VSInternalCommitCharacter[] augmentedCommitCharacters - && augmentedCommitCharacters.Length > 0) + if (vsCompletionItem.VsCommitCharacters?.Value is string[] basicCommitCharacters + && basicCommitCharacters.Length > 0) + { + if (!itemRawJsonCache.TryGetValue(basicCommitCharacters, out var jsonString)) { - if (!itemRawJsonCache.TryGetValue(augmentedCommitCharacters, out var jsonString)) - { - jsonString = JsonConvert.SerializeObject(augmentedCommitCharacters); - itemRawJsonCache.Add(augmentedCommitCharacters, jsonString); - } - - writer.WritePropertyName(VSInternalCompletionItem.VsCommitCharactersSerializedName); - writer.WriteRawValue(jsonString); + jsonString = JsonSerializer.Serialize(basicCommitCharacters, options); + itemRawJsonCache.Add(basicCommitCharacters, jsonString); } - if (vsCompletionItem.VsResolveTextEditOnCommit) + writer.WritePropertyName(VSInternalCompletionItem.VsCommitCharactersSerializedName); + writer.WriteRawValue(jsonString); + } + else if (vsCompletionItem.VsCommitCharacters?.Value is VSInternalCommitCharacter[] augmentedCommitCharacters + && augmentedCommitCharacters.Length > 0) + { + if (!itemRawJsonCache.TryGetValue(augmentedCommitCharacters, out var jsonString)) { - writer.WritePropertyName(VSInternalCompletionItem.VsResolveTextEditOnCommitName); - writer.WriteValue(vsCompletionItem.VsResolveTextEditOnCommit); + jsonString = JsonSerializer.Serialize(augmentedCommitCharacters, options); + itemRawJsonCache.Add(augmentedCommitCharacters, jsonString); } - } - var label = completionItem.Label; - if (label != null) - { - writer.WritePropertyName("label"); - writer.WriteValue(label); + writer.WritePropertyName(VSInternalCompletionItem.VsCommitCharactersSerializedName); + writer.WriteRawValue(jsonString); } - if (completionItem.LabelDetails != null) + if (vsCompletionItem.VsResolveTextEditOnCommit) { - writer.WritePropertyName("labelDetails"); - serializer.Serialize(writer, completionItem.LabelDetails); + writer.WriteBoolean(VSInternalCompletionItem.VsResolveTextEditOnCommitName, vsCompletionItem.VsResolveTextEditOnCommit); } + } - writer.WritePropertyName("kind"); - writer.WriteValue(completionItem.Kind); - - if (completionItem.Tags != null) - { - writer.WritePropertyName("tags"); - serializer.Serialize(writer, completionItem.Tags); - } + var label = completionItem.Label; + if (label != null) + { + writer.WriteString("label", label); + } - if (completionItem.Detail != null) - { - writer.WritePropertyName("detail"); - writer.WriteValue(completionItem.Detail); - } + if (completionItem.LabelDetails != null) + { + writer.WritePropertyName("labelDetails"); + JsonSerializer.Serialize(writer, completionItem.LabelDetails, options); + } - if (completionItem.Documentation != null) - { - writer.WritePropertyName("documentation"); - serializer.Serialize(writer, completionItem.Documentation); - } + writer.WriteNumber("kind", (int)completionItem.Kind); - // Only render preselect if it's "true" - if (completionItem.Preselect) - { - writer.WritePropertyName("preselect"); - writer.WriteValue(completionItem.Preselect); - } + if (completionItem.Detail != null) + { + writer.WriteString("detail", completionItem.Detail); + } - if (completionItem.SortText != null && !string.Equals(completionItem.SortText, label, StringComparison.Ordinal)) - { - writer.WritePropertyName("sortText"); - writer.WriteValue(completionItem.SortText); - } + if (completionItem.Documentation != null) + { + writer.WritePropertyName("documentation"); + JsonSerializer.Serialize(writer, completionItem.Documentation, options); + } - if (completionItem.FilterText != null && !string.Equals(completionItem.FilterText, label, StringComparison.Ordinal)) - { - writer.WritePropertyName("filterText"); - writer.WriteValue(completionItem.FilterText); - } + // Only render preselect if it's "true" + if (completionItem.Preselect) + { + writer.WriteBoolean("preselect", completionItem.Preselect); + } - if (completionItem.InsertText != null && !string.Equals(completionItem.InsertText, label, StringComparison.Ordinal)) - { - writer.WritePropertyName("insertText"); - writer.WriteValue(completionItem.InsertText); - } + if (completionItem.SortText != null && !string.Equals(completionItem.SortText, label, StringComparison.Ordinal)) + { + writer.WriteString("sortText", completionItem.SortText); + } - if (completionItem.InsertTextFormat != default && completionItem.InsertTextFormat != InsertTextFormat.Plaintext) - { - writer.WritePropertyName("insertTextFormat"); - writer.WriteValue(completionItem.InsertTextFormat); - } + if (completionItem.FilterText != null && !string.Equals(completionItem.FilterText, label, StringComparison.Ordinal)) + { + writer.WriteString("filterText", completionItem.FilterText); + } - if (completionItem.TextEdit != null) - { - writer.WritePropertyName("textEdit"); - serializer.Serialize(writer, completionItem.TextEdit); - } + if (completionItem.InsertText != null && !string.Equals(completionItem.InsertText, label, StringComparison.Ordinal)) + { + writer.WriteString("insertText", completionItem.InsertText); + } - if (completionItem.TextEditText != null) - { - writer.WritePropertyName("textEditText"); - serializer.Serialize(writer, completionItem.TextEditText); - } + if (completionItem.InsertTextFormat != default && completionItem.InsertTextFormat != InsertTextFormat.Plaintext) + { + writer.WriteNumber("insertTextFormat", (int)completionItem.InsertTextFormat); + } - if (completionItem.AdditionalTextEdits != null && completionItem.AdditionalTextEdits.Length > 0) - { - writer.WritePropertyName("additionalTextEdits"); - serializer.Serialize(writer, completionItem.AdditionalTextEdits); - } + if (completionItem.TextEdit != null) + { + writer.WritePropertyName("textEdit"); + JsonSerializer.Serialize(writer, completionItem.TextEdit, options); + } - if (completionItem.CommitCharacters != null && completionItem.CommitCharacters.Length > 0) - { - if (!itemRawJsonCache.TryGetValue(completionItem.CommitCharacters, out var jsonString)) - { - jsonString = JsonConvert.SerializeObject(completionItem.CommitCharacters); - itemRawJsonCache.Add(completionItem.CommitCharacters, jsonString); - } + if (completionItem.TextEditText != null) + { + writer.WritePropertyName("textEditText"); + JsonSerializer.Serialize(writer, completionItem.TextEditText, options); + } - writer.WritePropertyName("commitCharacters"); - writer.WriteRawValue(jsonString); - } + if (completionItem.AdditionalTextEdits != null && completionItem.AdditionalTextEdits.Length > 0) + { + writer.WritePropertyName("additionalTextEdits"); + JsonSerializer.Serialize(writer, completionItem.AdditionalTextEdits, options); + } - if (completionItem.Command != null) + if (completionItem.CommitCharacters != null && completionItem.CommitCharacters.Length > 0) + { + if (!itemRawJsonCache.TryGetValue(completionItem.CommitCharacters, out var jsonString)) { - writer.WritePropertyName("command"); - serializer.Serialize(writer, completionItem.Command); + jsonString = JsonSerializer.Serialize(completionItem.CommitCharacters, options); + itemRawJsonCache.Add(completionItem.CommitCharacters, jsonString); } - if (completionItem.Data != null) - { - writer.WritePropertyName("data"); - serializer.Serialize(writer, completionItem.Data); - } + writer.WritePropertyName("commitCharacters"); + writer.WriteRawValue(jsonString); + } + + if (completionItem.Command != null) + { + writer.WritePropertyName("command"); + JsonSerializer.Serialize(writer, completionItem.Command, options); + } - writer.WriteEndObject(); + if (completionItem.Data != null) + { + writer.WritePropertyName("data"); + JsonSerializer.Serialize(writer, completionItem.Data, options); } + + writer.WriteEndObject(); } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/Text/ClassifiedTextElement.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/Text/ClassifiedTextElement.cs index e472d496076d0..a96c5482e09cb 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/Text/ClassifiedTextElement.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/Text/ClassifiedTextElement.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using Roslyn.Text.Adornments; namespace Roslyn.Text.Adornments { diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSFoldingRangeSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSFoldingRangeSetting.cs index a7d46e257f83e..a2ad7eb9fae76 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSFoldingRangeSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSFoldingRangeSetting.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class used to extend to add internal capabilities. @@ -15,8 +14,8 @@ internal class VSFoldingRangeSetting : FoldingRangeSetting /// /// Gets or sets a value indicating whether if client only supports entire line folding only. /// - [DataMember(Name = "_vs_refreshSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClientCapabilities.cs index 476b1bbc3238e..ec9d0e7459dee 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClientCapabilities.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for ClientCapabilities with fields specific to Visual Studio. /// - [DataContract] internal class VSInternalClientCapabilities : ClientCapabilities { /// /// Gets or sets a value indicating whether client supports Visual Studio extensions. /// - [DataMember(Name = "_vs_supportsVisualStudioExtensions")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsVisualStudioExtensions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsVisualStudioExtensions { get; @@ -28,8 +26,8 @@ public bool SupportsVisualStudioExtensions /// Gets or sets a value indicating what level of snippet support is available from Visual Studio Client. /// v1.0 refers to only default tab stop support i.e. support for $0 which manipualtes the cursor position. /// - [DataMember(Name = "_vs_supportedSnippetVersion")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_supportedSnippetVersion")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalSnippetSupportLevel? SupportedSnippetVersion { get; @@ -39,8 +37,8 @@ public VSInternalSnippetSupportLevel? SupportedSnippetVersion /// /// Gets or sets a value indicating whether client supports omitting document text in textDocument/didOpen notifications. /// - [DataMember(Name = "_vs_supportsNotIncludingTextInTextDocumentDidOpen")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsNotIncludingTextInTextDocumentDidOpen")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsNotIncludingTextInTextDocumentDidOpen { get; @@ -51,8 +49,8 @@ public bool SupportsNotIncludingTextInTextDocumentDidOpen /// Gets or sets a value indicating whether the client supports string based response kinds /// instead of enum based response kinds. /// - [DataMember(Name = "_vs_supportsIconExtensions")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsIconExtensions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsIconExtensions { get; @@ -62,8 +60,8 @@ public bool SupportsIconExtensions /// /// Gets or sets a value indicating whether the client provides support for diagnostic pull requests. /// - [DataMember(Name = "_vs_supportsDiagnosticRequests")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsDiagnosticRequests")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsDiagnosticRequests { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClipboardContent.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClipboardContent.cs index eb25ceed3c90f..4fedc2a05ee70 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClipboardContent.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalClipboardContent.cs @@ -4,18 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents content to be sent to the clipboard. /// - [DataContract] internal class VSInternalClipboardContent { /// /// Gets or sets a string that describes clipboard format types, for example, "text/plain". /// - [DataMember(Name = "_vs_mime", IsRequired = true)] + [JsonPropertyName("_vs_mime")] + [JsonRequired] public string MimeType { get; @@ -25,7 +25,8 @@ public string MimeType /// /// Gets or sets the content of the clipboard. /// - [DataMember(Name = "_vs_content", IsRequired = true)] + [JsonPropertyName("_vs_content")] + [JsonRequired] public string Content { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeAction.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeAction.cs index 2daba780549e6..5b44a7388b215 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeAction.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeAction.cs @@ -5,20 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class used to extend to add the data field for codeAction/_ms_resolve support. /// - [DataContract] internal class VSInternalCodeAction : CodeAction { /// /// Gets or sets the group this CodeAction belongs to. /// - [DataMember(Name = "_vs_group")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_group")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Group { get; @@ -28,8 +26,8 @@ public string? Group /// /// Gets or sets the priority level of the code action. /// - [DataMember(Name = "_vs_priority")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_priority")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalPriorityLevel? Priority { get; @@ -39,8 +37,8 @@ public VSInternalPriorityLevel? Priority /// /// Gets or sets the range of the span this action is applicable to. /// - [DataMember(Name = "_vs_applicableRange")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_applicableRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Range? ApplicableRange { get; @@ -50,8 +48,8 @@ public Range? ApplicableRange /// /// Gets or sets the children of this action. /// - [DataMember(Name = "_vs_children")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_children")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalCodeAction[]? Children { get; @@ -61,8 +59,8 @@ public VSInternalCodeAction[]? Children /// /// Gets or sets the telemetry id of this action. /// - [DataMember(Name = "_vs_telemetryId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_telemetryId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Guid? TelemetryId { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionContext.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionContext.cs index 93a48ed25cbc6..a6384488e787f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionContext.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for the textDocument/codeAction request. /// - [DataContract] internal class VSInternalCodeActionContext : CodeActionContext { /// /// Gets or sets the range of the current selection in the document for which the command was invoked. /// If there is no selection this would be a Zero-length range for the caret position. /// - [DataMember(Name = "_vs_selectionRange")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_selectionRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Range? SelectionRange { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionGroupSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionGroupSetting.cs index 8bd608dbd27fe..87cdca79cd594 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionGroupSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionGroupSetting.cs @@ -4,18 +4,17 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class containing the set of code action default groups that are supported. /// - [DataContract] internal class VSInternalCodeActionGroupSetting { /// /// Gets or sets the code actions default group names the client supports. /// - [DataMember(Name = "_vs_valueSet")] + [JsonPropertyName("_vs_valueSet")] public string[] ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionLiteralSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionLiteralSetting.cs index 58da67255fd31..86e2389eefff3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionLiteralSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCodeActionLiteralSetting.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing support for code action literals. /// - [DataContract] internal class VSInternalCodeActionLiteralSetting : CodeActionLiteralSetting { /// /// Gets or sets a value indicating what code action default groups are supported. /// - [DataMember(Name = "_vs_codeActionGroup")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_codeActionGroup")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalCodeActionGroupSetting? CodeActionGroup { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCommitCharacter.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCommitCharacter.cs index 9e9b8ab8cebf2..1333ec15adfb5 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCommitCharacter.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCommitCharacter.cs @@ -4,24 +4,23 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Extension class for CompletionItem with fields specific to Visual Studio functionalities. /// - [DataContract] internal class VSInternalCommitCharacter { /// /// Gets or sets the commit character. /// - [DataMember(Name = "_vs_character")] + [JsonPropertyName("_vs_character")] public string Character { get; set; } /// /// Gets or sets a value indicating whether the commit character should be inserted or not. /// - [DataMember(Name = "_vs_insert")] + [JsonPropertyName("_vs_insert")] public bool Insert { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionContext.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionContext.cs index fc0b92a2fe216..3bcc6ea57ea39 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionContext.cs @@ -6,23 +6,21 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for with properties specific to Visual Studio. /// - [DataContract] internal class VSInternalCompletionContext : CompletionContext { /// /// Gets or sets the indicating how the completion was triggered. /// - [DataMember(Name = "_vs_invokeKind")] + [JsonPropertyName("_vs_invokeKind")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] [DefaultValue(VSInternalCompletionInvokeKind.Explicit)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public VSInternalCompletionInvokeKind InvokeKind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionInvokeKind.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionInvokeKind.cs index a8bd492e3ebd2..9bd3560beb600 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionInvokeKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionInvokeKind.cs @@ -4,13 +4,10 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Provides value for which specifies /// how completion was invoked. /// - [DataContract] internal enum VSInternalCompletionInvokeKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionItem.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionItem.cs index 7edcd8403e1ef..392f1a00bfac6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionItem.cs @@ -4,14 +4,12 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; using Roslyn.Text.Adornments; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for CompletionItem with fields specific to Visual Studio functionalities. /// - [DataContract] internal class VSInternalCompletionItem : CompletionItem { internal const string IconSerializedName = "_vs_icon"; @@ -22,17 +20,17 @@ internal class VSInternalCompletionItem : CompletionItem /// /// Gets or sets the icon to show for the completion item. In VS, this is more extensive than the completion kind. /// - [DataMember(Name = IconSerializedName)] + [JsonPropertyName(IconSerializedName)] [JsonConverter(typeof(ImageElementConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ImageElement? Icon { get; set; } /// /// Gets or sets the description for a completion item. /// - [DataMember(Name = DescriptionSerializedName)] + [JsonPropertyName(DescriptionSerializedName)] [JsonConverter(typeof(ClassifiedTextElementConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ClassifiedTextElement? Description { get; set; } /// @@ -41,16 +39,16 @@ internal class VSInternalCompletionItem : CompletionItem /// If present, client will use this value instead of . /// If absent, client will default to . /// - [DataMember(Name = VsCommitCharactersSerializedName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(VsCommitCharactersSerializedName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? VsCommitCharacters { get; set; } /// /// Gets or sets a value indicating whether the client should call to /// get the value of the text edit to commit. /// - [DataMember(Name = VsResolveTextEditOnCommitName)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName(VsResolveTextEditOnCommitName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool VsResolveTextEditOnCommit { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionList.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionList.cs index e6984d8584a40..a9063b038b456 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionList.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionList.cs @@ -4,13 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A subclass of the LSP protocol that contains extensions specific to Visual Studio. /// - [DataContract] internal class VSInternalCompletionList : CompletionList { internal const string SuggestionModeSerializedName = "_vs_suggestionMode"; @@ -21,8 +19,8 @@ internal class VSInternalCompletionList : CompletionList /// /// Gets or sets a value indicating whether the completion list should use suggestion mode. In suggestion mode items are "soft-selected" by default. /// - [DataMember(Name = SuggestionModeSerializedName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(SuggestionModeSerializedName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool SuggestionMode { get; @@ -32,8 +30,8 @@ public bool SuggestionMode /// /// Gets or sets the continue characters for the completion list. /// - [DataMember(Name = ContinueCharactersSerializedName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(ContinueCharactersSerializedName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType[]? ContinueCharacters { get; @@ -43,8 +41,8 @@ public SumType /// Gets or sets the default used for completion items. /// - [DataMember(Name = DataSerializedName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(DataSerializedName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data { get; @@ -57,8 +55,8 @@ public object? Data /// /// If set, overrides . /// - [DataMember(Name = CommitCharactersSerializedName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(CommitCharactersSerializedName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? CommitCharacters { get; set; } // NOTE: Any changes that are added to this file may need to be reflected in its "optimized" counterparts JsonConverter (OptomizedVSCompletionListJsonConverter). diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionListSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionListSetting.cs index 4f613cd4e478a..413695d0c9f74 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionListSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionListSetting.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for completion list. /// - [DataContract] internal class VSInternalCompletionListSetting { /// /// Gets or sets a value indicating whether completion lists can have Data bags. These data bags get propagated /// onto underlying completion items unless they have their own data bags. /// - [DataMember(Name = "_vs_data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool Data { get; @@ -29,8 +27,8 @@ public bool Data /// Gets or sets a value indicating whether completion lists can have VSCommitCharacters. These commit characters get propagated /// onto underlying valid completion items unless they have their own commit characters. /// - [DataMember(Name = "_vs_commitCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_commitCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool CommitCharacters { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionSetting.cs index 41cd0d069d8cb..9496e3f1eecd2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalCompletionSetting.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for VS completion. /// - [DataContract] internal class VSInternalCompletionSetting : CompletionSetting { /// /// Gets or sets completion list setting. /// - [DataMember(Name = "_vs_completionList")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_completionList")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalCompletionListSetting? CompletionList { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterClass.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterClass.cs index dbfacba1f2cf3..e59831f19eeae 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterClass.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterClass.cs @@ -4,27 +4,25 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a unicode character class for completion continuation. /// - [DataContract] internal class VSInternalContinueCharacterClass { /// /// Gets the type value. /// - [DataMember(Name = "_vs_type")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_type")] + [JsonRequired] public const string Type = "unicodeClass"; /// /// Gets or sets the unicode class. /// - [DataMember(Name = "_vs_unicodeClass")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_unicodeClass")] + [JsonRequired] public string UnicodeClass { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterRange.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterRange.cs index 46bc21e6ba34f..d464790256715 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterRange.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterRange.cs @@ -4,34 +4,32 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing range of characters for completion continuation. /// - [DataContract] internal class VSInternalContinueCharacterRange { /// /// Gets the type value. /// - [DataMember(Name = "_vs_type")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_type")] + [JsonRequired] public const string Type = "charRange"; /// /// Gets or sets the first completion character of the range. /// - [DataMember(Name = "_vs_start")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_start")] + [JsonRequired] public string Start { get; set; } /// /// Gets or sets the last completion character of the range. /// - [DataMember(Name = "_vs_end")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_end")] + [JsonRequired] public string End { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterSingle.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterSingle.cs index 233e1e82129e2..cb2af1a924f5d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterSingle.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalContinueCharacterSingle.cs @@ -4,27 +4,25 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing single continue character for completion. /// - [DataContract] internal class VSInternalContinueCharacterSingle { /// /// Gets the type value. /// - [DataMember(Name = "_vs_type")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_type")] + [JsonRequired] public const string Type = "singleChar"; /// /// Gets or sets the completion character. /// - [DataMember(Name = "_vs_char")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_char")] + [JsonRequired] public string Character { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertOptions.cs index 785e96b9decad..378ff67e08581 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertOptions.cs @@ -4,18 +4,17 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the options for on auto insert. /// - [DataContract] internal class VSInternalDocumentOnAutoInsertOptions { /// /// Gets or sets trigger characters for on auto insert. /// - [DataMember(Name = "_vs_triggerCharacters")] + [JsonPropertyName("_vs_triggerCharacters")] public string[] TriggerCharacters { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertParams.cs index 4fe5d9c1897a7..0000038032286 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertParams.cs @@ -4,18 +4,17 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/_ms_onAutoInsert request. /// - [DataContract] internal class VSInternalDocumentOnAutoInsertParams : ITextDocumentPositionParams { /// /// Gets or sets the representing the document to format. /// - [DataMember(Name = "_vs_textDocument")] + [JsonPropertyName("_vs_textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -25,7 +24,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the at which the request was sent. /// - [DataMember(Name = "_vs_position")] + [JsonPropertyName("_vs_position")] public Position Position { get; @@ -35,7 +34,7 @@ public Position Position /// /// Gets or sets the character that was typed. /// - [DataMember(Name = "_vs_ch")] + [JsonPropertyName("_vs_ch")] public string Character { get; @@ -45,7 +44,7 @@ public string Character /// /// Gets or sets the for the request. /// - [DataMember(Name = "_vs_options")] + [JsonPropertyName("_vs_options")] public FormattingOptions Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertResponseItem.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertResponseItem.cs index d9b52602383c3..f196732392f86 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertResponseItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentOnAutoInsertResponseItem.cs @@ -6,20 +6,18 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the response of an AutoInsert response. /// - [DataContract] internal class VSInternalDocumentOnAutoInsertResponseItem { /// /// Gets or sets the insert text format of the primary text edit. for supported formats. /// - [DataMember(Name = "_vs_textEditFormat")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_textEditFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [DefaultValue(InsertTextFormat.Plaintext)] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] @@ -32,8 +30,8 @@ public InsertTextFormat TextEditFormat /// /// Gets or sets the text edit. /// - [DataMember(Name = "_vs_textEdit")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_textEdit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextEdit TextEdit { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs index 2bee314d31fa6..e3634b57d5e98 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs @@ -5,22 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Collections.Generic; - using System.Runtime.Serialization; - using System.Text; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Parameter for tD/_vs_spellCheckableRanges. /// - [DataContract] internal class VSInternalDocumentSpellCheckableParams : VSInternalStreamingParams, IPartialResultParams { /// /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. /// - [DataMember(Name = Methods.PartialResultTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalExecuteCommandClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalExecuteCommandClientCapabilities.cs index ba2abd3e80a02..168d365a49115 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalExecuteCommandClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalExecuteCommandClientCapabilities.cs @@ -4,12 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing settings for well-known Visual Studio's code action command. /// - [DataContract] internal class VSInternalExecuteCommandClientCapabilities : DynamicRegistrationSetting { /// @@ -31,7 +30,7 @@ public VSInternalExecuteCommandClientCapabilities(bool value) /// /// Gets or sets a set of well-known commands name the given VS-LSP client supports. /// - [DataMember(Name = "_vs_supportedCommands")] + [JsonPropertyName("_vs_supportedCommands")] public string[] SupportedCommands { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs index de87ad88193bc..2dcd51847ce4d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension to Hover which adds additional data for colorization. @@ -18,9 +17,9 @@ internal class VSInternalHover : Hover /// of objects from the Microsoft.VisualStudio.Text.Adornments namespace, /// such as ContainerElements, ClassifiedTextElements and ClassifiedTextRuns. /// - [DataMember(Name = "_vs_rawContent")] + [JsonPropertyName("_vs_rawContent")] [JsonConverter(typeof(ObjectContentConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? RawContent { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalIconMapping.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalIconMapping.cs index aaf0fe7a8517a..a46ad067f020a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalIconMapping.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalIconMapping.cs @@ -5,20 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Response class when asking server to resolve the rendering information of a string kind. /// - [DataContract] internal class VSInternalIconMapping : IEquatable { /// /// Gets or sets the ImageElements for a certain kind. /// - [DataMember(Name = "_vs_images")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_images")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSImageId[]? Images { get; @@ -28,8 +26,8 @@ public VSImageId[]? Images /// /// Gets or sets the tags for a certain kind. To be used in the absence of ImageIds. /// - [DataMember(Name = "_vs_tags")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? Tags { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionContext.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionContext.cs index a3ab7943d4821..0c40cfcfc3b28 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionContext.cs @@ -4,9 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Context for inline completion request. @@ -18,8 +16,8 @@ internal class VSInternalInlineCompletionContext /// /// Gets or sets how completion was triggered. /// - [DataMember(Name = "_vs_triggerKind")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_triggerKind")] + [JsonRequired] public VSInternalInlineCompletionTriggerKind TriggerKind { get; set; } = VSInternalInlineCompletionTriggerKind.Explicit; /// @@ -27,8 +25,8 @@ internal class VSInternalInlineCompletionContext /// /// See https://github.com/microsoft/vscode/blob/075ba020e8493f40dba89891b1a08453f2c067e9/src/vscode-dts/vscode.proposed.inlineCompletions.d.ts#L45. /// - [DataMember(Name = "_vs_selectedCompletionInfo")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_selectedCompletionInfo")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public VSInternalSelectedCompletionInfo? SelectedCompletionInfo { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionItem.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionItem.cs index 740c6799c26d9..1c2520f3a6b4b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionItem.cs @@ -4,9 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// A single inline completion item response. @@ -19,8 +17,8 @@ internal class VSInternalInlineCompletionItem /// /// Gets or sets the text to replace the range with. /// - [DataMember(Name = "_vs_text")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_text")] + [JsonRequired] public string Text { get; set; } /// @@ -28,22 +26,22 @@ internal class VSInternalInlineCompletionItem /// /// See https://github.com/microsoft/vscode/blob/075ba020e8493f40dba89891b1a08453f2c067e9/src/vscode-dts/vscode.proposed.inlineCompletions.d.ts#L94. /// - [DataMember(Name = "_vs_range")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Range? Range { get; set; } /// /// Gets or sets the command that is executed after inserting this completion item. /// - [DataMember(Name = "_vs_command")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_command")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Command? Command { get; set; } /// /// Gets or sets the format of the insert text. /// - [DataMember(Name = "_vs_insertTextFormat")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_insertTextFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public InsertTextFormat? TextFormat { get; set; } = InsertTextFormat.Plaintext; } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionList.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionList.cs index 57c7957df661b..8fc7113870e2a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionList.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionList.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Response for an inline completions request. @@ -18,8 +17,8 @@ internal class VSInternalInlineCompletionList /// /// Gets or sets the inline completion items. /// - [DataMember(Name = "_vs_items")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_items")] + [JsonRequired] public VSInternalInlineCompletionItem[] Items { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionOptions.cs index b73012d5900e8..113e1d17b6fdf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionOptions.cs @@ -4,22 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; using System.Text.RegularExpressions; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// The options for inline completion. /// - [DataContract] internal class VSInternalInlineCompletionOptions { /// /// Gets or sets a regex used by the client to determine when to ask the server for snippets. /// - [DataMember(Name = "_vs_pattern")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_pattern")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonConverter(typeof(RegexConverter))] public Regex Pattern { get; set; } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionRequest.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionRequest.cs index a57c4f294d4db..3a7e067efbb49 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionRequest.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionRequest.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// The request data for an inline completions request. @@ -18,28 +17,28 @@ internal class VSInternalInlineCompletionRequest : ITextDocumentParams /// /// Gets or sets the text document. /// - [DataMember(Name = "_vs_textDocument")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; set; } /// /// Gets or sets the position where inline completions are being requested. /// - [DataMember(Name = "_vs_position")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_position")] + [JsonRequired] public Position Position { get; set; } /// /// Gets or sets the context for the inline completions request. /// - [DataMember(Name = "_vs_context")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_context")] + [JsonRequired] public VSInternalInlineCompletionContext Context { get; set; } /// /// Gets or sets the for the request. /// - [DataMember(Name = "_vs_options")] + [JsonPropertyName("_vs_options")] public FormattingOptions Options { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionTriggerKind.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionTriggerKind.cs index 476a038b93d7f..0a0f4335811de 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionTriggerKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalInlineCompletionTriggerKind.cs @@ -4,13 +4,10 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// How the inline completion request was triggered. /// See https://github.com/microsoft/vscode/blob/075ba020e8493f40dba89891b1a08453f2c067e9/src/vscode-dts/vscode.proposed.inlineCompletions.d.ts#L58. /// - [DataContract] internal enum VSInternalInlineCompletionTriggerKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalKindAndModifier.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalKindAndModifier.cs index 6167f1ff419e3..9ad6c9c4e99ad 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalKindAndModifier.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalKindAndModifier.cs @@ -5,19 +5,17 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class that contains the base kind and modifiers used to describe a response item. /// - [DataContract] internal class VSInternalKindAndModifier : IEquatable { /// /// Gets or sets the ImageIds for a certain kind. /// - [DataMember(Name = "_vs_kind")] + [JsonPropertyName("_vs_kind")] public string Kind { get; @@ -27,8 +25,8 @@ public string Kind /// /// Gets or sets the modifier of the kind. /// - [DataMember(Name = "_vs_modifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_modifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? Modifier { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalLocation.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalLocation.cs index 4c62c6fb74ec5..915dc06853f81 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalLocation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalLocation.cs @@ -5,14 +5,12 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; using Roslyn.Text.Adornments; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for . Used to relay reference text information with colorization. /// - [DataContract] internal class VSInternalLocation : VSLocation { private object? textValue = null; @@ -20,9 +18,9 @@ internal class VSInternalLocation : VSLocation /// /// Gets or sets the text value for a location reference. Must be of type or or or . /// - [DataMember(Name = "_vs_text")] + [JsonPropertyName("_vs_text")] [JsonConverter(typeof(ObjectContentConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Text { get diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeMapping.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeMapping.cs index 26394166fef4a..ab32d5981107d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeMapping.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeMapping.cs @@ -4,17 +4,15 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; - [DataContract] internal class VSInternalMapCodeMapping { /// /// Gets or sets identifier for the document the contents are supposed to be mapped into. /// - [DataMember(Name = "_vs_textDocument")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_textDocument")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextDocumentIdentifier? TextDocument { get; @@ -24,7 +22,7 @@ public TextDocumentIdentifier? TextDocument /// /// Gets or sets strings of code/text to map into TextDocument. /// - [DataMember(Name = "_vs_contents")] + [JsonPropertyName("_vs_contents")] public string[] Contents { get; @@ -36,8 +34,8 @@ public string[] Contents /// related classes (in other documents), viewport, etc. Earlier items should be considered /// higher priority. /// - [DataMember(Name = "_vs_focusLocations")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_focusLocations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Location[][]? FocusLocations { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeParams.cs index 6932c4d998bb2..e1460443c6612 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalMapCodeParams.cs @@ -4,19 +4,17 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// LSP Params for textDocument/mapCode calls. /// - [DataContract] internal class VSInternalMapCodeParams { /// /// Set of code blocks, associated with documents and regions, to map. /// - [DataMember(Name = "_vs_mappings")] + [JsonPropertyName("_vs_mappings")] public VSInternalMapCodeMapping[] Mappings { get; @@ -27,8 +25,8 @@ public VSInternalMapCodeMapping[] Mappings /// Changes that should be applied to the workspace by the mapper before performing /// the mapping operation. /// - [DataMember(Name = "_vs_updates")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_updates")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public WorkspaceEdit? Updates { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalProjectContext.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalProjectContext.cs index 4334c1b2aff26..647eb28637172 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalProjectContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalProjectContext.cs @@ -5,20 +5,18 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class for a project context. /// - [DataContract] internal class VSInternalProjectContext : VSProjectContext, IEquatable { /// /// Gets or sets the string context kind of the project context. /// - [DataMember(Name = "_vs_vsKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_vsKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalKindAndModifier? VSKind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceItem.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceItem.cs index cf551ec93172e..add3d0afb01b7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceItem.cs @@ -5,14 +5,12 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; using Roslyn.Text.Adornments; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents references information. /// - [DataContract] internal class VSInternalReferenceItem { private object? definitionTextValue = null; @@ -21,7 +19,8 @@ internal class VSInternalReferenceItem /// /// Gets or sets the reference id. /// - [DataMember(Name = "_vs_id", IsRequired = true)] + [JsonPropertyName("_vs_id")] + [JsonRequired] public int Id { get; @@ -31,7 +30,7 @@ public int Id /// /// Gets or sets the reference location. /// - [DataMember(Name = "_vs_location")] + [JsonPropertyName("_vs_location")] public Location Location { get; @@ -41,8 +40,8 @@ public Location Location /// /// Gets or sets the definition Id. /// - [DataMember(Name = "_vs_definitionId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_definitionId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? DefinitionId { get; @@ -57,9 +56,9 @@ public int? DefinitionId /// This element should colorize syntax, but should not contain highlighting, e.g. /// embedded within should not define . /// - [DataMember(Name = "_vs_definitionText")] + [JsonPropertyName("_vs_definitionText")] [JsonConverter(typeof(ObjectContentConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? DefinitionText { get @@ -84,7 +83,7 @@ public object? DefinitionText /// /// Gets or sets the resolution status. /// - [DataMember(Name = "_vs_resolutionStatus")] + [JsonPropertyName("_vs_resolutionStatus")] public VSInternalResolutionStatusKind ResolutionStatus { get; @@ -94,7 +93,7 @@ public VSInternalResolutionStatusKind ResolutionStatus /// /// Gets or sets the reference kind. /// - [DataMember(Name = "_vs_kind")] + [JsonPropertyName("_vs_kind")] public VSInternalReferenceKind[] Kind { get; @@ -104,29 +103,29 @@ public VSInternalReferenceKind[] Kind /// /// Gets or sets the document name to be displayed to user when needed.This can be used in cases where URI doesn't have a user friendly file name or it is a remote URI. /// - [DataMember(Name = "_vs_documentName")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_documentName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? DocumentName { get; set; } /// /// Gets or sets the project name. /// - [DataMember(Name = "_vs_projectName")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_projectName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ProjectName { get; set; } /// /// Gets or sets the containing type. /// - [DataMember(Name = "_vs_containingType")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_containingType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ContainingType { get; set; } /// /// Gets or sets the containing member. /// - [DataMember(Name = "_vs_containingMember")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_containingMember")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ContainingMember { get; set; } /// @@ -146,9 +145,9 @@ public VSInternalReferenceKind[] Kind /// "MarkerFormatDefinition/HighlightedDefinition" for definitions. /// /// - [DataMember(Name = "_vs_text")] + [JsonPropertyName("_vs_text")] [JsonConverter(typeof(ObjectContentConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Text { get @@ -173,23 +172,23 @@ public object? Text /// Gets or sets the text value for display path.This would be a friendly display name for scenarios where the actual path on disk may be confusing for users. /// This doesn't have to correspond to a real file path, but does need to be parsable by the various Path.GetFileName() methods. /// - [DataMember(Name = "_vs_displayPath")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_displayPath")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? DisplayPath { get; set; } /// /// Gets or sets the origin of the item.The origin is used to filter remote results. /// - [DataMember(Name = "_vs_origin")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_origin")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalItemOrigin? Origin { get; set; } /// /// Gets or sets the icon to show for the definition header. /// - [DataMember(Name = "_vs_definitionIcon")] + [JsonPropertyName("_vs_definitionIcon")] [JsonConverter(typeof(ImageElementConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ImageElement? DefinitionIcon { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceKind.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceKind.cs index b511340956f5c..28c2d6c76a120 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceKind.cs @@ -4,8 +4,6 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Diagnostics.CodeAnalysis; - /// /// Enum which represents the various reference kinds. /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs index ef0a031bbb6dd..b589fd7e9b218 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents extensions of passed as parameter of find reference requests. @@ -16,8 +15,8 @@ internal class VSInternalReferenceParams : ReferenceParams /// /// Gets or sets a value indicating the scope of returned items. /// - [DataMember(Name = "_vs_scope")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_scope")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalItemOrigin? Scope { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSelection.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSelection.cs index 4fe711ae387b5..6c7eeee8638bc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSelection.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSelection.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the user configuration (as defined in ) for a rename request. /// - [DataContract] internal class VSInternalRenameOptionSelection { /// /// Gets or sets the name that identifies the option. /// - [DataMember(Name = "_vs_name")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_name")] + [JsonRequired] public string Name { get; @@ -27,8 +25,8 @@ public string Name /// /// Gets or sets a value indicating whether the user selected the option. /// - [DataMember(Name = "_vs_value")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_value")] + [JsonRequired] public bool Value { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSupport.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSupport.cs index 4614f862c3eb2..23e893e123907 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSupport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameOptionSupport.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a renaming option for customizing the edit in the 'textDocument/rename' request. /// - [DataContract] internal class VSInternalRenameOptionSupport { /// /// Gets or sets the name that identifies the option. /// - [DataMember(Name = "_vs_name")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_name")] + [JsonRequired] public string Name { get; @@ -27,8 +25,8 @@ public string Name /// /// Gets or sets the user-facing option label. /// - [DataMember(Name = "_vs_label")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_label")] + [JsonRequired] public string Label { get; @@ -38,8 +36,8 @@ public string Label /// /// Gets or sets a value indicating whether the option has a default value of true. /// - [DataMember(Name = "_vs_default")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Default { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameParams.cs index 969228507d1b8..2281272ecd8b8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameParams.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters (together with extra VS-specific options) sent for the /// 'textDocument/rename' request. /// - [DataContract] internal class VSInternalRenameParams : RenameParams { /// /// Gets or sets the rename option values as selected by the user. /// - [DataMember(Name = "_vs_optionSelections")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_optionSelections")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalRenameOptionSelection[]? OptionSelections { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameRange.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameRange.cs index 092944a6dadae..4f144aaa2c8bd 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameRange.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalRenameRange.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a possible result value of the 'textDocument/prepareRename' request, /// together with extra VS-specific options. /// - [DataContract] internal class VSInternalRenameRange : RenameRange { /// /// Gets or sets the supported options for the rename request. /// - [DataMember(Name = "_vs_supportedOptions")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_supportedOptions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalRenameOptionSupport[]? SupportedOptions { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSelectedCompletionInfo.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSelectedCompletionInfo.cs index 963cc264e0acf..85c150b74778f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSelectedCompletionInfo.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSelectedCompletionInfo.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Information about the selected completion item for . @@ -18,29 +17,29 @@ internal class VSInternalSelectedCompletionInfo /// /// Gets or sets the range of the selected completion item. /// - [DataMember(Name = "_vs_range")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Range Range { get; set; } /// /// Gets or sets the text of the selected completion item. /// - [DataMember(Name = "_vs_text")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_text")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string Text { get; set; } /// /// Gets or sets the completion item kind of the selected completion item. /// - [DataMember(Name = "_vs_completionKind")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_completionKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public CompletionItemKind CompletionKind { get; set; } /// /// Gets or sets a value indicating whether the completion item is a snippet. /// - [DataMember(Name = "_vs_isSnippetText")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_isSnippetText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IsSnippetText { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalServerCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalServerCapabilities.cs index b8758f0f60161..b0c441bcd1a93 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalServerCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalServerCapabilities.cs @@ -4,15 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System; - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for ServerCapabilities with fields specific to Visual Studio. /// - [DataContract] internal class VSInternalServerCapabilities : VSServerCapabilities { /// @@ -24,8 +20,8 @@ internal class VSInternalServerCapabilities : VSServerCapabilities /// This is provided to facilitate transition from in-proc to OOP for teams that /// currently own both a Language Server for Ctrl+Q and a GoTo provider. /// - [DataMember(Name = "_vs_disableGoToWorkspaceSymbols")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_disableGoToWorkspaceSymbols")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DisableGoToWorkspaceSymbols { get; @@ -35,8 +31,8 @@ public bool DisableGoToWorkspaceSymbols /// /// Gets or sets a value indicating whether document/_ms_references is supported. /// - [DataMember(Name = "_vs_ReferencesProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_ReferencesProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool MSReferencesProvider { get; @@ -46,8 +42,8 @@ public bool MSReferencesProvider /// /// Gets or sets a value indicating whether the server supports OnAutoInsert. /// - [DataMember(Name = "_vs_onAutoInsertProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_onAutoInsertProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDocumentOnAutoInsertOptions? OnAutoInsertProvider { get; @@ -58,8 +54,8 @@ public VSInternalDocumentOnAutoInsertOptions? OnAutoInsertProvider /// Gets or sets a value indicating whether the server requires document text to be included in textDocument/didOpen notifications. /// /// This capability is not intended to be included into the official LSP, hence _ms_ prefix. - [DataMember(Name = "_vs_doNotIncludeTextInTextDocumentDidOpen")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_doNotIncludeTextInTextDocumentDidOpen")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DoNotIncludeTextInTextDocumentDidOpen { get; @@ -69,8 +65,8 @@ public bool DoNotIncludeTextInTextDocumentDidOpen /// /// Gets or sets a value indicating whether the server provides support to resolve string based response kinds. /// - [DataMember(Name = "_vs_KindDescriptionResolveProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_KindDescriptionResolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool KindDescriptionResolveProvider { get; @@ -80,8 +76,8 @@ public bool KindDescriptionResolveProvider /// /// Gets or sets a value indicating whether the server provides support for diagnostic pull requests. /// - [DataMember(Name = "_vs_supportsDiagnosticRequests")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_supportsDiagnosticRequests")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SupportsDiagnosticRequests { get; @@ -91,8 +87,8 @@ public bool SupportsDiagnosticRequests /// /// Gets or sets server specified options for diagnostic pull requests. /// - [DataMember(Name = "_vs_diagnosticProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_diagnosticProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalDiagnosticOptions? DiagnosticProvider { get; @@ -102,8 +98,8 @@ public VSInternalDiagnosticOptions? DiagnosticProvider /// /// Gets or sets a value indicating whether the server provides support for inline completion requests. /// - [DataMember(Name = "_vs_inlineCompletionOptions")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_inlineCompletionOptions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalInlineCompletionOptions? InlineCompletionOptions { get; @@ -113,8 +109,8 @@ public VSInternalInlineCompletionOptions? InlineCompletionOptions /// /// Gets or sets a value indicating whether the server provides support for spell checking. /// - [DataMember(Name = "_vs_spellCheckingProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_spellCheckingProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SpellCheckingProvider { get; @@ -124,8 +120,8 @@ public bool SpellCheckingProvider /// /// Gets or sets a value indicating whether the server supports validating breakable ranges. /// - [DataMember(Name = "_vs_breakableRangeProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_breakableRangeProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool BreakableRangeProvider { get; @@ -135,8 +131,8 @@ public bool BreakableRangeProvider /// /// Gets or sets a value indicating whether the server supports uri presentation. /// - [DataMember(Name = "_vs_uriPresentationProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_uriPresentationProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool UriPresentationProvider { get; @@ -146,8 +142,8 @@ public bool UriPresentationProvider /// /// Gets or sets a value indicating whether the server supports text presentation. /// - [DataMember(Name = "_vs_textPresentationProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_textPresentationProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool TextPresentationProvider { get; @@ -157,8 +153,8 @@ public bool TextPresentationProvider /// /// Gets or sets the value which indicates what support the server has for code mapping. /// - [DataMember(Name = "_vs_mapCodeProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("_vs_mapCodeProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool MapCodeProvider { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSignatureInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSignatureInformation.cs index 74ca607565159..375585cc5c934 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSignatureInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSignatureInformation.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; using Roslyn.Text.Adornments; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for signature help information which contains colorized label information. /// - [DataContract] internal class VSInternalSignatureInformation : SignatureInformation { /// /// Gets or sets the value representing the colorized label. /// - [DataMember(Name = "_vs_colorizedLabel")] + [JsonPropertyName("_vs_colorizedLabel")] [JsonConverter(typeof(ClassifiedTextElementConverter))] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ClassifiedTextElement? ColorizedLabel { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSpellCheckableRangeReport.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSpellCheckableRangeReport.cs index ca3264b7e8c30..c0acf2fc98f8b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSpellCheckableRangeReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSpellCheckableRangeReport.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Report of spell checkable ranges. /// - [DataContract] internal class VSInternalSpellCheckableRangeReport { /// @@ -21,8 +18,8 @@ internal class VSInternalSpellCheckableRangeReport /// spell checkable ranges. The server can use this result ID to avoid resending /// spell checkable ranges that had previously been sent. /// - [DataMember(Name = "_vs_resultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_resultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ResultId { get; set; } /// @@ -56,8 +53,8 @@ internal class VSInternalSpellCheckableRangeReport /// 5 // Span length /// ] /// - [DataMember(Name = "_vs_ranges")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_ranges")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int[]? Ranges { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalStreamingParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalStreamingParams.cs index 3b0e082213ebe..173f983b6b293 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalStreamingParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalStreamingParams.cs @@ -4,21 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a streaming pull request parameter used. /// /// TODO: Deprecate VSInternalDiagnosticParams.cs to use this merged param instead. /// - [DataContract] internal class VSInternalStreamingParams : ITextDocumentParams { /// /// Gets or sets the document for which the feature is being requested for. /// - [DataMember(Name = "_vs_textDocument", IsRequired = true)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; set; } /// @@ -40,8 +39,8 @@ internal class VSInternalStreamingParams : ITextDocumentParams /// document, then all reports are expected to have the same /// previousResultId. /// - [DataMember(Name = "_vs_previousResultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_previousResultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? PreviousResultId { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSymbolInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSymbolInformation.cs index 7e241f9b91960..469c85e86b4a7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSymbolInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalSymbolInformation.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Extension class for SymbolInformation with fields specific to Visual Studio functionalities. @@ -13,14 +12,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// This is a temporary protocol and should not be used. /// - [DataContract] internal class VSInternalSymbolInformation : VSSymbolInformation { /// /// Gets or sets the string kind used for icons. /// - [DataMember(Name = "_vs_vsKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_vsKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalKindAndModifier? VSKind { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentClientCapabilities.cs index abc8b2b3749ed..3a7d0af7a9725 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentClientCapabilities.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Text document capabilities specific to Visual Studio. @@ -16,8 +15,8 @@ internal class VSInternalTextDocumentClientCapabilities : TextDocumentClientCapa /// /// Gets or sets the setting which determines if on auto insert can be dynamically registered. /// - [DataMember(Name = "_vs_onAutoInsert")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_onAutoInsert")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? OnAutoInsert { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentRegistrationOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentRegistrationOptions.cs index e73b246d01f2e..933950179ae0a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentRegistrationOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextDocumentRegistrationOptions.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// / Class representing the options for registering textDocument/_vs_OnAutoInsert support. /// - [DataContract] internal class VSInternalTextDocumentRegistrationOptions : TextDocumentRegistrationOptions { /// /// Gets or sets trigger characters for on auto insert. /// - [DataMember(Name = "_vs_triggerCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_triggerCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? TriggerCharacters { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextPresentationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextPresentationParams.cs index 3ec280d525972..e2cd66192521e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextPresentationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalTextPresentationParams.cs @@ -4,20 +4,18 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/_vs_textPresentation request. /// - [DataContract] internal class VSInternalTextPresentationParams : ITextDocumentParams { /// /// Gets or sets the identifier for the text document to be operate on. /// - [DataMember(Name = "_vs_textDocument")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -27,8 +25,8 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the range. /// - [DataMember(Name = "_vs_range")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_range")] + [JsonRequired] public Range Range { get; @@ -38,7 +36,7 @@ public Range Range /// /// Gets or sets the text. /// - [DataMember(Name = "_vs_text")] + [JsonPropertyName("_vs_text")] public string? Text { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalUriPresentationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalUriPresentationParams.cs index 3736b48506e1e..99fa2ac931edf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalUriPresentationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalUriPresentationParams.cs @@ -5,20 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/_vs_uriPresentation request. /// - [DataContract] internal class VSInternalUriPresentationParams : ITextDocumentParams { /// /// Gets or sets the identifier for the text document to be operate on. /// - [DataMember(Name = "_vs_textDocument")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -28,8 +27,8 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the range. /// - [DataMember(Name = "_vs_range")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("_vs_range")] + [JsonRequired] public Range Range { get; @@ -39,8 +38,7 @@ public Range Range /// /// Gets or sets the URI values. Valid for DropKind.Uris. /// - [DataMember(Name = "_vs_uris")] - [JsonProperty(ItemConverterType = typeof(DocumentUriConverter))] + [JsonPropertyName("_vs_uris")] public Uri[]? Uris { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalValidateBreakableRangeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalValidateBreakableRangeParams.cs index f9a4464b2e282..e216a5b4aed8f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalValidateBreakableRangeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalValidateBreakableRangeParams.cs @@ -4,24 +4,23 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for the textDocument/validateBreakableRange request. /// - [DataContract] internal class VSInternalValidateBreakableRangeParams : ITextDocumentParams { /// /// Gets or sets the for the request. /// - [DataMember(Name = "_vs_textDocument")] + [JsonPropertyName("_vs_textDocument")] public TextDocumentIdentifier TextDocument { get; set; } /// /// Gets or sets the at which the request was sent. /// - [DataMember(Name = "_vs_range")] + [JsonPropertyName("_vs_range")] public Range Range { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs index 516eb1c8218ea..417638b7bd55d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs @@ -5,29 +5,25 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Collections.Generic; - using System.Runtime.Serialization; - using System.Text; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Parameter for workspace/_vs_spellCheckableRanges. /// - [DataContract] internal class VSInternalWorkspaceSpellCheckableParams : IPartialResultParams { /// /// Gets or sets the current state of the documents the client already has received. /// - [DataMember(Name = "_vs_previousResults")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_previousResults")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public VSInternalStreamingParams[]? PreviousResults { get; set; } /// /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. /// - [DataMember(Name = "_vs_partialResultToken")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("_vs_partialResultToken")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableReport.cs b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableReport.cs index a844892b092b1..5bfce67da8ca2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableReport.cs @@ -2,23 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol { - using System; - using System.Collections.Generic; - using System.Runtime.Serialization; - using System.Text; - /// /// Report for workspace spell checkable range request. /// - [DataContract] internal class VSInternalWorkspaceSpellCheckableReport : VSInternalSpellCheckableRangeReport, ITextDocumentParams { /// /// Gets or sets the document for which the spell checkable ranges are returned. /// - [DataMember(Name = "_vs_textDocument", IsRequired = true)] + [JsonPropertyName("_vs_textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs index 4ad14537b3856..16d07390197b3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents linked editing range capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class LinkedEditingRangeOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs index d24bfd158ddd3..78cbad670a95f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Class representing the parameters sent for a textDocument/linkedEditingRange request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class LinkedEditingRangeParams : TextDocumentPositionParams { } diff --git a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs index 9c0b78fd5c768..a60978b1e0cb9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the response of an LinkedEditingRanges response. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class LinkedEditingRanges { /// /// Gets or sets the ranges for the type rename. /// - [DataMember(Name = "ranges")] + [JsonPropertyName("ranges")] public Range[] Ranges { get; @@ -28,8 +26,8 @@ public Range[] Ranges /// /// Gets or sets the word pattern for the type rename. /// - [DataMember(Name = "wordPattern")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("wordPattern")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? WordPattern { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Location.cs b/src/Features/LanguageServer/Protocol/Protocol/Location.cs index e91082e4441dd..123dfea04440a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Location.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Location.cs @@ -6,21 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Collections.Generic; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a location in a document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Location : IEquatable { /// /// Gets or sets the URI for the document the location belongs to. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -31,7 +29,7 @@ public Uri Uri /// /// Gets or sets the range of the location in the document. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/LogMessageParams.cs b/src/Features/LanguageServer/Protocol/Protocol/LogMessageParams.cs index 8d80b156e99a5..6918677cc3014 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/LogMessageParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/LogMessageParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents parameter sent with window/logMessage requests. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class LogMessageParams { /// /// Gets or sets the type of message. /// - [DataMember(Name = "type")] + [JsonPropertyName("type")] public MessageType MessageType { get; @@ -27,7 +26,7 @@ public MessageType MessageType /// /// Gets or sets the message. /// - [DataMember(Name = "message")] + [JsonPropertyName("message")] public string Message { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/MarkedString.cs b/src/Features/LanguageServer/Protocol/Protocol/MarkedString.cs index 62c6b0d8a16d1..3ca516d0589ab 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/MarkedString.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/MarkedString.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing human readable text that should be rendered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class MarkedString { /// /// Gets or sets the language of the code stored in . /// - [DataMember(Name = "language")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("language")] + [JsonRequired] public string Language { get; @@ -29,8 +27,8 @@ public string Language /// /// Gets or sets the code. /// - [DataMember(Name = "value")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("value")] + [JsonRequired] public string Value { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/MarkupContent.cs b/src/Features/LanguageServer/Protocol/Protocol/MarkupContent.cs index ce92eda072808..de670049566fc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/MarkupContent.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/MarkupContent.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing text and an associated format that should be rendered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class MarkupContent { /// /// Gets or sets the representing the text's format. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] public MarkupKind Kind { get; @@ -27,7 +26,7 @@ public MarkupKind Kind /// /// Gets or sets the text that should be rendered. /// - [DataMember(Name = "value")] + [JsonPropertyName("value")] public string Value { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/MarkupKind.cs b/src/Features/LanguageServer/Protocol/Protocol/MarkupKind.cs index 29dda1ba997c7..e4ec736ad7694 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/MarkupKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/MarkupKind.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the various formats of markup text. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct MarkupKind(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/MessageActionItem.cs b/src/Features/LanguageServer/Protocol/Protocol/MessageActionItem.cs index 4dc981f6f1827..8f4739241c9e2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/MessageActionItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/MessageActionItem.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represent an action the user performs after a window/showMessageRequest request is sent. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class MessageActionItem { /// /// Gets or sets the title. /// - [DataMember(Name = "title")] + [JsonPropertyName("title")] public string Title { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/MessageType.cs b/src/Features/LanguageServer/Protocol/Protocol/MessageType.cs index 3b243d8a2f55f..b36f16e24c9d4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/MessageType.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/MessageType.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Message type enum. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum MessageType { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/OptionalVersionedTextDocumentIdentifier.cs b/src/Features/LanguageServer/Protocol/Protocol/OptionalVersionedTextDocumentIdentifier.cs index d34f9a1010fd7..32004eb595da6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/OptionalVersionedTextDocumentIdentifier.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/OptionalVersionedTextDocumentIdentifier.cs @@ -6,22 +6,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Globalization; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json; + using System.Text.Json.Serialization; /// /// Class which represents a text document, but optionally has a version identifier. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class OptionalVersionedTextDocumentIdentifier : TextDocumentIdentifier, IEquatable { /// /// Gets or sets the version of the document. /// - [DataMember(Name = "version")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("version")] public int? Version { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ParameterInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/ParameterInformation.cs index 38327189dcf73..e92aeb737af31 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ParameterInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ParameterInformation.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a parameter of a callable signature. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(ParameterInformationConverter))] internal class ParameterInformation { /// /// Gets or sets the label of the parameter. /// - [DataMember(Name = "label")] + [JsonPropertyName("label")] public SumType> Label { get; @@ -30,8 +28,8 @@ public SumType> Label /// /// Gets or sets the human-readable documentation of the parameter. /// - [DataMember(Name = "documentation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Documentation { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs index debdaa4cdcbd0..a392f4102186d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameter information initialization setting. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ParameterInformationSetting { /// /// Gets or sets a value indicating whether the client supports label offset. /// - [DataMember(Name = "labelOffsetSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("labelOffsetSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LabelOffsetSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Position.cs b/src/Features/LanguageServer/Protocol/Protocol/Position.cs index ec4a102e561be..a4a770efad361 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Position.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Position.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents a position on a text document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Position : IEquatable { /// @@ -37,7 +35,7 @@ public Position(int line, int character) /// /// Gets or sets the line number. /// - [DataMember(Name = "line")] + [JsonPropertyName("line")] public int Line { get; @@ -47,7 +45,7 @@ public int Line /// /// Gets or sets the character number. /// - [DataMember(Name = "character")] + [JsonPropertyName("character")] public int Character { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs b/src/Features/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs index 73184699a73db..2ef5c34b6eb05 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters for the 'textDocument/prepare' request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class PrepareRenameParams : ITextDocumentPositionParams { /// /// Gets or sets the value which identifies the document. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the position in which the rename is requested. /// - [DataMember(Name = "position")] + [JsonPropertyName("position")] public Position Position { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs b/src/Features/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs index 90dfe145b7c39..fb4a1319a87e1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum representing the default behavior used by the client for computing a rename range. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum PrepareSupportDefaultBehavior { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/PreviousResultId.cs b/src/Features/LanguageServer/Protocol/Protocol/PreviousResultId.cs index 59026f13ff01c..e8ae0c7e4e6bc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/PreviousResultId.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/PreviousResultId.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol; using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a previous result id in a workspace pull request. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class PreviousResultId { /// /// Gets or sets the URI for which the client knows a result id. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -30,7 +28,7 @@ public Uri Uri /// /// Gets or sets the value of the previous result id. /// - [DataMember(Name = "value")] + [JsonPropertyName("value")] public string Value { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs b/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs index c8cdae892ad2e..5b759a01c9aa3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that's sent with 'textDocument/publishDiagnostics' messages. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class PublishDiagnosticParams { /// /// Gets or sets the URI of the text document. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -30,7 +28,7 @@ public Uri Uri /// /// Gets or sets the collection of diagnostics. /// - [DataMember(Name = "diagnostics")] + [JsonPropertyName("diagnostics")] public Diagnostic[] Diagnostics { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs index 044cc92b08910..63f44c94aabbf 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the initialization setting for publish diagnostics. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class PublishDiagnosticsSetting { /// /// Gets or sets a value indicating whether gets or sets the capabilities. /// - [DataMember(Name = "tagSupport")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("tagSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TagSupport? TagSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Range.cs b/src/Features/LanguageServer/Protocol/Protocol/Range.cs index 47284808a2d33..a1e423608df98 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Range.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Range.cs @@ -6,22 +6,20 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Collections.Generic; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a text document text range. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Range : IEquatable { /// /// Gets or sets the text start position. /// - [DataMember(Name = "start")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("start")] + [JsonRequired] public Position Start { get; @@ -31,8 +29,8 @@ public Position Start /// /// Gets or sets the text end position. /// - [DataMember(Name = "end")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("end")] + [JsonRequired] public Position End { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ReferenceContext.cs b/src/Features/LanguageServer/Protocol/Protocol/ReferenceContext.cs index 36703524d53bd..2e7411b4411a0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ReferenceContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ReferenceContext.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing reference context information for find reference request parameter. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ReferenceContext { /// /// Gets or sets a value indicating whether declaration should be included. /// - [DataMember(Name = "includeDeclaration")] + [JsonPropertyName("includeDeclaration")] public bool IncludeDeclaration { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ReferenceOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/ReferenceOptions.cs index a65a49c2b9046..2282473292523 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ReferenceOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ReferenceOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ReferenceOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/ReferenceParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ReferenceParams.cs index 0809067d7a9ef..00a2106a75ddc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ReferenceParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ReferenceParams.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing find reference parameter for find reference request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ReferenceParams : TextDocumentPositionParams, IPartialResultParams { // Using IPartialResultParams instead of IPartialResultParams to @@ -22,7 +20,7 @@ internal class ReferenceParams : TextDocumentPositionParams, IPartialResultParam /// /// Gets or sets the reference context. /// - [DataMember(Name = "context")] + [JsonPropertyName("context")] public ReferenceContext Context { get; @@ -32,8 +30,8 @@ public ReferenceContext Context /// /// Gets or sets the value of the PartialResultToken instance. /// - [DataMember(Name = Methods.PartialResultTokenName, IsRequired = false)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Registration.cs b/src/Features/LanguageServer/Protocol/Protocol/Registration.cs index fcf186fb298ff..906b4f4277d8e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Registration.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Registration.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the general registration information for registering for a capability. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Registration { /// /// Gets or sets the id used to register the request. This can be used to deregister later. /// - [DataMember(Name = "id")] + [JsonPropertyName("id")] public string Id { get; @@ -28,7 +26,7 @@ public string Id /// /// Gets or sets the method / capability to register for. /// - [DataMember(Name = "method")] + [JsonPropertyName("method")] public string Method { get; @@ -38,8 +36,8 @@ public string Method /// /// Gets or sets the options necessary for registration. /// - [DataMember(Name = "registerOptions")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("registerOptions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? RegisterOptions { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RegistrationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/RegistrationParams.cs index 0a212c4740440..4125036ab0e1f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RegistrationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RegistrationParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for the client/registerCapability request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RegistrationParams { /// /// Gets or sets the set of capabilities that are being registered. /// - [DataMember(Name = "registrations")] + [JsonPropertyName("registrations")] public Registration[] Registrations { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs index 6c672b19efdaf..7b6fbc77a4210 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs @@ -6,23 +6,21 @@ namespace Roslyn.LanguageServer.Protocol; using System; using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a full diagnostic report with a set of related documents. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Full)] internal class RelatedFullDocumentDiagnosticReport : FullDocumentDiagnosticReport { /// /// Gets or sets the map of related document diagnostic reports. /// - [DataMember(Name = "relatedDocuments")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("relatedDocuments")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Dictionary>? RelatedDocuments { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RelatedUnchangedDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/RelatedUnchangedDocumentDiagnosticReport.cs index b4f1c2949d759..b9e968a0f9eda 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RelatedUnchangedDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RelatedUnchangedDocumentDiagnosticReport.cs @@ -6,23 +6,21 @@ namespace Roslyn.LanguageServer.Protocol; using System; using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing an unchanged diagnostic report with a set of related documents. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class RelatedUnchangedDocumentDiagnosticReport : UnchangedDocumentDiagnosticReport { /// /// Gets or sets the map of related document diagnostic reports. /// - [DataMember(Name = "relatedDocuments")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("relatedDocuments")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Dictionary>? RelatedDocuments { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs index df1fc09d55b7f..bea10606988cb 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs @@ -4,25 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using System.Xml.Linq; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using static System.Net.Mime.MediaTypeNames; + using System.Text.Json.Serialization; /// /// Class which represents renaming client capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RenameClientCapabilities : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether the client supports testing for validity of rename operations before execution. /// - [DataMember(Name = "prepareSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("prepareSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PrepareSupport { get; @@ -33,8 +28,8 @@ public bool PrepareSupport /// Gets or sets the value indicating the default behavior used by the client when the (`{ defaultBehavior: boolean }`) /// result is used in the 'textDocument/prepareRename' request. /// - [DataMember(Name = "prepareSupportDefaultBehavior")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("prepareSupportDefaultBehavior")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public PrepareSupportDefaultBehavior? PrepareSupportDefaultBehavior { get; @@ -46,8 +41,8 @@ public PrepareSupportDefaultBehavior? PrepareSupportDefaultBehavior /// operations returned via the rename request's workspace edit, by for example presenting the workspace edit in /// the user interface and asking for confirmation. /// - [DataMember(Name = "honorsChangeAnnotations")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("honorsChangeAnnotations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool HonorsChangeAnnotations { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameFile.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameFile.cs index 9e7a366ef345a..969e8a039d867 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameFile.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameFile.cs @@ -5,29 +5,28 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a rename file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [Kind("rename")] internal class RenameFile { /// /// Gets the kind value. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Member can't be static since it's part of the protocol")] public string Kind => "rename"; /// /// Gets or sets the old (existing) location. /// - [DataMember(Name = "oldUri", IsRequired = true)] + [JsonPropertyName("oldUri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri OldUri { @@ -38,7 +37,8 @@ public Uri OldUri /// /// Gets or sets the new location. /// - [DataMember(Name = "newUri", IsRequired = true)] + [JsonPropertyName("newUri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri NewUri { @@ -49,8 +49,8 @@ public Uri NewUri /// /// Gets or sets the rename options. /// - [DataMember(Name = "options")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("options")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public RenameFileOptions? Options { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameFileOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameFileOptions.cs index 64af96d73853a..59d45c42a225b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameFileOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameFileOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for a create file operation. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RenameFileOptions { /// /// Gets or sets a value indicating whether the rename should overwrite the target if it already exists. (Overwrite wins over ignoreIfExists). /// - [DataMember(Name = "overwrite")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("overwrite")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Overwrite { get; @@ -29,8 +27,8 @@ public bool Overwrite /// /// Gets or sets a value indicating whether the action should be ignored if the file already exists. /// - [DataMember(Name = "ignoreIfExists")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("ignoreIfExists")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IgnoreIfExists { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameOptions.cs index f869eea186238..841b679e2e005 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the rename options for server capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RenameOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether renames should be checked and tested before being executed. /// - [DataMember(Name = "prepareProvider")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("prepareProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PrepareProvider { get; @@ -29,8 +27,8 @@ public bool PrepareProvider /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameParams.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameParams.cs index 29b85b249c9a3..3c95b96d9393e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the rename parameters for the textDocument/rename request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RenameParams : TextDocumentPositionParams { /// /// Gets or sets the new name of the renamed symbol. /// - [DataMember(Name = "newName")] + [JsonPropertyName("newName")] public string NewName { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/RenameRange.cs b/src/Features/LanguageServer/Protocol/Protocol/RenameRange.cs index f424a260e236c..984b50dc823a0 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/RenameRange.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/RenameRange.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a possible result value of the 'textDocument/prepareRename' request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class RenameRange { /// /// Gets or sets the range of the string to rename. /// - [DataMember(Name = "range")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; @@ -29,8 +27,8 @@ public Range Range /// /// Gets or sets the placeholder text of the string content to be renamed. /// - [DataMember(Name = "placeholder")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("placeholder")] + [JsonRequired] public string Placeholder { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs index aa05c8d8e28ed..6ff560bb95808 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents initialization setting for properties a client can resolve lazily on a completion item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ResolveSupportSetting { /// /// Gets or sets a value indicating the properties that a client can resolve lazily. /// - [DataMember(Name = "properties", IsRequired = true)] + [JsonPropertyName("properties")] + [JsonRequired] public string[] Properties { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs b/src/Features/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs index 1b56ff4510eaf..228b44234bf60 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the kind of resource operations supported by the client. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct ResourceOperationKind(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/SaveOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/SaveOptions.cs index e14887dc310ef..9d04b661df742 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SaveOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SaveOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents save option configurations. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SaveOptions { /// /// Gets or sets a value indicating whether clients include text content on save. /// - [DataMember(Name = "includeText")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("includeText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IncludeText { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs index 3b46370ef84c7..5a75e425e946b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs @@ -5,15 +5,13 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the format used to describe semantic tokens. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct SemanticTokenFormat(string Value) : IStringEnum diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs index 5b1c243765f2a..bd467fbf475d6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs @@ -4,28 +4,27 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing response to semantic tokens messages. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokens { /// /// Gets or sets a property that identifies this version of the document's semantic tokens. /// - [DataMember(Name = "resultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ResultId { get; set; } /// /// Gets or sets and array containing encoded semantic tokens data. /// - [DataMember(Name = "data", IsRequired = true)] + [JsonPropertyName("data")] + [JsonRequired] public int[] Data { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs index c67e0d1e61523..f1697e0ac4939 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs @@ -4,31 +4,29 @@ namespace Roslyn.LanguageServer.Protocol { - using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Represents a response from a semantic tokens Document provider Edits request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensDelta { /// /// Gets or sets the Id for the client's new version after applying all /// edits to their current semantic tokens data. /// - [DataMember(Name = "resultId")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resultId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ResultId { get; set; } /// /// Gets or sets an array of edits to apply to a previous response from a /// semantic tokens Document provider. /// - [DataMember(Name = "edits", IsRequired = true)] + [JsonPropertyName("edits")] + [JsonRequired] public SemanticTokensEdit[] Edits { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs index eee3588bb8a02..aded0c9dd957b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs @@ -5,8 +5,7 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Parameters for a request for Edits that can be applied to a previous response @@ -14,27 +13,26 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensDeltaParams : ITextDocumentParams, IPartialResultParams { /// /// Gets or sets an identifier for the document to fetch semantic tokens from. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; set; } /// /// Gets or sets a property indicating the version of the semantic /// tokens Document provider response that the edits will be applied to. /// - [DataMember(Name = "previousResultId")] + [JsonPropertyName("previousResultId")] public string PreviousResultId { get; set; } /// /// Gets or sets the value of the Progress instance. /// - [DataMember(Name = Methods.PartialResultTokenName, IsRequired = false)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs index 5905b06a385ab..dadc783ce447f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs @@ -4,23 +4,21 @@ namespace Roslyn.LanguageServer.Protocol { - using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Represents a response from a semantic tokens Document provider Edits request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensDeltaPartialResult { /// /// Gets or sets an array of edits to apply to a previous response from a /// semantic tokens Document provider. /// - [DataMember(Name = "edits", IsRequired = true)] + [JsonPropertyName("edits")] + [JsonRequired] public SemanticTokensEdit[] Edits { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs index 9958a6d858b5c..c06932c59a9f7 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs @@ -5,8 +5,7 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing an individual edit incrementally applied to a previous @@ -14,7 +13,6 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1036:Override methods on comparable types", Justification = "Pending implementation of IComparable")] internal class SemanticTokensEdit : IComparable { @@ -22,22 +20,22 @@ internal class SemanticTokensEdit : IComparable /// Gets or sets the position in the previous response's /// to begin the edit. /// - [DataMember(Name = "start")] + [JsonPropertyName("start")] public int Start { get; set; } /// /// Gets or sets the number of numbers to delete in the /// from the previous response. /// - [DataMember(Name = "deleteCount")] + [JsonPropertyName("deleteCount")] public int DeleteCount { get; set; } /// /// Gets or sets an array containing the encoded semantic tokens information to insert /// into a previous response. /// - [DataMember(Name = "data")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int[]? Data { get; set; } /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs index ac04122c1dd4e..ff7dcdf3e4970 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Options for the full document semantic tokens classification provider. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensFullOptions { /// /// Gets or sets a value indicating whether the server supports deltas for full documents. /// - [DataMember(Name = "delta")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("delta")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Delta { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs index 1e2deb490d8b4..394c0d45c8f68 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Legend used to encode semantic token types in . /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensLegend { /// /// Gets or sets an array of token types that can be encoded in semantic tokens responses. /// - [DataMember(Name = "tokenTypes")] + [JsonPropertyName("tokenTypes")] public string[] TokenTypes { get; @@ -27,7 +26,7 @@ public string[] TokenTypes /// /// Gets or sets an array of token modfiers that can be encoded in semantic tokens responses. /// - [DataMember(Name = "tokenModifiers")] + [JsonPropertyName("tokenModifiers")] public string[] TokenModifiers { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs index 99e483f5ecb47..30fce0f5efaa6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs @@ -4,42 +4,40 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Initialization options for semantic tokens support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensOptions : IWorkDoneProgressOptions { /// /// Gets or sets a legend describing how semantic token types and modifiers are encoded in responses. /// - [DataMember(Name = "legend")] + [JsonPropertyName("legend")] public SemanticTokensLegend Legend { get; set; } /// /// Gets or sets a value indicating whether semantic tokens Range provider requests are supported. /// - [DataMember(Name = "range")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Range { get; set; } /// /// Gets or sets whether or not the server supports providing semantic tokens for a full document. /// - [DataMember(Name = "full")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("full")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Full { get; set; } /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs index f388365622b58..5cf3738c12b6b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs @@ -5,28 +5,26 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Parameters for semantic tokens full Document request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensParams : ITextDocumentParams, IPartialResultParams { /// /// Gets or sets an identifier for the document to fetch semantic tokens from. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; set; } /// /// Gets or sets the value of the Progress instance. /// - [DataMember(Name = Methods.PartialResultTokenName, IsRequired = false)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs index fef2fa0b35b48..3307b392e936a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing response to semantic tokens messages. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensPartialResult { /// /// Gets or sets and array containing encoded semantic tokens data. /// - [DataMember(Name = "data", IsRequired = true)] + [JsonPropertyName("data")] + [JsonRequired] public int[] Data { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs index b99746321df5b..0523c2e25293f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Parameters for the semantic tokens Range request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensRangeParams : SemanticTokensParams { /// /// Gets or sets the range within the document to fetch semantic tokens for. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs index 60311963550f3..ce6ad7de1e5d6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs @@ -4,8 +4,7 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Client settings for semantic tokens related to the @@ -13,7 +12,6 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensRequestsFullSetting { /// @@ -21,8 +19,8 @@ internal class SemanticTokensRequestsFullSetting /// textDocument/semanticTokens/full/delta request if the server /// provides a corresponding handler. /// - [DataMember(Name = "range")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Delta { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs index 26884ccc267b2..7c9dbd73769b9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs @@ -4,15 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Requests client settings for semantic tokens. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensRequestsSetting { /// @@ -20,8 +18,8 @@ internal class SemanticTokensRequestsSetting /// `textDocument/semanticTokens/range` request if the server provides a /// corresponding handler. /// - [DataMember(Name = "range")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("range")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Range { get; set; } /// @@ -29,8 +27,8 @@ internal class SemanticTokensRequestsSetting /// `textDocument/semanticTokens/full` request if the server provides a /// corresponding handler. /// - [DataMember(Name = "full")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("full")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Full { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs index ddef8c880b076..85e34d5680f9f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs @@ -4,56 +4,54 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Client settings for semantic tokens. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensSetting : DynamicRegistrationSetting { /// /// Gets or sets a value indicating which requests the client supports and might send to the server /// depending on the server's capability. /// - [DataMember(Name = "requests")] + [JsonPropertyName("requests")] public SemanticTokensRequestsSetting Requests { get; set; } /// /// Gets or sets an array of token types supported by the client for encoding /// semantic tokens. /// - [DataMember(Name = "tokenTypes")] + [JsonPropertyName("tokenTypes")] public string[] TokenTypes { get; set; } /// /// Gets or sets an array of token modifiers supported by the client for encoding /// semantic tokens. /// - [DataMember(Name = "tokenModifiers")] + [JsonPropertyName("tokenModifiers")] public string[] TokenModifiers { get; set; } /// /// Gets or sets an array of formats the clients supports. /// - [DataMember(Name = "formats")] + [JsonPropertyName("formats")] public SemanticTokenFormat[] Formats { get; set; } /// /// Gets or sets a value indicating whether the client supports tokens that can overlap each other. /// - [DataMember(Name = "overlappingTokenSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("overlappingTokenSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool OverlappingTokenSupport { get; set; } /// /// Gets or sets a value indicating whether the client supports tokens that can span multiple lines. /// - [DataMember(Name = "multilineTokenSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("multilineTokenSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool MultilineTokenSupport { get; set; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs index dd101255ae22e..d560f44d6c5c2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs @@ -4,15 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Capabilities specific to the semantic token requests scoped to the workspace. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SemanticTokensWorkspaceSetting { /// @@ -25,8 +23,8 @@ internal class SemanticTokensWorkspaceSetting /// and is useful for situation where a server for example detect a project /// wide change that requires such a calculation. /// - [DataMember(Name = "refreshSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } } } \ No newline at end of file diff --git a/src/Features/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 8e7416165f35f..840da00bb13b1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System.Diagnostics.CodeAnalysis; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents server capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ServerCapabilities { /// /// Gets or sets the value which indicates how text document are synced. /// - [DataMember(Name = "textDocumentSync")] + [JsonPropertyName("textDocumentSync")] [JsonConverter(typeof(TextDocumentSyncConverter))] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsShouldNotShareLine", Justification = "There are no issues with this code")] @@ -40,8 +38,8 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets the value which indicates if completions are supported. /// - [DataMember(Name = "completionProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completionProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionOptions? CompletionProvider { get; @@ -51,8 +49,8 @@ public CompletionOptions? CompletionProvider /// /// Gets or sets a value indicating whether the server provides hover support. /// - [DataMember(Name = "hoverProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("hoverProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? HoverProvider { get; @@ -62,8 +60,8 @@ public SumType? HoverProvider /// /// Gets or sets the value which indicates if signature help is supported. /// - [DataMember(Name = "signatureHelpProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("signatureHelpProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SignatureHelpOptions? SignatureHelpProvider { get; @@ -73,8 +71,8 @@ public SignatureHelpOptions? SignatureHelpProvider /// /// Gets or sets a value indicating whether go to definition is supported. /// - [DataMember(Name = "definitionProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("definitionProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DefinitionProvider { get; @@ -84,8 +82,8 @@ public SumType? DefinitionProvider /// /// Gets or sets a value indicating whether go to type definition is supported. /// - [DataMember(Name = "typeDefinitionProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("typeDefinitionProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? TypeDefinitionProvider { get; @@ -95,8 +93,8 @@ public SumType? TypeDefinitionProvider /// /// Gets or sets a value indicating whether go to implementation is supported. /// - [DataMember(Name = "implementationProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("implementationProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? ImplementationProvider { get; @@ -106,8 +104,8 @@ public SumType? ImplementationProvider /// /// Gets or sets a value indicating whether find all references is supported. /// - [DataMember(Name = "referencesProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("referencesProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? ReferencesProvider { get; @@ -117,8 +115,8 @@ public SumType? ReferencesProvider /// /// Gets or sets a value indicating whether the server supports document highlight. /// - [DataMember(Name = "documentHighlightProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentHighlightProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DocumentHighlightProvider { get; @@ -128,8 +126,8 @@ public SumType? DocumentHighlightProvider /// /// Gets or sets a value indicating whether document symbols are supported. /// - [DataMember(Name = "documentSymbolProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentSymbolProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DocumentSymbolProvider { get; @@ -139,8 +137,8 @@ public SumType? DocumentSymbolProvider /// /// Gets or sets a value indicating whether code actions are supported. /// - [DataMember(Name = "codeActionProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeActionProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? CodeActionProvider { get; @@ -150,8 +148,8 @@ public SumType? CodeActionProvider /// /// Gets or sets the value which indicates if code lens is supported. /// - [DataMember(Name = "codeLensProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeLensProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeLensOptions? CodeLensProvider { get; @@ -161,8 +159,8 @@ public CodeLensOptions? CodeLensProvider /// /// Gets or sets the value which indicates if document link is supported. /// - [DataMember(Name = "documentLinkProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentLinkProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentLinkOptions? DocumentLinkProvider { get; @@ -172,8 +170,8 @@ public DocumentLinkOptions? DocumentLinkProvider /// /// Gets or sets the value which indicates if document color is supported. /// - [DataMember(Name = "colorProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("colorProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DocumentColorProvider { get; @@ -183,8 +181,8 @@ public SumType? DocumentColorProvider /// /// Gets or sets a value indicating whether document formatting is supported. /// - [DataMember(Name = "documentFormattingProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentFormattingProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DocumentFormattingProvider { get; @@ -194,8 +192,8 @@ public SumType? DocumentFormattingProvider /// /// Gets or sets a value indicating whether document range formatting is supported. /// - [DataMember(Name = "documentRangeFormattingProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentRangeFormattingProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DocumentRangeFormattingProvider { get; @@ -205,8 +203,8 @@ public SumType? DocumentRangeFormattingPro /// /// Gets or sets the value which indicates if document on type formatting is supported. /// - [DataMember(Name = "documentOnTypeFormattingProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentOnTypeFormattingProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentOnTypeFormattingOptions? DocumentOnTypeFormattingProvider { get; @@ -216,8 +214,8 @@ public DocumentOnTypeFormattingOptions? DocumentOnTypeFormattingProvider /// /// Gets or sets a value indicating whether rename is supported. /// - [DataMember(Name = "renameProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("renameProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? RenameProvider { get; @@ -227,8 +225,8 @@ public SumType? RenameProvider /// /// Gets or sets the value which indicates if folding range is supported. /// - [DataMember(Name = "foldingRangeProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("foldingRangeProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? FoldingRangeProvider { get; @@ -238,8 +236,8 @@ public SumType? FoldingRangeProvider /// /// Gets or sets the value which indicates if execute command is supported. /// - [DataMember(Name = "executeCommandProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("executeCommandProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ExecuteCommandOptions? ExecuteCommandProvider { get; @@ -249,8 +247,8 @@ public ExecuteCommandOptions? ExecuteCommandProvider /// /// Gets or sets a value indicating whether workspace symbols are supported. /// - [DataMember(Name = "workspaceSymbolProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("workspaceSymbolProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? WorkspaceSymbolProvider { get; @@ -260,8 +258,8 @@ public SumType? WorkspaceSymbolProvider /// /// Gets or sets experimental server capabilities. /// - [DataMember(Name = "experimental")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("experimental")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Experimental { get; @@ -271,8 +269,8 @@ public object? Experimental /// /// Gets or sets a value indicating whether the server supports linked editing range. /// - [DataMember(Name = "linkedEditingRangeProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("linkedEditingRangeProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? LinkedEditingRangeProvider { get; @@ -282,8 +280,8 @@ public SumType? LinkedEditingRangeProvider /// /// Gets or sets the value which indicates if semantic tokens is supported. /// - [DataMember(Name = "semanticTokensProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("semanticTokensProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensOptions? SemanticTokensOptions { get; @@ -293,8 +291,8 @@ public SemanticTokensOptions? SemanticTokensOptions /// /// Gets or sets the value which indicates what support the server has for pull diagnostics. /// - [DataMember(Name = "diagnosticProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("diagnosticProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticOptions? DiagnosticOptions { get; @@ -304,8 +302,8 @@ public DiagnosticOptions? DiagnosticOptions /// /// Gets or sets the value which indicates what support the server has for inlay hints. /// - [DataMember(Name = "inlayHintProvider")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("inlayHintProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? InlayHintOptions { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ShowMessageParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ShowMessageParams.cs index d86b0e3ec53e7..b7da5703aedba 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ShowMessageParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ShowMessageParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents parameter sent with window/showMessage requests. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ShowMessageParams { /// /// Gets or sets the type of message. /// - [DataMember(Name = "type")] + [JsonPropertyName("type")] public MessageType MessageType { get; @@ -27,7 +26,7 @@ public MessageType MessageType /// /// Gets or sets the message. /// - [DataMember(Name = "message")] + [JsonPropertyName("message")] public string Message { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs b/src/Features/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs index 803ee910b8fa3..b8df89cb3f998 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents parameter sent with window/showMessageRequest requests. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class ShowMessageRequestParams : ShowMessageParams { /// /// Gets or sets an array of s to present. /// - [DataMember(Name = "actions")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("actions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public MessageActionItem[]? Actions { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelp.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelp.cs index ff7baa6c8c6c2..fbc02b0b71901 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelp.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelp.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the signature of something callable. This class is returned from the textDocument/signatureHelp request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureHelp { /// /// Gets or sets an array of signatures associated with the callable item. /// - [DataMember(Name = "signatures")] - [JsonProperty(Required = Required.Always)] + [JsonPropertyName("signatures")] + [JsonRequired] public SignatureInformation[] Signatures { get; @@ -29,8 +27,8 @@ public SignatureInformation[] Signatures /// /// Gets or sets the active signature. If the value is omitted or falls outside the range of Signatures it defaults to zero. /// - [DataMember(Name = "activeSignature")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("activeSignature")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? ActiveSignature { get; @@ -40,8 +38,8 @@ public int? ActiveSignature /// /// Gets or sets the active parameter. If the value is omitted or falls outside the range of Signatures[ActiveSignature].Parameters it defaults to zero. /// - [DataMember(Name = "activeParameter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("activeParameter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? ActiveParameter { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs index 4bc39650fc574..7d3a42675c951 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing additional information about the context in which a signature help request is triggered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureHelpContext { /// /// Gets or sets the indicating how the signature help was triggered. /// - [DataMember(Name = "triggerKind")] + [JsonPropertyName("triggerKind")] public SignatureHelpTriggerKind TriggerKind { get; @@ -29,8 +27,8 @@ public SignatureHelpTriggerKind TriggerKind /// Gets or sets the character that caused signature help to be triggered. /// This value is null when triggerKind is not TriggerCharacter. /// - [DataMember(Name = "triggerCharacter")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("triggerCharacter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? TriggerCharacter { get; @@ -40,7 +38,7 @@ public string? TriggerCharacter /// /// Gets or sets a value indicating whether signature help was already showing when it was triggered. /// - [DataMember(Name = "isRetrigger")] + [JsonPropertyName("isRetrigger")] public bool IsRetrigger { get; @@ -50,8 +48,8 @@ public bool IsRetrigger /// /// Gets or sets the currently active . /// - [DataMember(Name = "activeSignatureHelp")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("activeSignatureHelp")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SignatureHelp? ActiveSignatureHelp { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs index 9578bb1585af1..102ef229035f9 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the options for signature help support. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureHelpOptions : IWorkDoneProgressOptions { /// /// Gets or sets the characters that trigger signature help automatically. /// - [DataMember(Name = "triggerCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("triggerCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? TriggerCharacters { get; @@ -30,8 +28,8 @@ public string[]? TriggerCharacters /// Gets or sets the characters that re-trigger signature help /// when signature help is already showing. /// - [DataMember(Name = "retriggerCharacters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("retriggerCharacters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? RetriggerCharacters { get; @@ -41,8 +39,8 @@ public string[]? RetriggerCharacters /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs index 765bf13dbb073..52fbd2f43e10a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the parameters for the textDocument/signatureHelp request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureHelpParams : TextDocumentPositionParams { /// /// Gets or sets the signature help context. /// - [DataMember(Name = "context")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("context")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SignatureHelpContext? Context { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs index 7d12130ab2a96..447b91419344d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the signature help initialization setting. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureHelpSetting : DynamicRegistrationSetting { /// /// Gets or sets the information. /// - [DataMember(Name = "signatureInformation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("signatureInformation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SignatureInformationSetting? SignatureInformation { get; @@ -30,8 +28,8 @@ public SignatureInformationSetting? SignatureInformation /// Gets or sets a value indicating whether additional context information /// is supported for the `textDocument/signatureHelp` request. /// - [DataMember(Name = "contextSupport")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("contextSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ContextSupport { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs index 2ffba29c58692..00ba1f6410d50 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum which represents the various ways in which completion can be triggered. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum SignatureHelpTriggerKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureInformation.cs index 6e68c4d386a97..462bd9c6e2b4a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureInformation.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a single signature of a callable item. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureInformation { /// /// Gets or sets the label of this signature. /// - [DataMember(Name = "label")] + [JsonPropertyName("label")] public string Label { get; @@ -28,8 +26,8 @@ public string Label /// /// Gets or sets the human-readable documentation of this signature. /// - [DataMember(Name = "documentation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Documentation { get; @@ -39,8 +37,8 @@ public SumType? Documentation /// /// Gets or sets the parameters of this signature. /// - [DataMember(Name = "parameters")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("parameters")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ParameterInformation[]? Parameters { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs index 083fa7dfc90a9..efb21c658a425 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the signature information initialization setting. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SignatureInformationSetting { /// /// Gets or sets the set of documentation formats the client supports. /// - [DataMember(Name = "documentationFormat")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentationFormat")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public MarkupKind[]? DocumentationFormat { get; @@ -29,8 +27,8 @@ public MarkupKind[]? DocumentationFormat /// /// Gets or sets the parameter information the client supports. /// - [DataMember(Name = "parameterInformation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("parameterInformation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ParameterInformationSetting? ParameterInformation { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SumType.cs b/src/Features/LanguageServer/Protocol/Protocol/SumType.cs index 3c50c415f59a8..6d656e070a348 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SumType.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SumType.cs @@ -7,9 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - using System.Runtime.CompilerServices; - using Microsoft.CommonLanguageServerProtocol.Framework; + using System.Text.Json.Serialization; using Microsoft.CodeAnalysis.LanguageServer; /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/SymbolInformation.cs b/src/Features/LanguageServer/Protocol/Protocol/SymbolInformation.cs index dc3b38d0cdacb..c35871bdaef2b 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SymbolInformation.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SymbolInformation.cs @@ -6,21 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Collections.Generic; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing information about programming constructs like variables, classes, interfaces, etc. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SymbolInformation : IEquatable { /// /// Gets or sets the name of this symbol. /// - [DataMember(Name = "name")] + [JsonPropertyName("name")] public string Name { get; @@ -30,7 +28,7 @@ public string Name /// /// Gets or sets the of this symbol. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] public SymbolKind Kind { get; @@ -40,7 +38,7 @@ public SymbolKind Kind /// /// Gets or sets the of this symbol. /// - [DataMember(Name = "location")] + [JsonPropertyName("location")] public Location Location { get; @@ -50,8 +48,8 @@ public Location Location /// /// Gets or sets the name of the symbol containing this symbol. /// - [DataMember(Name = "containerName")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("containerName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ContainerName { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SymbolKind.cs b/src/Features/LanguageServer/Protocol/Protocol/SymbolKind.cs index e2d98be0daac4..77c9d57b8b8a3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SymbolKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SymbolKind.cs @@ -4,15 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; - /// /// Enum which represents the various kinds of symbols. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1720:Identifier contains type name", Justification = "Names are defined by the LSP")] internal enum SymbolKind { diff --git a/src/Features/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs index ce32110d895d1..3b9f98a15aad2 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the symbol kind setting in initialization. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SymbolKindSetting { /// /// Gets or sets the types of symbol kind the client supports. /// - [DataMember(Name = "valueSet")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("valueSet")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SymbolKind[]? ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SymbolSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SymbolSetting.cs index a1b609d5a041e..bad49978458a1 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SymbolSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SymbolSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the symbol setting for initialization. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SymbolSetting : DynamicRegistrationSetting { /// /// Gets or sets the information. /// - [DataMember(Name = "symbolKind")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("symbolKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SymbolKindSetting? SymbolKind { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs index 87da1fdc6ac1e..82e339cb5ea56 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents synchronization initialization setting. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class SynchronizationSetting : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether WillSave event is supported. /// - [DataMember(Name = "willSave")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("willSave")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WillSave { get; @@ -29,8 +27,8 @@ public bool WillSave /// /// Gets or sets a value indicating whether WillSaveWaitUntil event is supported. /// - [DataMember(Name = "willSaveWaitUntil")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("willSaveWaitUntil")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WillSaveWaitUntil { get; @@ -40,8 +38,8 @@ public bool WillSaveWaitUntil /// /// Gets or sets a value indicating whether DidSave event is supported. /// - [DataMember(Name = "didSave")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("didSave")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DidSave { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TagSupport.cs b/src/Features/LanguageServer/Protocol/Protocol/TagSupport.cs index e5dfaffa0e439..2f27a28e442e8 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TagSupport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TagSupport.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TagSupport { /// /// Gets or sets a value indicating the tags supported by the client. /// - [DataMember(Name = "valueSet")] + [JsonPropertyName("valueSet")] public DiagnosticTag[] ValueSet { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 5ea26816eaf94..ee1b4051ae3ea 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents text document capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentClientCapabilities { /// /// Gets or sets the synchronization setting. /// - [DataMember(Name = "synchronization")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("synchronization")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SynchronizationSetting? Synchronization { get; @@ -29,8 +27,8 @@ public SynchronizationSetting? Synchronization /// /// Gets or sets the completion setting. /// - [DataMember(Name = "completion")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("completion")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionSetting? Completion { get; @@ -40,8 +38,8 @@ public CompletionSetting? Completion /// /// Gets or sets the setting which determines if hover can be dynamically registered. /// - [DataMember(Name = "hover")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("hover")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public HoverSetting? Hover { get; @@ -51,8 +49,8 @@ public HoverSetting? Hover /// /// Gets or sets the setting which determines if signature help can be dynamically registered. /// - [DataMember(Name = "signatureHelp")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("signatureHelp")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SignatureHelpSetting? SignatureHelp { get; @@ -62,8 +60,8 @@ public SignatureHelpSetting? SignatureHelp /// /// Gets or sets the setting which determines if definition can be dynamically registered. /// - [DataMember(Name = "definition")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("definition")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? Definition { get; @@ -73,8 +71,8 @@ public DynamicRegistrationSetting? Definition /// /// Gets or sets the settings which determines if type definition can be dynamically registered. /// - [DataMember(Name = "typeDefinition")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("typeDefinition")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? TypeDefinition { get; @@ -84,8 +82,8 @@ public DynamicRegistrationSetting? TypeDefinition /// /// Gets or sets the settings which determines if implementation can be dynamically registered. /// - [DataMember(Name = "implementation")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("implementation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? Implementation { get; @@ -95,8 +93,8 @@ public DynamicRegistrationSetting? Implementation /// /// Gets or sets the setting which determines if references can be dynamically registered. /// - [DataMember(Name = "references")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("references")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? References { get; @@ -106,8 +104,8 @@ public DynamicRegistrationSetting? References /// /// Gets or sets the setting which determines if document highlight can be dynamically registered. /// - [DataMember(Name = "documentHighlight")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentHighlight")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? DocumentHighlight { get; @@ -117,8 +115,8 @@ public DynamicRegistrationSetting? DocumentHighlight /// /// Gets or sets the setting which determines if document symbol can be dynamically registered. /// - [DataMember(Name = "documentSymbol")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentSymbol")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentSymbolSetting? DocumentSymbol { get; @@ -128,8 +126,8 @@ public DocumentSymbolSetting? DocumentSymbol /// /// Gets or sets the setting which determines if code action can be dynamically registered. /// - [DataMember(Name = "codeAction")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeAction")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionSetting? CodeAction { get; @@ -139,8 +137,8 @@ public CodeActionSetting? CodeAction /// /// Gets or sets the setting which determines if code lens can be dynamically registered. /// - [DataMember(Name = "codeLens")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeLens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? CodeLens { get; @@ -150,8 +148,8 @@ public DynamicRegistrationSetting? CodeLens /// /// Gets or sets the setting which determines if document link can be dynamically registered. /// - [DataMember(Name = "documentLink")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentLink")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? DocumentLink { get; @@ -161,8 +159,8 @@ public DynamicRegistrationSetting? DocumentLink /// /// Gets or sets the setting which determines if formatting can be dynamically registered. /// - [DataMember(Name = "formatting")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("formatting")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? Formatting { get; @@ -172,8 +170,8 @@ public DynamicRegistrationSetting? Formatting /// /// Gets or sets the setting which determines if range formatting can be dynamically registered. /// - [DataMember(Name = "rangeFormatting")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("rangeFormatting")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? RangeFormatting { get; @@ -183,8 +181,8 @@ public DynamicRegistrationSetting? RangeFormatting /// /// Gets or sets the setting which determines if on type formatting can be dynamically registered. /// - [DataMember(Name = "onTypeFormatting")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("onTypeFormatting")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? OnTypeFormatting { get; @@ -194,8 +192,8 @@ public DynamicRegistrationSetting? OnTypeFormatting /// /// Gets or sets the setting which determines if rename can be dynamically registered. /// - [DataMember(Name = "rename")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("rename")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public RenameClientCapabilities? Rename { get; @@ -205,8 +203,8 @@ public RenameClientCapabilities? Rename /// /// Gets or sets the setting publish diagnostics setting. /// - [DataMember(Name = "publishDiagnostics")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("publishDiagnostics")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public PublishDiagnosticsSetting? PublishDiagnostics { get; @@ -216,7 +214,7 @@ public PublishDiagnosticsSetting? PublishDiagnostics /// /// Gets or sets the setting which determines how folding range is supported. /// - [DataMember(Name = "foldingRange")] + [JsonPropertyName("foldingRange")] public FoldingRangeSetting? FoldingRange { get; @@ -226,8 +224,8 @@ public FoldingRangeSetting? FoldingRange /// /// Gets or sets the setting which determines if linked editing range can be dynamically registered. /// - [DataMember(Name = "linkedEditingRange")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("linkedEditingRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting LinkedEditingRange { get; @@ -237,8 +235,8 @@ public DynamicRegistrationSetting LinkedEditingRange /// /// Gets or sets a setting indicating whether semantic tokens is supported. /// - [DataMember(Name = "semanticTokens")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("semanticTokens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensSetting? SemanticTokens { get; @@ -248,8 +246,8 @@ public SemanticTokensSetting? SemanticTokens /// /// Gets or sets the setting which determines what support the client has for pull diagnostics. /// - [DataMember(Name = "diagnostic")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("diagnostic")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticSetting? Diagnostic { get; @@ -259,8 +257,8 @@ public DiagnosticSetting? Diagnostic /// /// Gets or sets the setting which determines what support the client has for pull diagnostics. /// - [DataMember(Name = "inlayHint")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("inlayHint")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintSetting? InlayHint { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs index 8c2dd3dbb9566..64568623fe4dc 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs @@ -4,21 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which encapsulates a text document changed event. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentContentChangeEvent { /// /// Gets or sets the range of the text that was changed. /// - [DataMember(Name = "range")] + [JsonPropertyName("range")] public Range Range { get; @@ -28,8 +26,8 @@ public Range Range /// /// Gets or sets the length of the range that got replaced. /// - [DataMember(Name = "rangeLength")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("rangeLength")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? RangeLength { get; @@ -39,7 +37,7 @@ public int? RangeLength /// /// Gets or sets the new text of the range/document. /// - [DataMember(Name = "text")] + [JsonPropertyName("text")] public string Text { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs index bfe8999beff4c..26af2f8e87483 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing a set of changes to a single text document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentEdit { /// /// Gets or sets a document identifier indication which document to apply the edits to. /// - [DataMember(Name = "textDocument", IsRequired = true)] + [JsonPropertyName("textDocument")] + [JsonRequired] public OptionalVersionedTextDocumentIdentifier TextDocument { get; @@ -27,7 +27,8 @@ public OptionalVersionedTextDocumentIdentifier TextDocument /// /// Gets or sets the array of edits to be applied to the document. /// - [DataMember(Name = "edits", IsRequired = true)] + [JsonPropertyName("edits")] + [JsonRequired] public TextEdit[] Edits { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentIdentifier.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentIdentifier.cs index 78ffa87d73c42..9ec8f5a0c8804 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentIdentifier.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentIdentifier.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which identifies a text document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentIdentifier : IEquatable { /// /// Gets or sets the URI of the text document. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentItem.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentItem.cs index 4885efdb848b9..9a627e3ff7622 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentItem.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentItem.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a text document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentItem { /// /// Gets or sets the document URI. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -30,7 +28,7 @@ public Uri Uri /// /// Gets or sets the document language identifier. /// - [DataMember(Name = "languageId")] + [JsonPropertyName("languageId")] public string LanguageId { get; @@ -40,7 +38,7 @@ public string LanguageId /// /// Gets or sets the document version. /// - [DataMember(Name = "version")] + [JsonPropertyName("version")] public int Version { get; @@ -50,7 +48,7 @@ public int Version /// /// Gets or sets the content of the opened text document. /// - [DataMember(Name = "text")] + [JsonPropertyName("text")] public string Text { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentPositionParams.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentPositionParams.cs index 7886b68fb690a..ab430a5ed29c6 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentPositionParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentPositionParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents a position within a text document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentPositionParams : ITextDocumentPositionParams { /// /// Gets or sets the value which identifies the document. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the value which indicates the position within the document. /// - [DataMember(Name = "position")] + [JsonPropertyName("position")] public Position Position { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentRegistrationOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentRegistrationOptions.cs index 6fee4bee03e0f..94a0182345207 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentRegistrationOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentRegistrationOptions.cs @@ -4,22 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing the registration options for many different text document functions. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentRegistrationOptions : ITextDocumentRegistrationOptions { /// /// Gets or sets the document filters for this registration option. /// - [DataMember(Name = "documentSelector")] - [JsonProperty(NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("documentSelector")] public DocumentFilter[]? DocumentSelector { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSaveReason.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSaveReason.cs index c0ad11d2cf815..3fab506457c1f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSaveReason.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSaveReason.cs @@ -4,15 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; - /// /// Enum representing the reason a document was saved. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum TextDocumentSaveReason { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncKind.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncKind.cs index 105d0dbe2d5fe..5097bb3586c9c 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncKind.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncKind.cs @@ -4,14 +4,11 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - /// /// Enum which represents the various ways to sync text documents. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal enum TextDocumentSyncKind { /// diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncOptions.cs index 2c398b13b22e2..72f5e2a1c179e 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextDocumentSyncOptions.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents configuration values indicating how text documents should be synced. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextDocumentSyncOptions { /// /// Gets or sets a value indicating whether open and close notifications are sent to the server. /// - [DataMember(Name = "openClose")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("openClose")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool OpenClose { get; @@ -30,8 +28,8 @@ public bool OpenClose /// /// Gets or sets the value indicating how text documents are synced with the server. /// - [DataMember(Name = "change")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("change")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [DefaultValue(TextDocumentSyncKind.None)] public TextDocumentSyncKind? Change { @@ -42,8 +40,8 @@ public TextDocumentSyncKind? Change /// /// Gets or sets a value indicating whether 'will save' notifications are sent to the server. /// - [DataMember(Name = "willSave")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("willSave")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WillSave { get; @@ -53,8 +51,8 @@ public bool WillSave /// /// Gets or sets a value indicating whether 'will save until' notifications are sent to the server. /// - [DataMember(Name = "willSaveWaitUntil")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("willSaveWaitUntil")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WillSaveWaitUntil { get; @@ -64,8 +62,8 @@ public bool WillSaveWaitUntil /// /// Gets or sets a value indicating whether save notifications are sent to the server. /// - [DataMember(Name = "save")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("save")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Save { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TextEdit.cs b/src/Features/LanguageServer/Protocol/Protocol/TextEdit.cs index dccc1ce6887c5..c25885343f6c4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TextEdit.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TextEdit.cs @@ -4,20 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class which represents a text edit to a document. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TextEdit { /// /// Gets or sets the value which indicates the range of the text edit. /// - [DataMember(Name = "range", IsRequired = true)] + [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; @@ -27,7 +27,7 @@ public Range Range /// /// Gets or sets the value of the new text. /// - [DataMember(Name = "newText")] + [JsonPropertyName("newText")] public string NewText { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/TraceSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/TraceSetting.cs index 92261d6fc1790..cf1ec787ae2f4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TraceSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TraceSetting.cs @@ -5,7 +5,7 @@ namespace Roslyn.LanguageServer.Protocol { using System.ComponentModel; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Value representing the language server trace setting. diff --git a/src/Features/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs index 031e241a9fa5e..b17c3bec86600 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class TypeDefinitionOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs index eaff6e3e52e55..238da08d40af5 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs @@ -4,21 +4,20 @@ namespace Roslyn.LanguageServer.Protocol; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; /// /// Class representing a diagnostic report indicating that the last returned report is still accurate. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class UnchangedDocumentDiagnosticReport { /// /// Gets the kind of this report. /// - [DataMember(Name = "kind")] + [JsonPropertyName("kind")] #pragma warning disable CA1822 // Mark members as static public string Kind => DocumentDiagnosticReportKind.Unchanged; #pragma warning restore CA1822 // Mark members as static @@ -26,7 +25,7 @@ internal class UnchangedDocumentDiagnosticReport /// /// Gets or sets the optional result id. /// - [DataMember(Name = "resultId")] + [JsonPropertyName("resultId")] public string ResultId { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/Unregistration.cs b/src/Features/LanguageServer/Protocol/Protocol/Unregistration.cs index 03493010e0a44..ea2c9e8efbea3 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/Unregistration.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/Unregistration.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the information needed for unregistering a capability. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class Unregistration { /// /// Gets or sets the id of the unregistration. /// - [DataMember(Name = "id")] + [JsonPropertyName("id")] public string Id { get; @@ -27,7 +26,7 @@ public string Id /// /// Gets or sets the method to unregister. /// - [DataMember(Name = "method")] + [JsonPropertyName("method")] public string Method { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/UnregistrationParams.cs b/src/Features/LanguageServer/Protocol/Protocol/UnregistrationParams.cs index 54d954451b88e..118084c82212d 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/UnregistrationParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/UnregistrationParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameter sent for the client/unregisterCapability request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class UnregistrationParams { /// /// Gets or sets the capabilities to unregister. /// - [DataMember(Name = "unregistrations")] + [JsonPropertyName("unregistrations")] public Unregistration[] Unregistrations { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/VersionedTextDocumentIdentifier.cs b/src/Features/LanguageServer/Protocol/Protocol/VersionedTextDocumentIdentifier.cs index ecffd30fcdbba..296808d6a31f4 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/VersionedTextDocumentIdentifier.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/VersionedTextDocumentIdentifier.cs @@ -6,21 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Globalization; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents a text document, but has a version identifier. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class VersionedTextDocumentIdentifier : TextDocumentIdentifier, IEquatable { /// /// Gets or sets the version of the document. /// - [DataMember(Name = "version")] + [JsonPropertyName("version")] public int Version { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs b/src/Features/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs index fb88efda26c86..46269ba196183 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs @@ -4,20 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; + using System.Text.Json.Serialization; /// /// Class representing the parameters sent for the textDocument/willSave request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WillSaveTextDocumentParams : ITextDocumentParams { /// /// Gets or sets the representing the document to be saved. /// - [DataMember(Name = "textDocument")] + [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument { get; @@ -27,7 +26,7 @@ public TextDocumentIdentifier TextDocument /// /// Gets or sets the reason that the text document was saved. /// - [DataMember(Name = "reason")] + [JsonPropertyName("reason")] public TextDocumentSaveReason Reason { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 74cb04f4e3912..a045161ec3973 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WorkspaceClientCapabilities { /// /// Gets or sets a value indicating whether apply edit is supported. /// - [DataMember(Name = "applyEdit")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("applyEdit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ApplyEdit { get; @@ -29,8 +27,8 @@ public bool ApplyEdit /// /// Gets or sets the workspace edit setting. /// - [DataMember(Name = "workspaceEdit")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("workspaceEdit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public WorkspaceEditSetting? WorkspaceEdit { get; @@ -40,8 +38,8 @@ public WorkspaceEditSetting? WorkspaceEdit /// /// Gets or sets the setting which determines if did change configuration can be dynamically registered. /// - [DataMember(Name = "didChangeConfiguration")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("didChangeConfiguration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? DidChangeConfiguration { get; @@ -51,8 +49,8 @@ public DynamicRegistrationSetting? DidChangeConfiguration /// /// Gets or sets the setting which determines if did change watched files can be dynamically registered. /// - [DataMember(Name = "didChangeWatchedFiles")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("didChangeWatchedFiles")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? DidChangeWatchedFiles { get; @@ -62,8 +60,8 @@ public DynamicRegistrationSetting? DidChangeWatchedFiles /// /// Gets or sets the setting which determines if symbols can be dynamically registered. /// - [DataMember(Name = "symbol")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("symbol")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SymbolSetting? Symbol { get; @@ -73,8 +71,8 @@ public SymbolSetting? Symbol /// /// Gets or sets the setting which determines if execute command can be dynamically registered. /// - [DataMember(Name = "executeCommand")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("executeCommand")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? ExecuteCommand { get; @@ -84,8 +82,8 @@ public DynamicRegistrationSetting? ExecuteCommand /// /// Gets or sets capabilities specific to the semantic token requests scoped to the workspace. /// - [DataMember(Name = "semanticTokens")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("semanticTokens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensWorkspaceSetting? SemanticTokens { get; @@ -95,8 +93,8 @@ public SemanticTokensWorkspaceSetting? SemanticTokens /// /// Gets or sets capabilities indicating what support the client has for workspace pull diagnostics. /// - [DataMember(Name = "diagnostics")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("diagnostics")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticWorkspaceSetting? Diagnostics { get; @@ -106,8 +104,8 @@ public DiagnosticWorkspaceSetting? Diagnostics /// /// Gets or sets the capabilities if client support 'workspace/configuration' requests. /// - [DataMember(Name = "configuration")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("configuration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Configuration { get; @@ -117,8 +115,8 @@ public bool Configuration /// /// Gets of sets capabilities specific to the inlay hint requests scoped to the workspace. /// - [DataMember(Name = "inlayHint")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("inlayHint")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintWorkspaceSetting? InlayHint { get; @@ -128,8 +126,8 @@ public InlayHintWorkspaceSetting? InlayHint /// /// Gets of sets capabilities specific to the code lens requests scoped to the workspace. /// - [DataMember(Name = "codeLens")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("codeLens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeLensWorkspaceSetting? CodeLens { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs index f8c2cdb7dcfef..850f8c4fa31ab 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs @@ -5,8 +5,7 @@ namespace Roslyn.LanguageServer.Protocol; using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing the workspace diagnostic request parameters @@ -17,14 +16,13 @@ namespace Roslyn.LanguageServer.Protocol; /// Note that the first literal send needs to be a /// followed by n literals. /// -[DataContract] internal class WorkspaceDiagnosticParams : IPartialResultParams> { /// /// Gets or sets the value of the Progress instance. /// - [DataMember(Name = Methods.PartialResultTokenName, IsRequired = false)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress>? PartialResultToken { get; @@ -34,8 +32,8 @@ public IProgress /// Gets or sets the identifier for which the client is requesting diagnostics for. /// - [DataMember(Name = "identifier")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("identifier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Identifier { get; @@ -45,7 +43,7 @@ public string? Identifier /// /// Gets or sets the result id of a previous diagnostics response if provided. /// - [DataMember(Name = "previousResultIds")] + [JsonPropertyName("previousResultIds")] public PreviousResultId[] PreviousResultId { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs index fff52c02f2e2e..49b33e63f135a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs @@ -3,23 +3,19 @@ // See the LICENSE file in the project root for more information. namespace Roslyn.LanguageServer.Protocol; - -using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a workspace diagnostic report. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class WorkspaceDiagnosticReport { /// /// Gets or sets the items in this diagnostic report. /// - [DataMember(Name = "items")] + [JsonPropertyName("items")] public SumType[] Items { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs index f2e3387cc2c88..1c29c40074e81 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs @@ -3,23 +3,19 @@ // See the LICENSE file in the project root for more information. namespace Roslyn.LanguageServer.Protocol; - -using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a partial result for a workspace diagnostic report. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] internal class WorkspaceDiagnosticReportPartialResult { /// /// Gets or sets the items in this diagnostic report. /// - [DataMember(Name = "items")] + [JsonPropertyName("items")] public SumType[] Items { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs index 23fba470b1e07..d3739a5a90425 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol { using System.Collections.Generic; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class representing a request sent from a language server to modify resources in the workspace. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WorkspaceEdit { /// /// Gets or sets a dictionary holding changes to existing resources. /// - [DataMember(Name = "changes")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("changes")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Dictionary? Changes { get; @@ -30,8 +28,8 @@ public Dictionary? Changes /// /// Gets or sets an array representing versioned document changes. /// - [DataMember(Name = "documentChanges")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("documentChanges")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType[]>? DocumentChanges { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs index 26265677883bd..c3aee573bdf8f 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents initialization settings for workspace edit. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WorkspaceEditSetting { /// /// Gets or sets a value indicating whether document changes event is supported. /// - [DataMember(Name = "documentChanges")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("documentChanges")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DocumentChanges { get; @@ -29,8 +27,8 @@ public bool DocumentChanges /// /// GEts or sets the resource operations the client supports. /// - [DataMember(Name = "resourceOperations")] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("resourceOperations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ResourceOperationKind[]? ResourceOperations { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs index 7a2f9d84ee9d2..95ec1cad08b96 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol; using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a full document diagnostic report for workspace diagnostic result. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Full)] internal class WorkspaceFullDocumentDiagnosticReport : FullDocumentDiagnosticReport { /// /// Gets or sets the URI associated with this diagnostic report. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -32,7 +30,7 @@ public Uri Uri /// Gets or sets the version number for which the diagnostics are reported. /// If the document is not marked as open 'null' can be provided. /// - [DataMember(Name = "version")] + [JsonPropertyName("version")] public int? Version { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs index 8f2f697842d37..01ac93b66f538 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs @@ -4,22 +4,20 @@ namespace Roslyn.LanguageServer.Protocol { - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents workspace symbols capabilities. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WorkspaceSymbolOptions : IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. /// - [DataMember(Name = "workDoneProgress")] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } } } diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs index 2ef10ea9fa3ef..bc70cf64c559a 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs @@ -5,21 +5,19 @@ namespace Roslyn.LanguageServer.Protocol { using System; - using System.Runtime.Serialization; - using Newtonsoft.Json; + using System.Text.Json.Serialization; /// /// Class which represents the parameter that's sent with the 'workspace/symbol' request. /// /// See the Language Server Protocol specification for additional information. /// - [DataContract] internal class WorkspaceSymbolParams : IPartialResultParams { /// /// Gets or sets the query (a non-empty string). /// - [DataMember(Name = "query")] + [JsonPropertyName("query")] public string Query { get; @@ -29,8 +27,8 @@ public string Query /// /// Gets or sets the value of the Progress instance. /// - [DataMember(Name = Methods.PartialResultTokenName)] - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; diff --git a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs index d7aa7192da725..1fc1bd8cda697 100644 --- a/src/Features/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs +++ b/src/Features/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs @@ -5,22 +5,20 @@ namespace Roslyn.LanguageServer.Protocol; using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// Class representing a unchanged document diagnostic report for workspace diagnostic result. /// /// See the Language Server Protocol specification for additional information. /// -[DataContract] [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class WorkspaceUnchangedDocumentDiagnosticReport : UnchangedDocumentDiagnosticReport { /// /// Gets or sets the URI associated with this diagnostic report. /// - [DataMember(Name = "uri")] + [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -32,7 +30,7 @@ public Uri Uri /// Gets or sets the version number for which the diagnostics are reported. /// If the document is not marked as open 'null' can be provided. /// - [DataMember(Name = "version")] + [JsonPropertyName("version")] public int? Version { get; diff --git a/src/Features/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspace.cs b/src/Features/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspace.cs index 92ac29ae53f61..bb5490d3220ea 100644 --- a/src/Features/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspace.cs +++ b/src/Features/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspace.cs @@ -3,15 +3,11 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Features.Workspaces; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; diff --git a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs index 289f609e7df67..5a7b6a6a69a09 100644 --- a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs +++ b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks;