Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement json serialization/deserialization for LSP json messages. Part 2/N #68990

Merged
merged 33 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a5375e
Implement json serialization/deserialization for LSP json messages.
CyrusNajmabadi Jul 11, 2023
99570a1
Merge branch 'main' into lspApis2
CyrusNajmabadi Jul 11, 2023
611c756
Merge remote-tracking branch 'upstream/main' into lspApis2
CyrusNajmabadi Jul 12, 2023
7592fef
lint
CyrusNajmabadi Jul 12, 2023
f74a4bc
Lint
CyrusNajmabadi Jul 12, 2023
448194d
Update
CyrusNajmabadi Jul 12, 2023
d387fca
Marshalling
CyrusNajmabadi Jul 12, 2023
80ed94e
Marshalling
CyrusNajmabadi Jul 12, 2023
8681f96
Find refs
CyrusNajmabadi Jul 12, 2023
e6287b3
Merge remote-tracking branch 'upstream/main' into lspApis2
CyrusNajmabadi Dec 7, 2023
c00dde3
Move
CyrusNajmabadi Dec 7, 2023
83226f1
No need for this attribute
CyrusNajmabadi Dec 7, 2023
e75a404
Add project ref
CyrusNajmabadi Dec 7, 2023
72de881
editorconfig
CyrusNajmabadi Dec 7, 2023
38f03ff
remove references
CyrusNajmabadi Dec 7, 2023
779f6af
remove unnecessary code
CyrusNajmabadi Dec 7, 2023
0a447ec
Fix tests
CyrusNajmabadi Dec 7, 2023
b6d97f2
Rename type
CyrusNajmabadi Dec 7, 2023
31cb874
Add new types in
CyrusNajmabadi Dec 7, 2023
aefdc5d
Remove file
CyrusNajmabadi Dec 7, 2023
f7d0c33
Merge branch 'lspApis3' into lspApis2
CyrusNajmabadi Dec 7, 2023
2cb528a
Make internal
CyrusNajmabadi Dec 7, 2023
53b4d15
Merge branch 'lspApis3' into lspApis2
CyrusNajmabadi Dec 7, 2023
232ebb1
Merge branch 'main' into lspApis3
CyrusNajmabadi Dec 15, 2023
6215db6
Merge branch 'lspApis3' into lspApis2
CyrusNajmabadi Dec 15, 2023
bbc3105
Downstream fallout
CyrusNajmabadi Dec 15, 2023
4ad5db0
Fixes
CyrusNajmabadi Dec 15, 2023
fe289fc
Accvessibility
CyrusNajmabadi Dec 15, 2023
cb0278c
fixes
CyrusNajmabadi Dec 15, 2023
1ff3c20
fixes
CyrusNajmabadi Dec 15, 2023
c22e296
fixes
CyrusNajmabadi Dec 15, 2023
19b6a4e
fixes
CyrusNajmabadi Dec 15, 2023
0c984c0
Fix
CyrusNajmabadi Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.LanguageServer.Protocol;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of fallout from switching from Microsoft.VisualStudio.LanguageServer.Protocol to Roslyn.LanguageServer.Protocol.

using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Classification
Expand Down
27 changes: 27 additions & 0 deletions src/EditorFeatures/Core/Extensions/LSPExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.Extensions
{
internal static class LSPExtensions
{
public static Roslyn.Core.Imaging.ImageId ToLSPImageId(this VisualStudio.Core.Imaging.ImageId imageId)
=> new Roslyn.Core.Imaging.ImageId(imageId.Guid, imageId.Id);

public static Roslyn.Text.Adornments.ImageElement ToLSPImageElement(this VisualStudio.Text.Adornments.ImageElement imageElement)
=> new Roslyn.Text.Adornments.ImageElement(imageElement.ImageId.ToLSPImageId(), imageElement.AutomationName);

public static Roslyn.Text.Adornments.ClassifiedTextRun ToLSPRun(this VisualStudio.Text.Adornments.ClassifiedTextRun run)
=> new Roslyn.Text.Adornments.ClassifiedTextRun(run.ClassificationTypeName, run.Text, run.NavigationAction, run.Tooltip, (Roslyn.Text.Adornments.ClassifiedTextRunStyle)run.Style);

public static Roslyn.Text.Adornments.ClassifiedTextElement ToLSPElement(this VisualStudio.Text.Adornments.ClassifiedTextElement element)
=> new Roslyn.Text.Adornments.ClassifiedTextElement(element.Runs.Select(r => r.ToLSPRun()));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few helpers for when we have some VS types to convert to LSP types.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;

internal interface IVSTypeScriptCapabilitiesProvider
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Utilities;
using Newtonsoft.Json;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Threading;
using Nerdbank.Streams;
using Roslyn.LanguageServer.Protocol;
using StreamJsonRpc;

namespace Microsoft.CodeAnalysis.Editor.Implementation.LanguageClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
Expand All @@ -15,11 +14,10 @@
using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics;
using Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Utilities;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.Editor.Implementation.LanguageClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.QuickInfo;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler.Completion;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Roslyn.Text.Adornments;
using Roslyn.Utilities;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer
{
Expand All @@ -42,7 +43,7 @@ public EditorLspCompletionResultCreationService()
var lspItem = new LSP.VSInternalCompletionItem
{
Label = item.GetEntireDisplayText(),
Icon = new ImageElement(item.Tags.GetFirstGlyph().GetImageId())
Icon = new ImageElement(item.Tags.GetFirstGlyph().GetImageId().ToLSPImageId()),
};

// Complex text edits (e.g. override and partial method completions) are always populated in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Text.Adornments;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Text.Adornments;
using LSP = Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer
{
Expand All @@ -24,7 +25,7 @@ public EditorLspReferencesResultCreationService()
{
}

public SumType<VSInternalReferenceItem, VisualStudio.LanguageServer.Protocol.Location>? CreateReference(
public SumType<VSInternalReferenceItem, Roslyn.LanguageServer.Protocol.Location>? CreateReference(
int definitionId,
int id,
ClassifiedTextElement text,
Expand All @@ -33,15 +34,16 @@ public EditorLspReferencesResultCreationService()
ClassifiedTextElement? definitionText,
Glyph definitionGlyph,
SymbolUsageInfo? symbolUsageInfo,
VisualStudio.LanguageServer.Protocol.Location? location)
Roslyn.LanguageServer.Protocol.Location? location)
{
// TO-DO: The Origin property should be added once Rich-Nav is completed.
// https://github.com/dotnet/roslyn/issues/42847
var imageId = definitionGlyph.GetImageId();
var result = new VSInternalReferenceItem
{
DefinitionId = definitionId,
DefinitionText = definitionText, // Only definitions should have a non-null DefinitionText
DefinitionIcon = new ImageElement(definitionGlyph.GetImageId()),
DefinitionIcon = new ImageElement(imageId.ToLSPImageId()),
DisplayPath = location?.Uri.LocalPath,
Id = id,
Kind = symbolUsageInfo.HasValue ? ProtocolConversions.SymbolUsageInfoToReferenceKinds(symbolUsageInfo.Value) : Array.Empty<VSInternalReferenceKind>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;
using LSP = Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Utilities;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.Editor.Implementation.LanguageClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler.InlineCompletions;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Utilities;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.Editor.Implementation.LanguageClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Options;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Roslyn.LanguageServer.Protocol;

namespace Roslyn.Test.Utilities
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.Editor.Test;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
Expand All @@ -37,7 +38,7 @@
using StreamJsonRpc;
using Xunit;
using Xunit.Abstractions;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Roslyn.LanguageServer.Protocol;

namespace Roslyn.Test.Utilities
{
Expand Down Expand Up @@ -120,10 +121,9 @@ protected static LSP.ClientCapabilities GetCapabilities(bool isVS)
/// <summary>
/// Asserts two objects are equivalent by converting to JSON and ignoring whitespace.
/// </summary>
/// <typeparam name="T">the JSON object type.</typeparam>
/// <param name="expected">the expected object to be converted to JSON.</param>
/// <param name="actual">the actual object to be converted to JSON.</param>
public static void AssertJsonEquals<T>(T expected, T actual)
public static void AssertJsonEquals<T1, T2>(T1 expected, T2 actual)
{
var expectedStr = JsonConvert.SerializeObject(expected);
var actualStr = JsonConvert.SerializeObject(actual);
Expand Down Expand Up @@ -280,7 +280,7 @@ protected static LSP.CompletionParams CreateCompletionParams(
};

if (tags != null)
item.Icon = tags.ToImmutableArray().GetFirstGlyph().GetImageElement();
item.Icon = tags.ToImmutableArray().GetFirstGlyph().GetImageElement().ToLSPImageElement();

if (commitCharacters != null)
item.CommitCharacters = commitCharacters.Value.Select(c => c.ToString()).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;

namespace Microsoft.CodeAnalysis.LanguageServer.BrokeredServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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 Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer.LanguageServer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CommonLanguageServerProtocol.Framework.Example;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using Microsoft.CommonLanguageServerProtocol.Framework.Handlers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;
using StreamJsonRpc;

namespace Microsoft.CommonLanguageServerProtocol.Framework.Example;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionVersion)" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol" Version="$(MicrosoftVisualStudioLanguageServerProtocolVersion)" />
</ItemGroup>

<ItemGroup Label="Project References">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CommonLanguageServerProtocol.Framework.Example;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.LanguageServer.Protocol;
using Xunit;

namespace Microsoft.CommonLanguageServerProtocol.Framework.UnitTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CommonLanguageServerProtocol.Framework.Example;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.Extensions.DependencyInjection;
using Nerdbank.Streams;
using Roslyn.LanguageServer.Protocol;
using StreamJsonRpc;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.CommonLanguageServerProtocol.Framework.UnitTests;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
dotnet_diagnostic.CS8618.severity = none
Loading