提交 413b6b66 编写于 作者: D David Barbet

Address review feedback.

上级 23eb3421
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.DocumentHighlighting;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Tags;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Roslyn.Utilities;
......@@ -14,6 +16,47 @@ namespace Microsoft.CodeAnalysis.LanguageServer
{
internal static class ProtocolConversions
{
public static readonly Dictionary<string, LSP.CompletionItemKind> RoslynTagToCompletionItemKind = new Dictionary<string, LSP.CompletionItemKind>()
{
{ WellKnownTags.Public, LSP.CompletionItemKind.Keyword },
{ WellKnownTags.Protected, LSP.CompletionItemKind.Keyword },
{ WellKnownTags.Private, LSP.CompletionItemKind.Keyword },
{ WellKnownTags.Internal, LSP.CompletionItemKind.Keyword },
{ WellKnownTags.File, LSP.CompletionItemKind.File },
{ WellKnownTags.Project, LSP.CompletionItemKind.File },
{ WellKnownTags.Folder, LSP.CompletionItemKind.Folder },
{ WellKnownTags.Assembly, LSP.CompletionItemKind.File },
{ WellKnownTags.Class, LSP.CompletionItemKind.Class },
{ WellKnownTags.Constant, LSP.CompletionItemKind.Constant },
{ WellKnownTags.Delegate, LSP.CompletionItemKind.Function },
{ WellKnownTags.Enum, LSP.CompletionItemKind.Enum },
{ WellKnownTags.EnumMember, LSP.CompletionItemKind.EnumMember },
{ WellKnownTags.Event, LSP.CompletionItemKind.Event },
{ WellKnownTags.ExtensionMethod, LSP.CompletionItemKind.Method },
{ WellKnownTags.Field, LSP.CompletionItemKind.Field },
{ WellKnownTags.Interface, LSP.CompletionItemKind.Interface },
{ WellKnownTags.Intrinsic, LSP.CompletionItemKind.Text },
{ WellKnownTags.Keyword, LSP.CompletionItemKind.Keyword },
{ WellKnownTags.Label, LSP.CompletionItemKind.Text },
{ WellKnownTags.Local, LSP.CompletionItemKind.Variable },
{ WellKnownTags.Namespace, LSP.CompletionItemKind.Text },
{ WellKnownTags.Method, LSP.CompletionItemKind.Method },
{ WellKnownTags.Module, LSP.CompletionItemKind.Module },
{ WellKnownTags.Operator, LSP.CompletionItemKind.Operator },
{ WellKnownTags.Parameter, LSP.CompletionItemKind.Value },
{ WellKnownTags.Property, LSP.CompletionItemKind.Property },
{ WellKnownTags.RangeVariable, LSP.CompletionItemKind.Variable },
{ WellKnownTags.Reference, LSP.CompletionItemKind.Reference },
{ WellKnownTags.Structure, LSP.CompletionItemKind.Struct },
{ WellKnownTags.TypeParameter, LSP.CompletionItemKind.TypeParameter },
{ WellKnownTags.Snippet, LSP.CompletionItemKind.Snippet },
{ WellKnownTags.Error, LSP.CompletionItemKind.Text },
{ WellKnownTags.Warning, LSP.CompletionItemKind.Text },
{ WellKnownTags.StatusInformation, LSP.CompletionItemKind.Text },
{ WellKnownTags.AddReference, LSP.CompletionItemKind.Text },
{ WellKnownTags.NuGet, LSP.CompletionItemKind.Text }
};
public static LinePosition PositionToLinePosition(LSP.Position position)
{
return new LinePosition(position.Line, position.Character);
......
......@@ -8,7 +8,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Tags;
using Microsoft.VisualStudio.Text.Adornments;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -60,21 +59,9 @@ private static LSP.CompletionItemKind GetCompletionKind(ImmutableArray<string> t
{
foreach (var tag in tags)
{
if (Enum.TryParse<LSP.CompletionItemKind>(tag, out var kind))
if (ProtocolConversions.RoslynTagToCompletionItemKind.TryGetValue(tag, out var completionItemKind))
{
return kind;
}
else if (tag == WellKnownTags.Local || tag == WellKnownTags.Parameter)
{
return LSP.CompletionItemKind.Variable;
}
else if (tag == WellKnownTags.Structure)
{
return LSP.CompletionItemKind.Struct;
}
else if (tag == WellKnownTags.Delegate)
{
return LSP.CompletionItemKind.Function;
return completionItemKind;
}
}
......
......@@ -9,8 +9,7 @@
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
[Shared]
// TODO - Use method name from VS language server package once updated.
[ExportLspMethod("textDocument/typeDefinition")]
[ExportLspMethod(LSP.Methods.TextDocumentTypeDefinitionName)]
internal class GoToTypeDefinitionHandler : GoToDefinitionHandlerBase, IRequestHandler<LSP.TextDocumentPositionParams, LSP.Location[]>
{
[ImportingConstructor]
......
......@@ -10,8 +10,7 @@
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
[Shared]
// TODO - Use method name from VS language server package once updated.
[ExportLspMethod("textDocument/foldingRange")]
[ExportLspMethod(Methods.TextDocumentFoldingRangeName)]
internal class FoldingRangesHandler : IRequestHandler<FoldingRangeParams, FoldingRange[]>
{
public async Task<FoldingRange[]> HandleRequestAsync(Solution solution, FoldingRangeParams request,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
[Shared]
[ExportLspMethod(Methods.TextDocumentFormattingName)]
internal class FormatDocumentHandler : IRequestHandler<DocumentFormattingParams, TextEdit[]>
[ExportLspMethod(LSP.Methods.TextDocumentFormattingName)]
internal class FormatDocumentHandler : FormatDocumentHandlerBase, IRequestHandler<LSP.DocumentFormattingParams, LSP.TextEdit[]>
{
public async Task<TextEdit[]> HandleRequestAsync(Solution solution, DocumentFormattingParams request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
public async Task<LSP.TextEdit[]> HandleRequestAsync(Solution solution, LSP.DocumentFormattingParams request, LSP.ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
{
var edits = new List<TextEdit>();
var document = solution.GetDocumentFromURI(request.TextDocument.Uri);
if (document != null)
{
var formattingService = document.Project.LanguageServices.GetService<IEditorFormattingService>();
var textChanges = await formattingService.GetFormattingChangesAsync(document, null, cancellationToken).ConfigureAwait(false);
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
edits.AddRange(textChanges.Select(change => ProtocolConversions.TextChangeToTextEdit(change, text)));
}
return edits.ToArray();
return await GetTextEdits(solution, request.TextDocument.Uri, cancellationToken).ConfigureAwait(false);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
internal class FormatDocumentHandlerBase
{
protected async Task<LSP.TextEdit[]> GetTextEdits(Solution solution, Uri documentUri, CancellationToken cancellationToken, LSP.Range range = null)
{
var edits = new ArrayBuilder<LSP.TextEdit>();
var document = solution.GetDocumentFromURI(documentUri);
if (document != null)
{
var formattingService = document.Project.LanguageServices.GetService<IEditorFormattingService>();
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
TextSpan? textSpan = null;
if (range != null)
{
textSpan = ProtocolConversions.RangeToTextSpan(range, text);
}
var textChanges = await formattingService.GetFormattingChangesAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
edits.AddRange(textChanges.Select(change => ProtocolConversions.TextChangeToTextEdit(change, text)));
}
return edits.ToArrayAndFree();
}
}
}
......@@ -5,7 +5,9 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -17,16 +19,21 @@ internal class FormatDocumentOnTypeHandler : IRequestHandler<DocumentOnTypeForma
{
public async Task<TextEdit[]> HandleRequestAsync(Solution solution, DocumentOnTypeFormattingParams request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
{
var edits = new List<TextEdit>();
var edits = new ArrayBuilder<TextEdit>();
var document = solution.GetDocumentFromURI(request.TextDocument.Uri);
if (document != null)
{
var formattingService = document.Project.LanguageServices.GetService<IEditorFormattingService>();
var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(request.Character))
{
return edits.ToArrayAndFree();
}
IList<TextChange> textChanges;
// Formatting on new lines must be handled differently.
if (request.Character == "\n")
if (SyntaxFacts.IsNewLine(request.Character[0]))
{
textChanges = await formattingService.GetFormattingChangesOnReturnAsync(document, position, cancellationToken).ConfigureAwait(false);
}
......@@ -42,7 +49,7 @@ public async Task<TextEdit[]> HandleRequestAsync(Solution solution, DocumentOnTy
}
}
return edits.ToArray();
return edits.ToArrayAndFree();
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
[Shared]
[ExportLspMethod(Methods.TextDocumentRangeFormattingName)]
internal class FormatDocumentRangeHandler : IRequestHandler<DocumentRangeFormattingParams, TextEdit[]>
internal class FormatDocumentRangeHandler : FormatDocumentHandlerBase, IRequestHandler<DocumentRangeFormattingParams, TextEdit[]>
{
public async Task<TextEdit[]> HandleRequestAsync(Solution solution, DocumentRangeFormattingParams request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
{
var edits = new List<TextEdit>();
var document = solution.GetDocumentFromURI(request.TextDocument.Uri);
if (document != null)
{
var formattingService = document.Project.LanguageServices.GetService<IEditorFormattingService>();
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var textSpan = ProtocolConversions.RangeToTextSpan(request.Range, text);
var textChanges = await formattingService.GetFormattingChangesAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
edits.AddRange(textChanges.Select(change => ProtocolConversions.TextChangeToTextEdit(change, text)));
}
return edits.ToArray();
return await GetTextEdits(solution, request.TextDocument.Uri, cancellationToken, range: request.Range).ConfigureAwait(false);
}
}
}
......@@ -9,11 +9,11 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
/// <summary>
/// Top level type for LSP request handler.
/// </summary>
interface IRequestHandler
internal interface IRequestHandler
{
}
interface IRequestHandler<RequestType, ResponseType> : IRequestHandler
internal interface IRequestHandler<RequestType, ResponseType> : IRequestHandler
{
Task<ResponseType> HandleRequestAsync(Solution solution, RequestType request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken);
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
interface IRequestHandlerMetadata
internal interface IRequestHandlerMetadata
{
/// <summary>
/// Name of the LSP method to handle.
......
......@@ -11,31 +11,29 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
[ExportLspMethod(Methods.InitializeName)]
internal class InitializeHandler : IRequestHandler<InitializeParams, InitializeResult>
{
public Task<InitializeResult> HandleRequestAsync(Solution solution, InitializeParams request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
private static readonly InitializeResult s_initializeResult = new InitializeResult
{
var result = new InitializeResult
Capabilities = new ServerCapabilities
{
Capabilities = new ServerCapabilities
{
DefinitionProvider = true,
ReferencesProvider = true,
ImplementationProvider = true,
CompletionProvider = new CompletionOptions { ResolveProvider = true, TriggerCharacters = new[] { "." } },
HoverProvider = true,
SignatureHelpProvider = new SignatureHelpOptions { TriggerCharacters = new[] { "(", "," } },
CodeActionProvider = true,
DocumentSymbolProvider = true,
WorkspaceSymbolProvider = true,
DocumentFormattingProvider = true,
DocumentRangeFormattingProvider = true,
DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions { FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" } },
DocumentHighlightProvider = true,
RenameProvider = true,
ExecuteCommandProvider = new ExecuteCommandOptions()
}
};
DefinitionProvider = true,
ReferencesProvider = true,
ImplementationProvider = true,
CompletionProvider = new CompletionOptions { ResolveProvider = true, TriggerCharacters = new[] { "." } },
HoverProvider = true,
SignatureHelpProvider = new SignatureHelpOptions { TriggerCharacters = new[] { "(", "," } },
CodeActionProvider = true,
DocumentSymbolProvider = true,
WorkspaceSymbolProvider = true,
DocumentFormattingProvider = true,
DocumentRangeFormattingProvider = true,
DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions { FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" } },
DocumentHighlightProvider = true,
RenameProvider = true,
ExecuteCommandProvider = new ExecuteCommandOptions()
}
};
return Task.FromResult(result);
}
public Task<InitializeResult> HandleRequestAsync(Solution solution, InitializeParams request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
=> Task.FromResult(s_initializeResult);
}
}
......@@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.VisualStudio.Text.Adornments;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -46,7 +47,7 @@ public SignatureHelpHandler([ImportMany] IEnumerable<Lazy<ISignatureHelpProvider
if (items != null)
{
var sigInfos = new List<LSP.SignatureInformation>();
var sigInfos = new ArrayBuilder<LSP.SignatureInformation>();
foreach (var item in items.Items)
{
......@@ -77,7 +78,7 @@ public SignatureHelpHandler([ImportMany] IEnumerable<Lazy<ISignatureHelpProvider
{
ActiveSignature = GetActiveSignature(items),
ActiveParameter = items.ArgumentIndex,
Signatures = sigInfos.ToArray()
Signatures = sigInfos.ToArrayAndFree()
};
return sigHelp;
......@@ -138,7 +139,7 @@ private string GetSignatureText(SignatureHelpItem item)
}
private ClassifiedTextElement GetSignatureClassifiedText(SignatureHelpItem item)
{
var taggedTexts = new List<TaggedText>();
var taggedTexts = new ArrayBuilder<TaggedText>();
taggedTexts.AddRange(item.PrefixDisplayParts);
......@@ -160,7 +161,7 @@ private ClassifiedTextElement GetSignatureClassifiedText(SignatureHelpItem item)
taggedTexts.AddRange(item.SuffixDisplayParts);
taggedTexts.AddRange(item.DescriptionParts);
return new ClassifiedTextElement(taggedTexts.Select(part => new ClassifiedTextRun(part.Tag.ToClassificationTypeName(), part.Text)));
return new ClassifiedTextElement(taggedTexts.ToArrayAndFree().Select(part => new ClassifiedTextRun(part.Tag.ToClassificationTypeName(), part.Text)));
}
}
}
......@@ -139,13 +139,13 @@ static SymbolInformation Create(NavigationBarItem item, TextSpan span, string co
static async Task<DocumentSymbol[]> GetChildrenAsync(IEnumerable<NavigationBarItem> items, Compilation compilation, SyntaxTree tree,
SourceText text, CancellationToken cancellationToken)
{
var list = new List<DocumentSymbol>();
var list = new ArrayBuilder<DocumentSymbol>();
foreach (var item in items)
{
list.Add(await GetDocumentSymbolAsync(item, compilation, tree, text, cancellationToken).ConfigureAwait(false));
}
return list.ToArray();
return list.ToArrayAndFree();
}
static async Task<ISymbol> GetSymbolAsync(Location location, Compilation compilation, CancellationToken cancellationToken)
......
......@@ -6,7 +6,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -28,7 +27,7 @@ public LanguageServerProtocol([ImportMany] IEnumerable<Lazy<IRequestHandler, IRe
_requestHandlers = CreateMethodToHandlerMap(requestHandlers);
}
private ImmutableDictionary<string, Lazy<IRequestHandler, IRequestHandlerMetadata>> CreateMethodToHandlerMap(IEnumerable<Lazy<IRequestHandler, IRequestHandlerMetadata>> requestHandlers)
private static ImmutableDictionary<string, Lazy<IRequestHandler, IRequestHandlerMetadata>> CreateMethodToHandlerMap(IEnumerable<Lazy<IRequestHandler, IRequestHandlerMetadata>> requestHandlers)
{
var requestHandlerDictionary = new Dictionary<string, Lazy<IRequestHandler, IRequestHandlerMetadata>>();
foreach (var lazyHandler in requestHandlers)
......@@ -256,19 +255,6 @@ public async Task<LSP.InitializeResult> InitializeAsync(Solution solution, LSP.I
.ConfigureAwait(false);
}
/// <summary>
/// Answers a preview code action request by returning the text edits for a specific code action.
/// </summary>
/// <param name="solution">the solution containing the document.</param>
/// <param name="request">the code action location and title to preview.</param>
/// <param name="cancellationToken">a cancellation token.</param>
/// <returns>a list of text edits for the code action result.</returns>
public async Task<LSP.TextEdit[]> PreviewCodeActionsAsync(Solution solution, RunCodeActionParams request, LSP.ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
{
return await ExecuteRequestAsync<RunCodeActionParams, LSP.TextEdit[]>(RoslynMethods.CodeActionPreviewName, solution, request, clientCapabilities, cancellationToken)
.ConfigureAwait(false);
}
/// <summary>
/// Answers a request to resolve a completion item.
/// https://microsoft.github.io/language-server-protocol/specification#completionItem_resolve
......
......@@ -14,6 +14,7 @@
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\..\EditorFeatures\Core\Microsoft.CodeAnalysis.EditorFeatures.csproj" />
</ItemGroup>
......
......@@ -4,11 +4,9 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
......@@ -220,16 +218,6 @@ protected static LSP.VSCompletionItem CreateCompletionItem(string text, LSP.Comp
Icon = tags != null ? new ImageElement(tags.ToImmutableArray().GetFirstGlyph().GetImageId()) : null
};
// Private procted because RunCodeActionParams is internal.
private protected static RunCodeActionParams CreateRunCodeActionParams(LSP.Location location, string title)
=> new RunCodeActionParams()
{
Range = location.Range,
TextDocument = CreateTextDocumentIdentifier(location.Uri),
Title = title
};
/// <summary>
/// Creates a solution with a document.
/// </summary>
......
......@@ -83,7 +83,12 @@ private static LSP.Command CreateCommand(string title, LSP.Location location)
CommandIdentifier = "Roslyn.RunCodeAction",
Arguments = new object[]
{
CreateRunCodeActionParams(location, title)
new RunCodeActionParams()
{
Range = location.Range,
TextDocument = CreateTextDocumentIdentifier(location.Uri),
Title = title
}
}
}
}
......
......@@ -78,7 +78,6 @@
<ProjectReference Include="..\..\..\EditorFeatures\Text\Microsoft.CodeAnalysis.EditorFeatures.Text.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" />
<ProjectReference Include="..\..\..\Features\LanguageServer\Protocol\Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj" />
<ProjectReference Include="..\..\..\Interactive\Host\Microsoft.CodeAnalysis.InteractiveHost.csproj" PrivateAssets="all" Aliases="InteractiveHost" />
</ItemGroup>
<ItemGroup Label="File References">
......
......@@ -70,19 +70,11 @@
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
</ItemGroup>
<ItemGroup>
<Compile Update="Options\AbstractOptionPage.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Options\AbstractOptionPageControl.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Options\GridOptionPreviewControl.xaml.cs">
<DependentUpon>GridOptionPreviewControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Options\OptionPreviewControl.xaml.cs">
<DependentUpon>OptionPreviewControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Options\Style\NamingPreferences\ManageNamingStylesInfoDialog.xaml.cs">
<DependentUpon>ManageNamingStylesInfoDialog.xaml</DependentUpon>
......@@ -92,7 +84,6 @@
</Compile>
<Compile Update="Options\Style\NamingPreferences\NamingStyleOptionPageControl.xaml.cs">
<DependentUpon>NamingStyleOptionPageControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Options\Style\NamingPreferences\SymbolSpecification\SymbolSpecificationDialog.xaml.cs">
<DependentUpon>SymbolSpecificationDialog.xaml</DependentUpon>
......
......@@ -86,7 +86,7 @@ private async Task<LSP.ReferenceGroup[]> GetReferenceGroupsAsync(LSP.ReferencePa
referenceGroup.Definition = await ProtocolConversions.DocumentSpanToLocationWithTextAsync(definition.SourceSpans.First(), text, cancellationToken).ConfigureAwait(false);
referenceGroup.DefinitionIcon = new ImageElement(definition.Tags.GetFirstGlyph().GetImageId());
var locationWithTexts = new List<LSP.LocationWithText>();
var locationWithTexts = new ArrayBuilder<LSP.LocationWithText>();
foreach (var reference in references)
{
var classifiedSpansAndHighlightSpan = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync(reference.SourceSpan, context.CancellationToken).ConfigureAwait(false);
......@@ -98,7 +98,7 @@ private async Task<LSP.ReferenceGroup[]> GetReferenceGroupsAsync(LSP.ReferencePa
locationWithTexts.Add(locationWithText);
}
referenceGroup.References = locationWithTexts.ToArray();
referenceGroup.References = locationWithTexts.ToArrayAndFree();
referenceGroups.Add(referenceGroup);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
namespace Microsoft.VisualStudio.LanguageServices.LiveShare
{
[Shared]
[ExportLspMethod(RoslynMethods.CodeActionPreviewName)]
internal class PreviewCodeActionsHandler : CodeActionsHandlerBase, IRequestHandler<RunCodeActionParams, LSP.TextEdit[]>
[ExportLspRequestHandler(LiveShareConstants.RoslynContractName, RoslynMethods.CodeActionPreviewName)]
internal class PreviewCodeActionsHandler : CodeActionsHandlerBase, ILspRequestHandler<RunCodeActionParams, LSP.TextEdit[], Solution>
{
[ImportingConstructor]
public PreviewCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
......@@ -23,11 +26,10 @@ public PreviewCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactorin
{
}
public async Task<LSP.TextEdit[]> HandleRequestAsync(Solution solution, RunCodeActionParams request,
LSP.ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
public async Task<LSP.TextEdit[]> HandleAsync(RunCodeActionParams request, RequestContext<Solution> requestContext, CancellationToken cancellationToken)
{
var edits = ArrayBuilder<LSP.TextEdit>.GetInstance();
var solution = requestContext.Context;
var codeActions = await GetCodeActionsAsync(solution,
request.TextDocument.Uri,
request.Range,
......
......@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
namespace Microsoft.VisualStudio.LanguageServices.LiveShare
......@@ -19,11 +20,11 @@ internal class ProjectsHandler : ILspRequestHandler<object, CustomProtocol.Proje
{
public async Task<CustomProtocol.Project[]> HandleAsync(object param, RequestContext<Solution> requestContext, CancellationToken cancellationToken)
{
var projects = new List<CustomProtocol.Project>();
var projects = new ArrayBuilder<CustomProtocol.Project>();
var solution = requestContext.Context;
foreach (var project in solution.Projects)
{
var externalUris = new List<Uri>();
var externalUris = new ArrayBuilder<Uri>();
foreach (var sourceFile in project.Documents)
{
var uri = new Uri(sourceFile.FilePath);
......@@ -32,7 +33,7 @@ public async Task<CustomProtocol.Project[]> HandleAsync(object param, RequestCon
externalUris.Add(uri);
}
}
await requestContext.ProtocolConverter.RegisterExternalFilesAsync(externalUris.ToArray()).ConfigureAwait(false);
await requestContext.ProtocolConverter.RegisterExternalFilesAsync(externalUris.ToArrayAndFree()).ConfigureAwait(false);
var lspProject = new CustomProtocol.Project
{
......@@ -44,7 +45,7 @@ public async Task<CustomProtocol.Project[]> HandleAsync(object param, RequestCon
projects.Add(lspProject);
}
return projects.ToArray();
return projects.ToArrayAndFree();
}
}
}
......@@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
......@@ -55,7 +56,7 @@ public async Task<WorkspaceEdit> HandleAsync(RenameParams request, RequestContex
.GetProjectChanges()
.SelectMany(p => p.GetChangedDocuments());
var documentEdits = new List<TextDocumentEdit>();
var documentEdits = new ArrayBuilder<TextDocumentEdit>();
foreach (var docId in changedDocuments)
{
var oldDoc = solution.GetDocument(docId);
......@@ -71,7 +72,7 @@ public async Task<WorkspaceEdit> HandleAsync(RenameParams request, RequestContex
documentEdits.Add(textDocumentEdit);
}
workspaceEdit = new WorkspaceEdit { DocumentChanges = documentEdits.ToArray() };
workspaceEdit = new WorkspaceEdit { DocumentChanges = documentEdits.ToArrayAndFree() };
}
return workspaceEdit;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
namespace Microsoft.VisualStudio.LanguageServices.LiveShare
{
[ExportLspRequestHandler(LiveShareConstants.RoslynContractName, RoslynMethods.CodeActionPreviewName)]
internal class PreviewCodeActionsHandlerShim : AbstractLiveShareHandlerShim<RunCodeActionParams, TextEdit[]>
{
[ImportingConstructor]
public PreviewCodeActionsHandlerShim([ImportMany] IEnumerable<Lazy<IRequestHandler, IRequestHandlerMetadata>> requestHandlers) : base(requestHandlers, RoslynMethods.CodeActionPreviewName)
{
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Common;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.VisualStudio.LanguageServices.LiveShare.CustomProtocol;
using Xunit;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -18,7 +12,7 @@ namespace Microsoft.VisualStudio.LanguageServices.LiveShare.UnitTests
{
public class DiagnosticsHandlerTests : AbstractLiveShareRequestHandlerTests
{
[Fact]
[Fact(Skip = "Need easy way to export analyzers for testing.")]
public async Task TestDiagnosticsAsync()
{
var markup =
......@@ -31,23 +25,10 @@ void M()
}";
var (solution, ranges) = CreateTestSolution(markup);
var workspace = (TestWorkspace)solution.Workspace;
var diagnosticService = (DiagnosticService)workspace.ExportProvider.GetExportedValue<IDiagnosticService>();
var miscService = new DefaultDiagnosticAnalyzerService(new TestDiagnosticAnalyzerService(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()), diagnosticService);
DiagnosticProvider.Enable(workspace, DiagnosticProvider.Options.Syntax);
var document = solution.Projects.First().Documents.First();
var analyzer = miscService.CreateIncrementalAnalyzer(workspace);
await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None);
await analyzer.AnalyzeDocumentAsync(document, null, InvocationReasons.Empty, CancellationToken.None);
var diagnosticLocation = ranges["diagnostic"].First();
var results = await TestHandleAsync<TextDocumentParams, LSP.Diagnostic[]>(solution, CreateTestDocumentParams(diagnosticLocation.Uri));
var i = 1;
//AssertCollectionsEqual(new ClassificationSpan[] { CreateClassificationSpan("keyword", classifyLocation.Range) }, results, AssertClassificationsEqual);
var _ = await TestHandleAsync<TextDocumentParams, LSP.Diagnostic[]>(solution, CreateTestDocumentParams(diagnosticLocation.Uri));
}
private static TextDocumentParams CreateTestDocumentParams(Uri uri)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Xunit;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests.CodeActions
namespace Microsoft.VisualStudio.LanguageServices.LiveShare.UnitTests
{
public class PreviewCodeActionsTests : AbstractLanguageServerProtocolTests
public class PreviewCodeActionsTests : AbstractLiveShareRequestHandlerTests
{
[Fact]
public async Task TestPreviewCodeActionsAsync()
......@@ -24,12 +24,17 @@ void M()
var (solution, locations) = CreateTestSolution(markup);
var expected = CreateTextEdit("var", locations["edit"].First().Range);
var results = await RunPreviewCodeActionsAsync(solution, locations["caret"].First(), "Use implicit type");
var results = await TestHandleAsync<RunCodeActionParams, LSP.TextEdit[]>(solution, CreateRunCodeActionParams(locations["caret"].First(), "Use implicit type"));
AssertCollectionsEqual(new LSP.TextEdit[] { expected }, results, AssertTextEditsEqual);
}
private static async Task<LSP.TextEdit[]> RunPreviewCodeActionsAsync(Solution solution, LSP.Location caret, string title)
=> await GetLanguageServer(solution).PreviewCodeActionsAsync(solution, CreateRunCodeActionParams(caret, title), new LSP.ClientCapabilities(), CancellationToken.None);
private static RunCodeActionParams CreateRunCodeActionParams(LSP.Location location, string title)
=> new RunCodeActionParams()
{
Range = location.Range,
TextDocument = CreateTextDocumentIdentifier(location.Uri),
Title = title
};
private static LSP.TextEdit CreateTextEdit(string text, LSP.Range range)
=> new LSP.TextEdit()
......
......@@ -29,6 +29,7 @@
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.Implementation.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.VisualBasic.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.CSharp.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.LiveShare.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.SolutionExplorer.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.Xaml.dll")]
[assembly: ProvideRoslynBindingRedirection("Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient.dll")]
......
......@@ -114,6 +114,11 @@
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;SatelliteDllsProjectOutputGroup</IncludeOutputGroupsInVSIX>
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
</ProjectReference>
<ProjectReference Include="..\..\VisualStudio\LiveShare\Impl\Microsoft.VisualStudio.LanguageServices.LiveShare.csproj">
<Name>LiveShareLanguageServices</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;SatelliteDllsProjectOutputGroup</IncludeOutputGroupsInVSIX>
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
</ProjectReference>
<ProjectReference Include="..\..\EditorFeatures\Text\Microsoft.CodeAnalysis.EditorFeatures.Text.csproj">
<Name>TextEditorFeatures</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;SatelliteDllsProjectOutputGroup</IncludeOutputGroupsInVSIX>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册