Make SolutionServices (and related) APIs public#63241
Make SolutionServices (and related) APIs public#63241CyrusNajmabadi merged 10 commits intodotnet:mainfrom
Conversation
| identifier = currentRoot.GetCurrentNode(identifier); | ||
|
|
||
| var editor = document.GetSyntaxEditor(currentRoot); | ||
| var editor = new SyntaxEditor(currentRoot, document.Project.Solution.Services); |
There was a problem hiding this comment.
Reverted this code to the original pattern now that we have this public API.
| { | ||
| var parsedDocument = ParsedDocument.CreateSynchronously(document, cancellationToken); | ||
| var options = textBuffer.GetSyntaxFormattingOptions(_editorOptionsService, parsedDocument.ProjectServices, explicitFormat: true); | ||
| var options = textBuffer.GetSyntaxFormattingOptions(_editorOptionsService, parsedDocument.LanguageServices, explicitFormat: true); |
There was a problem hiding this comment.
ProjectServices was renamed to LanugageServices on behalf of the API committee. This was preferred as the type exposes ILanguageServices. I originally didn't name it that way as we we had HostLanguageServices and i was naming the type HostXXX. However, the API group decided to drop Host. So now we have:
HostWorkspaceServices (existing, mutable) and its immutable counterpart: SolutionServices
HostLanguageServices (existing, mutable) and its immutable counterpart: LanguageServices
|
|
||
| var (formattingChanges, finalCurlyBraceEnd) = FormatTrackingSpan( | ||
| context.Document, | ||
| context.Document.LanguageServices.ProjectServices, |
There was a problem hiding this comment.
unnecessarily redundant with the ParsedDocument being passed in. removed this parameter.
| /// Creates a new <see cref="SyntaxEditor"/> instance. | ||
| /// </summary> | ||
| internal SyntaxEditor(SyntaxNode root, HostSolutionServices services) | ||
| public SyntaxEditor(SyntaxNode root, SolutionServices services) |
There was a problem hiding this comment.
New public API.
| Microsoft.CodeAnalysis.Host.SolutionServices.IsSupported(string languageName) -> bool | ||
| Microsoft.CodeAnalysis.Host.SolutionServices.SupportedLanguages.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.CodeAnalysis.Project.Services.get -> Microsoft.CodeAnalysis.Host.LanguageServices | ||
| Microsoft.CodeAnalysis.Solution.Services.get -> Microsoft.CodeAnalysis.Host.SolutionServices |
There was a problem hiding this comment.
this is worth reviewing to make sure it aligns with the shape people expect.
| /// Immutable snapshot of the host services. Preferable to use instead of this <see | ||
| /// cref="HostLanguageServices"/> when possible. | ||
| /// </summary> | ||
| public LanguageServices LanguageServices { get; } |
There was a problem hiding this comment.
New public API.
| /// <summary> | ||
| /// Per language services provided by the host environment. | ||
| /// </summary> | ||
| public sealed class LanguageServices |
There was a problem hiding this comment.
New public API. ANd all public members in this are the new public api shape. It's worth expanding this file to see/understand them.
| internal LanguageServices(HostLanguageServices services) | ||
| { | ||
| _services = services; | ||
| } |
There was a problem hiding this comment.
note: GetRequiredService below could become an extension method. But that has the downside that the caller must know to include a using for Microsoft.CodeAnalysis.Host to see that extension. so it's just convenient to have thse be instance methods instead.
There was a problem hiding this comment.
Instance methods are definitely better. Extension methods are not discoverable.
| /// <summary> | ||
| /// Per solution services provided by the host environment. | ||
| /// </summary> | ||
| public sealed class SolutionServices |
There was a problem hiding this comment.
new public API. it's worth expanding this file to see the entire shape exposed.
| /// Immutable snapshot of language services from the host environment associated with this project's language. | ||
| /// Use this over <see cref="LanguageServices"/> when possible. | ||
| /// </summary> | ||
| public Host.LanguageServices Services => LanguageServices.LanguageServices; |
There was a problem hiding this comment.
new public API.
| /// Per solution services provided by the host environment. Use this instead of <see | ||
| /// cref="Workspace.Services"/> when possible. | ||
| /// </summary> | ||
| public SolutionServices Services => _state.Services.SolutionServices; |
There was a problem hiding this comment.
new public API.
| } | ||
| #endif | ||
|
|
||
| public static SyntaxEditor GetSyntaxEditor(this Document document, SyntaxNode root) |
There was a problem hiding this comment.
removed this extension which just existed so we could customize CODE_STYLE behavior prior to these types becoming public.
|
@dotnet/roslyn-ide please review. |
|
Many places using |
Yes. but i would strongly advise in a separate PR. Here's the issue, right now this PR adds the public type I can resolve the conflict by renaming the existing non-exported namespace to something like I will link to that PR immediately though. |
|
@tmat PTAL. Thanks :) |
| /// of such feature to either not be invoked on a UI thread or be entirely synchronous. | ||
| /// </remarks> | ||
| internal readonly record struct ParsedDocument(DocumentId Id, SourceText Text, SyntaxNode Root, HostLanguageServices LanguageServices) | ||
| internal readonly record struct ParsedDocument(DocumentId Id, SourceText Text, SyntaxNode Root, HostLanguageServices HostLanguageServices) |
There was a problem hiding this comment.
Have noted this for follow-up
Closes #62914.
Approved by Public API committee.
I have commented interesting lines to help explain the API shape changes that were approved and came along with things becoming public.