Skip to content

Commit

Permalink
Merge pull request #271 from OmniSharp/nuget-sources
Browse files Browse the repository at this point in the history
Added package sources endpoint
  • Loading branch information
nosami committed Jul 22, 2015
2 parents 6f4a617 + c6807c1 commit 442b15e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 2 deletions.
40 changes: 39 additions & 1 deletion src/OmniSharp/Api/v1/NuGet/OmnisharpController.Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ namespace OmniSharp
#if DNX451

This comment has been minimized.

Copy link
@davidfowl

davidfowl Jul 28, 2015

Member

why

This comment has been minimized.

Copy link
@david-driscoll

david-driscoll Jul 28, 2015

Member

I could not get Nuget3 to build against core clr no matter what I tried. Even without the dependency on the Nuget v2 I was getting errors.

public partial class OmnisharpController
{
[HttpPost("packagesource")]
public PackageSourceResponse PackageSource(PackageSourceRequest request)
{
var projectPath = request.ProjectPath;
if (request.ProjectPath.EndsWith(".json"))
{
projectPath = Path.GetDirectoryName(projectPath);
}

if (!string.IsNullOrWhiteSpace(projectPath))
{
var tasks = new List<Task<IEnumerable<SimpleSearchMetadata>>>();
var repositoryProvider = new OmniSharpSourceRepositoryProvider(projectPath);
var repos = repositoryProvider.GetRepositories().ToArray();
return new PackageSourceResponse()
{
Sources = repos.Select(x => x.PackageSource.Source)
};
}

return new PackageSourceResponse();
}

[HttpPost("packagesearch")]
public async Task<PackageSearchResponse> PackageSearch(PackageSearchRequest request)
{
Expand All @@ -42,6 +65,9 @@ public async Task<PackageSearchResponse> PackageSearch(PackageSearchRequest requ
if (request.PackageTypes == null)
request.PackageTypes = Enumerable.Empty<string>();

if (request.Sources == null)
request.Sources = Enumerable.Empty<string>();

var token = CancellationToken.None;
var filter = new SearchFilter()
{
Expand All @@ -52,6 +78,11 @@ public async Task<PackageSearchResponse> PackageSearch(PackageSearchRequest requ
var tasks = new List<Task<IEnumerable<SimpleSearchMetadata>>>();
var repositoryProvider = new OmniSharpSourceRepositoryProvider(projectPath);
var repos = repositoryProvider.GetRepositories().ToArray();
if (request.Sources.Any())
{
// Reduce to just the sources we requested
repos = repos.Join(request.Sources, x => x.PackageSource.Source, x => x, (x, y) => x).ToArray();
}

foreach (var repo in repos)
{
Expand All @@ -74,7 +105,6 @@ private PackageSearchResponse MergeResults(IEnumerable<SimpleSearchMetadata>[] r
var comparer = new PackageIdentityComparer();
return new PackageSearchResponse()
{
Sources = repos.Select(repo => repo.PackageSource.Source),
Packages = results
.SelectMany(metadata => metadata)
.GroupBy(metadata => metadata.Identity.Id)
Expand All @@ -101,6 +131,9 @@ public async Task<PackageVersionResponse> PackageVersion(PackageVersionRequest r

if (!string.IsNullOrWhiteSpace(projectPath))
{
if (request.Sources == null)
request.Sources = Enumerable.Empty<string>();

var token = CancellationToken.None;

var filter = new SearchFilter
Expand All @@ -110,6 +143,11 @@ public async Task<PackageVersionResponse> PackageVersion(PackageVersionRequest r
var foundVersions = new List<NuGetVersion>();
var repositoryProvider = new OmniSharpSourceRepositoryProvider(projectPath);
var repos = repositoryProvider.GetRepositories().ToArray();
if (request.Sources.Any())
{
// Reduce to just the sources we requested
repos = repos.Join(request.Sources, x => x.PackageSource.Source, x => x, (x, y) => x).ToArray();
}
foreach (var repo in repos)
{
// TODO: Swap when bug is fixed
Expand Down
5 changes: 5 additions & 0 deletions src/OmniSharp/Models/v1/PackageSearchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class PackageSearchRequest
/// </summary>
public string ProjectPath { get; set; }

/// <summary>
/// The sources to search for the given package
/// </summary>
public IEnumerable<string> Sources { get; set; }

/// <summary>
/// The filter search critera
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/OmniSharp/Models/v1/PackageSearchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace OmniSharp.Models
public class PackageSearchResponse
{
public IEnumerable<PackageSearchItem> Packages { get; set; }
public IEnumerable<string> Sources { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/OmniSharp/Models/v1/PackageSourceRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace OmniSharp.Models
{
public class PackageSourceRequest
{
/// <summary>
/// The path to the project file
/// </summary>
public string ProjectPath { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp/Models/v1/PackageSourceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace OmniSharp.Models
{
public class PackageSourceResponse
{
public IEnumerable<string> Sources { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/OmniSharp/Models/v1/PackageVersionRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace OmniSharp.Models
{
Expand All @@ -9,6 +10,11 @@ public class PackageVersionRequest
/// </summary>
public string ProjectPath { get; set; }

/// <summary>
/// The sources to search for the given package
/// </summary>
public IEnumerable<string> Sources { get; set; }

/// <summary>
/// The id of the package to look up the versions
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"NuGet.Packaging.Core": "3.1.0-*",
"NuGet.Protocol.Core.v2": "3.1.0-*",
"NuGet.Protocol.Core.v3": "3.1.0-*"

},
"frameworkAssemblies": {
"System.Globalization": "",
Expand Down

0 comments on commit 442b15e

Please sign in to comment.