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