Skip to content

Commit

Permalink
Merge pull request #247 from OmniSharp/magicv2
Browse files Browse the repository at this point in the history
created a v2 version of code actions
  • Loading branch information
Mathew McLoughlin committed Jun 23, 2015
2 parents c32cd12 + a05e6f3 commit 2439ca8
Show file tree
Hide file tree
Showing 100 changed files with 982 additions and 113 deletions.
3 changes: 2 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<clear />
<add key="OmniSharp" value="https://www.myget.org/F/omnisharp/api/v2" />
<add key="AspNetMaster" value="https://www.myget.org/F/aspnetmaster/api/v2" />
<add key="AspNetRelease" value="https://www.myget.org/F/aspnetrelease/api/v2" />
<add key="XunitMyGet" value="https://www.myget.org/F/xunit/api/v2" />
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp/Api/OmnisharpController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public OmnisharpController(OmnisharpWorkspace workspace, IOptions<OmniSharpOptio
_options = optionsAccessor != null ? optionsAccessor.Options : new OmniSharpOptions();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public async Task<ObjectResult> ChangeBuffer(ChangeBufferRequest request)
return new ObjectResult(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task GetContextualCodeActions(CodeRefactoringContext? context)
{
foreach (var provider in _codeActionProviders)
{
var providers = provider.GetProviders();
var providers = provider.Refactorings;

foreach (var codeActionProvider in providers)
{
Expand Down
12 changes: 12 additions & 0 deletions src/OmniSharp/Api/v2/Refactoring/CodeActionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.CodeAnalysis.CodeActions;

namespace OmniSharp.Api.V2
{
public static class CodeActionExtensions
{
public static string GetIdentifier(this CodeAction codeAction)
{
return codeAction.EquivalenceKey ?? codeAction.Title;
}
}
}
330 changes: 330 additions & 0 deletions src/OmniSharp/Api/v2/Refactoring/OmnisharpController.CodeActions.cs

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions src/OmniSharp/Models/Request.cs
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
using System.IO;

namespace OmniSharp.Models
{
public class Request
{
private string _fileName;

public int Line { get; set; }
public int Column { get; set; }
public string Buffer { get; set; }
public string FileName
{
get
{
return _fileName?.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
set
{
_fileName = value;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public DnxProject(Project project)
SourceFiles = project.SourceFiles;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public DnxWorkspaceInformation(DnxContext context)
public int DesignTimeHostPort { get; }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public string WordToComplete
public bool WantSnippet { get; set; }

/// <summary>
/// Returns the return type
/// Returns the return type
/// </summary>
public bool WantReturnType { get; set; }

Expand All @@ -48,4 +48,4 @@ public string WordToComplete
/// </summary>
public bool WantKind { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public class ChangeBufferRequest
public int EndColumn { get; set; }
public string NewText { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public class CodeActionRequest : Request
public int? SelectionEndColumn { get; set; }
public int? SelectionEndLine { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class CodeFormatResponse
{
public string Buffer { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public class DiagnosticLocation : QuickFix
{
public string LogLevel { get; set; }
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ public override int GetHashCode()
31 * Location.EndColumn;
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public class FindSymbolsRequest
{
public string Filter { get; set; }
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class FormatAfterKeystrokeRequest : Request

public char Char { get { return string.IsNullOrEmpty(Character) ? (char)0 : Character[0]; } }
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class GetCodeActionsResponse
{
public IEnumerable<string> CodeActions { get; set; }
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public ModifiedFileResponse(string fileName)
public string Buffer { get; set; }
public IEnumerable<LinePositionSpanTextChange> Changes { get; set; }
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions src/OmniSharp/Models/v1/Request.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;

namespace OmniSharp.Models
{
public class Request
{
private string _fileName;

public int Line { get; set; }
public int Column { get; set; }
public string Buffer { get; set; }
public string FileName
{
get
{
return _fileName?.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
set
{
_fileName = value;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class RunCodeActionResponse
public string Text { get; set; }
public IEnumerable<LinePositionSpanTextChange> Changes { get; set; }
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions src/OmniSharp/Models/v2/CodeAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace OmniSharp.Models.V2
{
public class OmniSharpCodeAction
{
public OmniSharpCodeAction(string identifier, string name)
{
Identifier = identifier;
Name = name;
}

public string Identifier { get; }
public string Name { get; }
}
}
7 changes: 7 additions & 0 deletions src/OmniSharp/Models/v2/GetCodeActionsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OmniSharp.Models.V2
{
public class GetCodeActionsRequest : Request, ICodeActionRequest
{
public Range Selection { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp/Models/v2/GetCodeActionsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace OmniSharp.Models.V2
{
public class GetCodeActionsResponse
{
public IEnumerable<OmniSharpCodeAction> CodeActions { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp/Models/v2/ICodeActionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OmniSharp.Models.V2
{
public interface ICodeActionRequest
{
int Line { get; }
int Column { get; }
string Buffer { get; }
string FileName { get; }
Range Selection { get; }
}
}
8 changes: 8 additions & 0 deletions src/OmniSharp/Models/v2/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OmniSharp.Models.V2
{
public class Point
{
public int Line { get; set; }
public int Column { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/OmniSharp/Models/v2/Range.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OmniSharp.Models.V2
{
public class Range
{
public Point Start { get; set; }
public Point End { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp/Models/v2/RunCodeActionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OmniSharp.Models.V2
{
public class RunCodeActionRequest : Request, ICodeActionRequest
{
public string Identifier { get; set; }
public Range Selection { get; set; }
public bool WantsTextChanges { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp/Models/v2/RunCodeActionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace OmniSharp.Models.V2
{
public class RunCodeActionResponse
{
public IEnumerable<ModifiedFileResponse> Changes { get; set; }
}
}
11 changes: 7 additions & 4 deletions src/OmniSharp/Roslyn/OmniSharpWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Models;
using OmniSharp.Roslyn;

namespace OmniSharp
Expand All @@ -14,7 +13,11 @@ public class OmnisharpWorkspace : Workspace

public BufferManager BufferManager { get; private set; }

public OmnisharpWorkspace() : base(MefHostServices.DefaultHost, "Custom")
public OmnisharpWorkspace() : this(MefHostServices.DefaultHost)
{
}

public OmnisharpWorkspace(MefHostServices hostServices) : base(hostServices, "Custom")
{
BufferManager = new BufferManager(this);
}
Expand Down Expand Up @@ -79,7 +82,7 @@ public DocumentId GetDocumentId(string filePath)
var documentIds = CurrentSolution.GetDocumentIdsWithFilePath(filePath);
return documentIds.FirstOrDefault();
}

public IEnumerable<Document> GetDocuments(string filePath)
{
return CurrentSolution.GetDocumentIdsWithFilePath(filePath).Select(id => CurrentSolution.GetDocument(id));
Expand All @@ -88,7 +91,7 @@ public IEnumerable<Document> GetDocuments(string filePath)
public Document GetDocument(string filePath)
{
var documentId = GetDocumentId(filePath);
if(documentId == null)
if (documentId == null)
{
return null;
}
Expand Down
43 changes: 43 additions & 0 deletions src/OmniSharp/Services/AbstractCodeActionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#if DNX451
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;

namespace OmniSharp.Services
{
public abstract class AbstractCodeActionProvider : ICodeActionProvider
{
private readonly IEnumerable<CodeRefactoringProvider> _refactorings;
private readonly IEnumerable<CodeFixProvider> _codeFixes;

protected AbstractCodeActionProvider(string assemblyName) : this(Assembly.Load(assemblyName))
{
}

protected AbstractCodeActionProvider(Assembly codeActionAssembly)
{
var features = codeActionAssembly
.GetTypes()
.Where(type => !type.IsInterface
&& !type.IsAbstract
&& !type.ContainsGenericParameters); // TODO: handle providers with generic params

_refactorings = features.Where(t => typeof(CodeRefactoringProvider).IsAssignableFrom(t))
.Select(type => (CodeRefactoringProvider)Activator.CreateInstance(type));

_codeFixes = features.Where(t => typeof(CodeFixProvider).IsAssignableFrom(t))
.Select(type => (CodeFixProvider)Activator.CreateInstance(type));
}

public virtual IEnumerable<CodeRefactoringProvider> Refactorings => _refactorings;

public virtual IEnumerable<CodeFixProvider> CodeFixes => _codeFixes;

public abstract string ProviderName { get; }
}
}
#endif
13 changes: 0 additions & 13 deletions src/OmniSharp/Services/EmptyCodeActionProvider.cs

This file was deleted.

6 changes: 4 additions & 2 deletions src/OmniSharp/Services/ICodeActionProvider.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;

namespace OmniSharp.Services
{
public interface ICodeActionProvider
{
IEnumerable<CodeRefactoringProvider> GetProviders();
IEnumerable<CodeRefactoringProvider> Refactorings { get; }
IEnumerable<CodeFixProvider> CodeFixes { get; }
}
}
}
Loading

0 comments on commit 2439ca8

Please sign in to comment.