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

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 11, 2023

Follows the same patterns as the existing library we use. However, while the types are the same, the namespace is different so as to not conflict.

Followup to #71141. Draft until that goes in. That PR introduced the types. This PR moves us onto them. We also remove our actual references entirely to the VS libs.

build: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_build/results?buildId=8820065&view=results
PR: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/517178

Follows the same patterns as the existing library we use.  However, while the types are the same, the namespace is different so as to not conflict.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 11, 2023
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.

=> 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.

@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member Author

Choose a reason for hiding this comment

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

all our own versions of these lsp objects.

pros:

  1. follows the same approach as MS.VS.LS.Protocol.
  2. Is binary compatible for our code (modulo updating our namespace).
  3. Can be tweaked as we see fit on our own schedule

Cons:

  1. Newtonsoft based.
  2. May diverge from VS as they add support for things. Will require manual upkeep.
  3. Large.

Copy link
Contributor

@davidwengier davidwengier Jul 11, 2023

Choose a reason for hiding this comment

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

Can be tweaked as we see fit on our own schedule

Razor has the same problem to solve with MS.VS.LS.Protocol. Would you rather us not use these so you are free to modify at will?

Copy link
Member

Choose a reason for hiding this comment

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

We need to do something here in regards to clasp / this with Razor. currently we basically cannot make any changes to clasp (of which I've wanted to make quite a fiew) without doing a dual insertion. I would like us to avoid more places where we need that, especially because LSP compatibility does not mean binary compat

Copy link
Member

Choose a reason for hiding this comment

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

without doing a dual insertion

I would block Razor using these types until we figure out how / if we can share it without dual insertions

I think we should also strongly consider using Karthik / Matteo's generation library for these (though doesn't have to be now). If we're using them,

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. we could potenitally make this a source package or something as well. it truly is just serialization goo.

does Karthik's lib handle all the extension cases?

Copy link
Member

Choose a reason for hiding this comment

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

Though - I would also avoid putting these definitions in clasp. It should probably be a different (source-only) package.

Copy link
Contributor

Choose a reason for hiding this comment

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

would having VS platform owned source package solve the issue we are tying to solve?

Copy link
Member Author

Choose a reason for hiding this comment

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

@olegtk yes. If the license for those files didn't conflict in some way.

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it cause PerfDDRIT regression though?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not as a source package. It wouldn't make a new dll. It would literally just me code added to Roslyn. Just maintained in one location.

@CyrusNajmabadi
Copy link
Member Author

@arkalyanms @dibarbet @jasonmalinowski . This should hopefully get us licensing clean. This is not my first choice at all. But absent approval and movement on unblocking these dependencies working with our license, this is the most expedient path forward. As we can see, there is literally nothing of interest here. It's all just DataContract + Newtonsoft.Json goop to give us an object model on top of the LSP protocol.

@CyrusNajmabadi CyrusNajmabadi force-pushed the lspApis2 branch 2 times, most recently from 3fb3596 to 4770338 Compare July 11, 2023 21:47
@CyrusNajmabadi
Copy link
Member Author

also tagging @333fred as this may impact some downstream consumers (but in a way that should be easy to migrate to).

@davidwengier
Copy link
Contributor

It seems odd that these are part of the public API of Microsoft.CommonLanguageServerProtocol.Framework, but namespaced with "Roslyn". Additionally, CLaSP was specifically written to avoid direct dependencies on LSP protocol POCOs. I think it would make sense to either move these out into their own/another project, or keep them in CLaSP, but namespace them accordingly (and in future, we could review whether the original design decision makes sense)

@@ -0,0 +1,59 @@
<Project>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be here?

@CyrusNajmabadi
Copy link
Member Author

It seems odd that these are part of the public API of Microsoft.CommonLanguageServerProtocol.Framework, but namespaced with "Roslyn". Additionally, CLaSP was specifically written to avoid direct dependencies on LSP protocol POCOs. I think it would make sense to either move these out into their own/another project, or keep them in CLaSP, but namespace them accordingly (and in future, we could review whether the original design decision makes sense)

All this is good feedback. I will say that my #1 goal above all else is to get us first to a clean licensing position. That delivers on our own licensing being sane, and making properly consumable by downstream (as well as abiding by everything we've promised).

After getting clean, i think we can update this aggressively to be in a place we want. That includes, but is not limited to:

  1. deciding if these 'model types' should be in this lib, or in a separate lib.
  2. deciding on the namespace for these types.
  3. deciding on the general patterns practices for these types. For example, i would prefer them all to be records, with strong immutability guarantees around them.

But this can all come later IMO.

using System.Collections.Immutable;
using Roslyn.Text.Adornments;

namespace Roslyn.Text.Adornments
Copy link
Member

Choose a reason for hiding this comment

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

I would really like to avoid redefining the VS types if at all possible. Today using the protocol libs as-is, we can make the protocol project only depend on the public definitions by default (add more abstraction around the creation of LSP types).

However if we're using our own definitions I can see using the actual VS LSP library definitions could be hard, especially if we want a VSHover to be a subclass of an LSP Hover. The only workaround I can think of is object types, but that doesn't seem super nice.

Re-defining the vs only types is going to be annoying especially since that is where a lot of the changes go (so keeping in syc could be challenging).

Copy link
Member

@arunchndr arunchndr left a comment

Choose a reason for hiding this comment

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

We have been asked to hold off on this PR in favor of a holistic solution on the LSP side.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 7, 2023 00:43
@CyrusNajmabadi CyrusNajmabadi requested review from 333fred and a team as code owners December 7, 2023 00:43
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Implement json serialization/deserialization for LSP json messages. Implement json serialization/deserialization for LSP json messages. Dec 7, 2023
@CyrusNajmabadi CyrusNajmabadi changed the title Implement json serialization/deserialization for LSP json messages. Implement json serialization/deserialization for LSP json messages. Part 2/N Dec 7, 2023
@CyrusNajmabadi CyrusNajmabadi marked this pull request as draft December 7, 2023 03:33
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 18, 2023 18:29
@CyrusNajmabadi
Copy link
Member Author

Moving forward. Speedometer showed no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants