Skip to content

Commit

Permalink
Sort package versions in descending order.
Browse files Browse the repository at this point in the history
Add switch to revert to old behaviour.

Relates to #6.
  • Loading branch information
tintoy committed Aug 26, 2017
1 parent bf36e64 commit a2558e9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v0.1.11

* Sort package versions in descending order.
If you prefer the old behaviour, you can set `msbuildProjectTools.nuget.newestVersionsFirst` to `false`.

## v0.1.10

* Improve tooltip content when hovering on MSBuild XML.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "msbuild-project-tools",
"displayName": "MSBuild project tools",
"description": "Tools for working with MSBuild project files (such as auto-complete for package Ids / versions).",
"version": "0.1.10",
"version": "0.1.11",
"publisher": "tintoy",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -48,6 +48,7 @@
"trace": false
},
"nuget": {
"newestVersionsFirst": true,
"disablePrefetch": false
}
},
Expand Down Expand Up @@ -97,9 +98,15 @@
"description": "Configuration for the MSBuild language service.",
"type": "object",
"default": {
"newestVersionsFirst": true,
"disablePreFetch": false
},
"properties": {
"newestVersionsFirst": {
"type": "boolean",
"default": true,
"description": "Sort package versions in descending order (i.e. newest versions first)? Set this to false to revert to the old behaviour (VSCode decides how to sort the completion list)."
},
"disablePreFetch": {
"type": "boolean",
"default": false,
Expand Down
5 changes: 5 additions & 0 deletions src/LanguageServer.Engine/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ public Configuration()
/// Disable automatic warm-up of the NuGet API client?
/// </summary>
public bool DisableNuGetPreFetch { get; set; } = false;

/// <summary>
/// Sort package versions in descending order (i.e. newest versions first)?
/// </summary>
public bool ShowNewestNuGetVersionsFirst { get; set; } = true;
}
}
11 changes: 8 additions & 3 deletions src/LanguageServer.Engine/Handlers/CompletionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,21 @@ async Task<CompletionList> OnCompletion(TextDocumentPositionParams parameters, C
return null;

string packageId = includeAttribute.Value;
SortedSet<NuGetVersion> packageVersions = await projectDocument.SuggestPackageVersions(packageId, cancellationToken);
IEnumerable<NuGetVersion> packageVersions = await projectDocument.SuggestPackageVersions(packageId, cancellationToken);
if (Workspace.Configuration.ShowNewestNuGetVersionsFirst)
packageVersions = packageVersions.Reverse();

Lsp.Models.Range replacementRange = attributeValueRange.ToLsp();

completionItems.AddRange(
packageVersions.Select(packageVersion => new CompletionItem
packageVersions.Select((packageVersion, index) => new CompletionItem
{
Label = packageVersion.ToNormalizedString(),
SortText = Workspace.Configuration.ShowNewestNuGetVersionsFirst ? $"NuGet{index:00}" : null, // Override default sort order if configured to do so.
Kind = CompletionItemKind.Field,
TextEdit = new TextEdit
{
Range = attributeValueRange.ToLsp(),
Range = replacementRange,
NewText = packageVersion.ToNormalizedString()
}
})
Expand Down
3 changes: 3 additions & 0 deletions src/LanguageServer.Engine/Handlers/ConfigurationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Task OnDidChangeConfiguration(DidChangeConfigurationObjectParams parameters)
{
if (nugetConfiguration.TryGetValue("disablePreFetch", out JToken disablePrefetch) && disablePrefetch.Type == JTokenType.Boolean)
Configuration.DisableNuGetPreFetch = disablePrefetch.Value<bool>();

if (nugetConfiguration.TryGetValue("newestVersionsFirst", out JToken newestVersionsFirst) && newestVersionsFirst.Type == JTokenType.Boolean)
Configuration.ShowNewestNuGetVersionsFirst = newestVersionsFirst.Value<bool>();
}

if (ConfigurationChanged != null)
Expand Down
3 changes: 2 additions & 1 deletion src/LanguageServer.Engine/Utilities/NuGetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public static Task<List<AutoCompleteResource>> GetAutoCompleteResources(params P
);

return new SortedSet<NuGetVersion>(
results.SelectMany(suggestions => suggestions)
results.SelectMany(suggestions => suggestions),
NuGet.Versioning.VersionComparer.VersionReleaseMetadata
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ interface LanguageSettings {
* NuGet settings.
*/
interface NuGetSettings {
/**
* Sort package versions in descending order (i.e. newest versions first)?
*/
newestVersionsFirst: boolean;

/**
* Disable automatic warm-up of the NuGet client when opening a project?
*/
Expand Down

0 comments on commit a2558e9

Please sign in to comment.