-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52907 from 333fred/osharp-externalaccess
Add OmniSharp ExternalAccess
- Loading branch information
Showing
37 changed files
with
941 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# External Access Policies | ||
|
||
## OmniSharp | ||
|
||
When a change needs to be made to an API in the ExternalAccess.OmniSharp or ExternalAccess.OmniSharp.CSharp packages, ping @333fred, @JoeRobich, @filipw, or @david-driscoll as a heads up. Breaking changes are allowed, but please wait for acknowledgement and followup questions to ensure that we don't completely break OmniSharp scenarios. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Tools/ExternalAccess/OmniSharp.CSharp/Completion/OmniSharpCompletionProviderNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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 Microsoft.CodeAnalysis.CSharp.Completion.Providers; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp.Completion | ||
{ | ||
internal static class OmniSharpCompletionProviderNames | ||
{ | ||
internal static string ObjectCreationCompletionProvider = typeof(ObjectCreationCompletionProvider).FullName; | ||
internal static string OverrideCompletionProvider = typeof(OverrideCompletionProvider).FullName; | ||
internal static string PartialMethodCompletionProvider = typeof(PartialMethodCompletionProvider).FullName; | ||
internal static string InternalsVisibleToCompletionProvider = typeof(InternalsVisibleToCompletionProvider).FullName; | ||
internal static string TypeImportCompletionProvider = typeof(TypeImportCompletionProvider).FullName; | ||
internal static string ExtensionMethodImportCompletionProvider = typeof(ExtensionMethodImportCompletionProvider).FullName; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ols/ExternalAccess/OmniSharp.CSharp/DocumentationComments/OmniSharpDocCommentConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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.Threading; | ||
using Microsoft.CodeAnalysis.CSharp.DocumentationComments; | ||
using Microsoft.CodeAnalysis.DocumentationComments; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp.DocumentationComments | ||
{ | ||
internal static class OmniSharpDocCommentConverter | ||
{ | ||
public static SyntaxNode ConvertToRegularComments(SyntaxNode node, Project project, CancellationToken cancellationToken) | ||
{ | ||
var formattingService = project.GetRequiredLanguageService<IDocumentationCommentFormattingService>(); | ||
return DocCommentConverter.ConvertToRegularComments(node, formattingService, cancellationToken); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...rnalAccess/OmniSharp.CSharp/Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
|
||
<IsPackable>true</IsPackable> | ||
<PackageId>Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp</PackageId> | ||
<PackageDescription> | ||
A supporting package for OmniSharp: | ||
https://github.com/OmniSharp/omnisharp-roslyn | ||
</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.UnitTests" /> | ||
<!-- | ||
⚠ ONLY OMNISHARP ASSEMBLIES MAY BE ADDED HERE ⚠ | ||
--> | ||
<InternalsVisibleTo Include="OmniSharp.Roslyn.CSharp" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.Roslyn.CSharp.Tests" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.DotNetTest" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.DotNetTest.Tests" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.LanguageServerProtocol" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.Lsp.Tests" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.MSBuild" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.MSBuild.Tests" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.Script" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.Script.Tests" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.Cake" Key="$(OmniSharpKey)" /> | ||
<InternalsVisibleTo Include="OmniSharp.CakeTests" Key="$(OmniSharpKey)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" /> | ||
<ProjectReference Include="..\..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" /> | ||
<ProjectReference Include="..\..\..\Features\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Features.csproj" /> | ||
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" /> | ||
<ProjectReference Include="..\OmniSharp\Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PublicAPI Include="PublicAPI.Shipped.txt" /> | ||
<PublicAPI Include="PublicAPI.Unshipped.txt" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Empty file.
1 change: 1 addition & 0 deletions
1
src/Tools/ExternalAccess/OmniSharp.CSharp/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
15 changes: 15 additions & 0 deletions
15
src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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.Collections.Immutable; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CodeActions | ||
{ | ||
internal static class OmniSharpCodeAction | ||
{ | ||
public static ImmutableArray<CodeAction> GetNestedCodeActions(this CodeAction codeAction) | ||
=> codeAction.NestedCodeActions; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...gs/WorkspaceServices/IOmniSharpSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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. | ||
|
||
#nullable disable | ||
|
||
using Microsoft.CodeAnalysis.CodeActions; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CodeRefactorings.WorkspaceServices | ||
{ | ||
interface IOmniSharpSymbolRenamedCodeActionOperationFactoryWorkspaceService | ||
{ | ||
CodeActionOperation CreateSymbolRenamedOperation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Tools/ExternalAccess/OmniSharp/Completion/OmniSharpCompletionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Completion; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Completion | ||
{ | ||
internal static class OmniSharpCompletionService | ||
{ | ||
public static Task<(CompletionList completionList, bool expandItemsAvailable)> GetCompletionsAsync( | ||
this CompletionService completionService, | ||
Document document, | ||
int caretPosition, | ||
CompletionTrigger trigger = default, | ||
ImmutableHashSet<string>? roles = null, | ||
OptionSet? options = null, | ||
CancellationToken cancellationToken = default) | ||
=> completionService.GetCompletionsInternalAsync(document, caretPosition, trigger, roles, options, cancellationToken); | ||
|
||
public static Task<CompletionChange> GetChangeAsync( | ||
this CompletionService completionService, | ||
Document document, | ||
CompletionItem item, | ||
TextSpan completionListSpan, | ||
char? commitCharacter = null, | ||
bool disallowAddingImports = false, | ||
CancellationToken cancellationToken = default) | ||
=> completionService.GetChangeAsync(document, item, completionListSpan, commitCharacter, disallowAddingImports, cancellationToken); | ||
|
||
public static string GetProviderName(this CompletionItem completionItem) => completionItem.ProviderName; | ||
|
||
public static PerLanguageOption<bool?> ShowItemsFromUnimportedNamespaces = (PerLanguageOption<bool?>)CompletionOptions.ShowItemsFromUnimportedNamespaces; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...nalAccess/OmniSharp/DocumentationComments/OmniSharpDocumentationCommentsSnippetService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// 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.Threading; | ||
using Microsoft.CodeAnalysis.DocumentationComments; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.DocumentationComments | ||
{ | ||
internal static class OmniSharpDocumentationCommentsSnippetService | ||
{ | ||
public static OmniSharpDocumentationCommentSnippet? GetDocumentationCommentSnippetOnCharacterTyped( | ||
Document document, | ||
SyntaxTree syntaxTree, | ||
SourceText text, | ||
int position, | ||
DocumentOptionSet options, | ||
CancellationToken cancellationToken) | ||
{ | ||
var service = document.GetRequiredLanguageService<IDocumentationCommentSnippetService>(); | ||
return Translate(service.GetDocumentationCommentSnippetOnCharacterTyped(syntaxTree, text, position, options, cancellationToken)); | ||
} | ||
|
||
public static OmniSharpDocumentationCommentSnippet? GetDocumentationCommentSnippetOnCommandInvoke( | ||
Document document, | ||
SyntaxTree syntaxTree, | ||
SourceText text, | ||
int position, | ||
DocumentOptionSet options, | ||
CancellationToken cancellationToken) | ||
{ | ||
var service = document.GetRequiredLanguageService<IDocumentationCommentSnippetService>(); | ||
return Translate(service.GetDocumentationCommentSnippetOnCommandInvoke(syntaxTree, text, position, options, cancellationToken)); | ||
} | ||
|
||
public static OmniSharpDocumentationCommentSnippet? GetDocumentationCommentSnippetOnEnterTyped( | ||
Document document, | ||
SyntaxTree syntaxTree, | ||
SourceText text, | ||
int position, | ||
DocumentOptionSet options, | ||
CancellationToken cancellationToken) | ||
{ | ||
var service = document.GetRequiredLanguageService<IDocumentationCommentSnippetService>(); | ||
return Translate(service.GetDocumentationCommentSnippetOnEnterTyped(syntaxTree, text, position, options, cancellationToken)); | ||
} | ||
|
||
public static OmniSharpDocumentationCommentSnippet? GetDocumentationCommentSnippetFromPreviousLine( | ||
Document document, | ||
DocumentOptionSet options, | ||
TextLine currentLine, | ||
TextLine previousLine) | ||
{ | ||
var service = document.GetRequiredLanguageService<IDocumentationCommentSnippetService>(); | ||
return Translate(service.GetDocumentationCommentSnippetFromPreviousLine(options, currentLine, previousLine)); | ||
} | ||
|
||
private static OmniSharpDocumentationCommentSnippet? Translate(DocumentationCommentSnippet? result) | ||
=> result == null ? null : new(result.SpanToReplace, result.SnippetText, result.CaretOffset); | ||
} | ||
|
||
internal sealed class OmniSharpDocumentationCommentSnippet | ||
{ | ||
/// <summary> | ||
/// The span in the original text that should be replaced with the documentation comment. | ||
/// </summary> | ||
public TextSpan SpanToReplace { get; } | ||
|
||
/// <summary> | ||
/// The documentation comment text to replace the span with | ||
/// </summary> | ||
public string SnippetText { get; } | ||
|
||
/// <summary> | ||
/// The offset within <see cref="SnippetText"/> where the caret should be positioned after replacement | ||
/// </summary> | ||
public int CaretOffset { get; } | ||
|
||
internal OmniSharpDocumentationCommentSnippet(TextSpan spanToReplace, string snippetText, int caretOffset) | ||
{ | ||
SpanToReplace = spanToReplace; | ||
SnippetText = snippetText; | ||
CaretOffset = caretOffset; | ||
} | ||
} | ||
} |
Oops, something went wrong.