Skip to content

Commit

Permalink
Merge branch 'master' into completion-on-part-of-typed-text
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Sep 18, 2020
2 parents 252f79a + 608e77e commit 6c2a86f
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All changes to the project will be documented in this file.

## [1.37.2] - Not Yet Released
* Add support for new quick info endpoint when working with Cake (PR: [#1945](https://github.com/OmniSharp/omnisharp-roslyn/pull/1945))
* Add support for new completion endpoints when working with Cake ([#1939](https://github.com/OmniSharp/omnisharp-roslyn/issues/1939), PR: [#1944](https://github.com/OmniSharp/omnisharp-roslyn/pull/1944))

## [1.37.1] - 2020-09-01
* Ensure that all quickinfo sections have linebreaks between them, and don't add unecessary duplicate linebreaks (PR: [#1900](https://github.com/OmniSharp/omnisharp-roslyn/pull/1900))
* Support completion of unimported types (PR: [#1896](https://github.com/OmniSharp/omnisharp-roslyn/pull/1896))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For more details, see [Build](https://github.com/OmniSharp/omnisharp-roslyn/blob

### VS Code

Add the following setting to your [User Settings or Workspace Settings](https://code.visualstudio.com/Docs/customization/userandworkspace).
Add the following setting to your [User Settings](https://code.visualstudio.com/Docs/customization/userandworkspace).

```JSON
{
Expand All @@ -77,7 +77,7 @@ The above option can also be set to:
- "latest" - To consume the latest build from the master branch
- A specific version number like `1.29.2-beta.60`

In order to be able to attach a debugger, add the following setting:
In order to be able to attach a debugger, add the following setting to your [User or Workspace settings](https://code.visualstudio.com/Docs/customization/userandworkspace):

```JSON
{
Expand Down
65 changes: 49 additions & 16 deletions src/OmniSharp.Cake/Extensions/ResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OmniSharp.Models.Navigate;
using OmniSharp.Models.MembersTree;
using OmniSharp.Models.Rename;
using OmniSharp.Models.v1.Completion;
using OmniSharp.Models.V2;
using OmniSharp.Models.V2.CodeActions;
using OmniSharp.Models.V2.CodeStructure;
Expand All @@ -27,22 +28,6 @@ public static QuickFixResponse OnlyThisFile(this QuickFixResponse response, stri
var quickFixes = response.QuickFixes.Where(x => PathsAreEqual(x.FileName, fileName));
response.QuickFixes = quickFixes;
return response;

bool PathsAreEqual(string x, string y)
{
if (x == null && y == null)
{
return true;
}
if (x == null || y == null)
{
return false;
}

var comparer = PlatformHelper.IsWindows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

return Path.GetFullPath(x).Equals(Path.GetFullPath(y), comparer);
}
}

public static Task<QuickFixResponse> TranslateAsync(this QuickFixResponse response, OmniSharpWorkspace workspace)
Expand Down Expand Up @@ -211,6 +196,38 @@ public static async Task<BlockStructureResponse> TranslateAsync(this BlockStruct
return response;
}

public static async Task<CompletionResponse> TranslateAsync(this CompletionResponse response, OmniSharpWorkspace workspace, CompletionRequest request)
{
foreach (var item in response.Items)
{
if (item.AdditionalTextEdits is null)
{
continue;
}

List<LinePositionSpanTextChange> additionalTextEdits = null;

foreach (var additionalTextEdit in item.AdditionalTextEdits)
{
var (_, change) = await additionalTextEdit.TranslateAsync(workspace, request.FileName);

// Due to the fact that AdditionalTextEdits return the complete buffer, we can't currently use that in Cake.
// Revisit when we have a solution. At this point it's probably just best to remove AdditionalTextEdits.
if (change.StartLine < 0)
{
continue;
}

additionalTextEdits ??= new List<LinePositionSpanTextChange>();
additionalTextEdits.Add(change);
}

item.AdditionalTextEdits = additionalTextEdits;
}

return response;
}

private static async Task<CodeElement> TranslateAsync(this CodeElement element, OmniSharpWorkspace workspace, SimpleFileRequest request)
{
var builder = new CodeElement.Builder
Expand Down Expand Up @@ -345,5 +362,21 @@ private static async Task PopulateModificationsAsync(

return (newFileName, change);
}

private static bool PathsAreEqual(string x, string y)
{
if (x == null && y == null)
{
return true;
}
if (x == null || y == null)
{
return false;
}

var comparer = PlatformHelper.IsWindows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

return Path.GetFullPath(x).Equals(Path.GetFullPath(y), comparer);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Cake.Extensions;
using OmniSharp.Mef;
using OmniSharp.Models.v1.Completion;

namespace OmniSharp.Cake.Services.RequestHandlers.Completion
{
[Shared]
[OmniSharpHandler(OmniSharpEndpoints.Completion, Constants.LanguageNames.Cake)]
public class CompletionHandler : CakeRequestHandler<CompletionRequest, CompletionResponse>
{
[ImportingConstructor]
public CompletionHandler(OmniSharpWorkspace workspace) : base(workspace)
{
}

protected override Task<CompletionResponse> TranslateResponse(CompletionResponse response, CompletionRequest request)
{
return response.TranslateAsync(Workspace, request);
}
}

[Shared]
[OmniSharpHandler(OmniSharpEndpoints.CompletionResolve, Constants.LanguageNames.Cake)]
public class CompletionResolveHandler : CakeRequestHandler<CompletionResolveRequest, CompletionResolveResponse>
{
[ImportingConstructor]
public CompletionResolveHandler(OmniSharpWorkspace workspace) : base(workspace)
{
}

protected override Task<CompletionResolveResponse> TranslateResponse(CompletionResolveResponse response, CompletionResolveRequest request)
{
// Due to the fact that AdditionalTextEdits return the complete buffer, we can't currently use that in Cake.
// Revisit when we have a solution. At this point it's probably just best to remove AdditionalTextEdits.
if (response.Item is object)
{
response.Item.AdditionalTextEdits = null;
}

return Task.FromResult(response);
}
}
}
16 changes: 16 additions & 0 deletions src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Composition;
using OmniSharp.Mef;
using OmniSharp.Models;

namespace OmniSharp.Cake.Services.RequestHandlers
{
[Shared]
[OmniSharpHandler(OmniSharpEndpoints.QuickInfo, Constants.LanguageNames.Cake)]
public class QuickInfoHandler : CakeRequestHandler<QuickInfoRequest, QuickInfoResponse>
{
[ImportingConstructor]
public QuickInfoHandler(OmniSharpWorkspace workspace) : base(workspace)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
private static readonly IDictionary<string, CompletionItemKind> _kind = new Dictionary<string, CompletionItemKind>{
// types
{ "Class", CompletionItemKind.Class },
{ "Delegate", CompletionItemKind.Class }, // need a better option for this.
{ "Delegate", CompletionItemKind.Function },
{ "Enum", CompletionItemKind.Enum },
{ "Interface", CompletionItemKind.Interface },
{ "Struct", CompletionItemKind.Class }, // TODO: Is struct missing from enum?
{ "Struct", CompletionItemKind.Struct },

// variables
{ "Local", CompletionItemKind.Variable },
{ "Parameter", CompletionItemKind.Variable },
{ "RangeVariable", CompletionItemKind.Variable },

// members
{ "Const", CompletionItemKind.Value }, // TODO: Is const missing from enum?
{ "Const", CompletionItemKind.Constant },
{ "EnumMember", CompletionItemKind.Enum },
{ "Event", CompletionItemKind.Function }, // TODO: Is event missing from enum?
{ "Event", CompletionItemKind.Event },
{ "Field", CompletionItemKind.Field },
{ "Method", CompletionItemKind.Method },
{ "Property", CompletionItemKind.Property },

// other stuff
{ "Label", CompletionItemKind.Unit }, // need a better option for this.
{ "Label", CompletionItemKind.Text },
{ "Keyword", CompletionItemKind.Keyword },
{ "Namespace", CompletionItemKind.Module }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public override async Task<RunCodeActionResponse> Handle(RunCodeActionRequest re
changes.AddRange(fileChangesResult.FileChanges);
solution = fileChangesResult.Solution;
}
else
{
o.Apply(this.Workspace, CancellationToken.None);
solution = this.Workspace.CurrentSolution;
}

if (request.WantsAllCodeActionOperations)
{
Expand Down
Loading

0 comments on commit 6c2a86f

Please sign in to comment.