Skip to content

Commit

Permalink
Initial support for autocomplete of versions in private sources in At…
Browse files Browse the repository at this point in the history
…om and VS Code - references #1298
  • Loading branch information
forki committed Jan 18, 2016
1 parent 599776f commit 7572b87
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### 2.44.6 - 18.01.2016
* BUGFIX: Fix casing for autocomplete of local NuGet feeds - https://github.com/fsprojects/Paket/issues/1298
* Initial support for autocomplete of private sources in Atom and VS Code - https://github.com/fsprojects/Paket/issues/1298
* Initial support for autocomplete of versions in private sources in Atom and VS Code - https://github.com/fsprojects/Paket/issues/1298

#### 2.44.5 - 17.01.2016
* Initial support for autocomplete of local NuGet feeds - https://github.com/fsprojects/Paket/issues/1298
Expand Down
23 changes: 22 additions & 1 deletion integrationtests/Paket.IntegrationTests/AutocompleteSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,25 @@ let ``#1298 should autocomplete for fake on local feed``() =
let result = Dependencies.FindPackagesByName([PackageSource.LocalNuGet(Path.Combine(originalScenarioPath "i001219-props-files", "nuget_repo"))],"fake")
result |> shouldContain "FAKE.Core"
result |> shouldNotContain "Dapper"
result |> shouldNotContain "dapper"
result |> shouldNotContain "dapper"

[<Test>]
let ``#1298 should autocomplete versions for FAKE on NuGet3``() =
let result = Dependencies.FindPackageVersions("",[PackageSource.NuGetV3Source Constants.DefaultNuGetV3Stream],"fake")
result |> shouldContain "2.6.15"
result |> shouldContain "4.14.9"
result.Length |> shouldEqual 1000
result |> shouldNotContain "FAKE.Core"

[<Test>]
[<Ignore>] // it's only working on forki's machine
let ``#1298 should autocomplete versions for msu on local teamcity``() =
let result = Dependencies.FindPackageVersions("",[PackageSource.NuGetV2Source "http://teamcity/guestAuth/app/nuget/v1/FeedService.svc/"],"msu.Addins")
result |> shouldNotContain "msu.Addins"
result |> shouldContain "03.03.7"

[<Test>]
let ``#1298 should autocomplete versions for dapper on local feed``() =
let result = Dependencies.FindPackageVersions("",[PackageSource.LocalNuGet(Path.Combine(originalScenarioPath "i001219-props-files", "nuget_repo"))],"Dapper")
result |> shouldEqual [|"1.42.0"; "1.40"|]

2 changes: 1 addition & 1 deletion src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let tryNuGetV3 (auth, nugetV3Url, package:PackageName) =
with exn -> return None
}

/// Gets versions of the given package from local Nuget feed.
/// Gets versions of the given package from local NuGet feed.
let getAllVersionsFromLocalPath (localNugetPath, package:PackageName, root) =
async {
let localNugetPath = Utils.normalizeLocalPath localNugetPath
Expand Down
6 changes: 3 additions & 3 deletions src/Paket.Core/NuGetV3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ let internal findAutoCompleteVersionsForPackage(v3Url, auth, packageName:Domain.
let versions =
let extracted = extractAutoCompleteVersions text
if extracted.Length > maxResults then
extracted |> Seq.take maxResults |> Seq.toArray
SemVer.SortVersions extracted |> Array.take maxResults
else
extracted
SemVer.SortVersions extracted

return Some(SemVer.SortVersions versions)
return Some versions
| None -> return None
}

Expand Down
28 changes: 24 additions & 4 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,9 @@ type Dependencies(dependenciesFileName: string) =
|> Seq.choose (fun source ->
match source with
| NuGetV2 s ->
if s.Url.Contains "nuget.org" || s.Url.Contains "myget.org" then
Some(NuGetV3.FindPackages(s.Authentication, s.Url, searchTerm, maxResults))
else
Some(NuGetV2.FindPackages(s.Authentication, s.Url, searchTerm, maxResults))
match NuGetV3.getSearchAPI(s.Authentication,s.Url) with
| Some _ -> Some(NuGetV3.FindPackages(s.Authentication, s.Url, searchTerm, maxResults))
| None -> Some(NuGetV2.FindPackages(s.Authentication, s.Url, searchTerm, maxResults))
| NuGetV3 s -> Some(NuGetV3.FindPackages(s.Authentication, s.Url, searchTerm, maxResults))
| LocalNuGet s ->
Some(async {
Expand Down Expand Up @@ -498,6 +497,27 @@ type Dependencies(dependenciesFileName: string) =
cancellationToken,
maxResults)

static member FindPackageVersions(root,sources:PackageSource seq,name:string,?maxResults) =
let maxResults = defaultArg maxResults 1000
let sources =
match sources |> Seq.toList |> List.distinct with
| [] -> [PackageSources.DefaultNuGetSource]
| sources -> sources
|> List.distinct

let versions =
NuGetV2.GetVersions true root (sources, PackageName name)
|> List.map (fun (v,_) -> v.ToString())
|> List.toArray
|> SemVer.SortVersions

if versions.Length > maxResults then Array.take maxResults versions else versions


member this.FindPackageVersions(sources:PackageSource seq,name:string,?maxResults) =
let maxResults = defaultArg maxResults 1000
Dependencies.FindPackageVersions(this.RootPath,sources,name,maxResults)

/// Finds all projects where the given package is referenced.
member this.FindProjectsFor(group:string,package: string): ProjectFile list =
FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process
Expand Down
16 changes: 7 additions & 9 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,17 @@ let showGroups (results : ParseResults<ShowGroupsArgs>) =

let findPackageVersions (results : ParseResults<_>) =
let maxResults = defaultArg (results.TryGetResult <@ FindPackageVersionsArgs.MaxResults @>) 10000
let dependencies = Dependencies.Locate()
let name =
match results.TryGetResult <@ FindPackageVersionsArgs.NuGet @> with
| Some name -> name
| None -> results.GetResult <@ FindPackageVersionsArgs.Name @>
let source = defaultArg (results.TryGetResult <@ FindPackageVersionsArgs.Source @>) Constants.DefaultNuGetStream
let result =
match NuGetV3.getSearchAPI(None,source) with
| None -> Array.empty
| Some v3Url ->
NuGetV3.FindAutoCompleteVersionsForPackage(v3Url,None,Domain.PackageName name,true,maxResults)
|> Async.RunSynchronously

for p in result do
let sources =
match results.TryGetResult <@ FindPackageVersionsArgs.Source @> with
| Some source -> [PackageSource.NuGetV2Source source]
| _ -> dependencies.GetSources() |> Seq.map (fun kv -> kv.Value) |> List.concat

for p in dependencies.FindPackageVersions(sources,name,maxResults) do
tracefn "%s" p

let push (results : ParseResults<_>) =
Expand Down

0 comments on commit 7572b87

Please sign in to comment.