-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from OmniSharp/nuget-sources
Added package sources endpoint
- Loading branch information
Showing
7 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,29 @@ namespace OmniSharp | |
#if DNX451 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
david-driscoll
Member
|
||
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) | ||
{ | ||
|
@@ -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() | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
why