-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support dependency management in VSCode #2734
- Loading branch information
1 parent
2217210
commit 1354620
Showing
23 changed files
with
978 additions
and
304 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
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
67 changes: 67 additions & 0 deletions
67
src/PSRule.EditorServices/Handlers/UpgradeDependencyCommandHandler.cs
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,67 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Window; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace; | ||
using PSRule.CommandLine; | ||
using PSRule.CommandLine.Commands; | ||
using PSRule.CommandLine.Models; | ||
using PSRule.Runtime; | ||
|
||
namespace PSRule.EditorServices.Handlers; | ||
|
||
/// <summary> | ||
/// Handler the upgradeDependency command. | ||
/// This command upgrades a module dependency to the latest version that meeds any specified constraints. | ||
/// </summary> | ||
public sealed class UpgradeDependencyCommandHandler(ClientContext context, ISerializer serializer, ILogger logger) | ||
: ExecuteTypedResponseCommandHandlerBase<UpgradeDependencyCommandHandlerInput, UpgradeDependencyCommandHandlerOutput>(COMMAND_NAME, serializer) | ||
{ | ||
private const string COMMAND_NAME = "upgradeDependency"; | ||
private const string ALL_MODULES_PLACEHOLDER = "*"; | ||
|
||
private readonly ClientContext _Context = context; | ||
private readonly ILogger _Logger = logger; | ||
|
||
/// <summary> | ||
/// Handle the upgradeDependency command. | ||
/// </summary> | ||
public override async Task<UpgradeDependencyCommandHandlerOutput> Handle(UpgradeDependencyCommandHandlerInput input, CancellationToken cancellationToken) | ||
{ | ||
ArgumentNullException.ThrowIfNull(input, nameof(input)); | ||
ArgumentException.ThrowIfNullOrWhiteSpace(input.Path, nameof(input.Path)); | ||
ArgumentException.ThrowIfNullOrWhiteSpace(input.Module, nameof(input.Module)); | ||
|
||
var all = input.Module == ALL_MODULES_PLACEHOLDER; | ||
|
||
var options = new ModuleOptions | ||
{ | ||
Module = all ? null : [input.Module], | ||
}; | ||
|
||
if (all) | ||
{ | ||
_Logger.LogInformation(new EventId(0), "Checking for upgrades of all modules in: {0}", input.Path); | ||
} | ||
else | ||
{ | ||
_Logger.LogInformation(new EventId(0), "Checking for upgrades of module {0} in: {1}", input.Module, input.Path); | ||
} | ||
|
||
try | ||
{ | ||
var exitCode = await ModuleCommand.ModuleUpgradeAsync(options, _Context, cancellationToken); | ||
if (exitCode != 0) | ||
{ | ||
throw new InvalidOperationException("Module upgrade failed"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_Logger.LogError(new EventId(0), ex, ex.Message); | ||
} | ||
|
||
return new UpgradeDependencyCommandHandlerOutput(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/PSRule.EditorServices/Handlers/UpgradeDependencyCommandHandlerInput.cs
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,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.EditorServices.Handlers; | ||
|
||
/// <summary> | ||
/// Input for the upgrade dependency command handler. | ||
/// </summary> | ||
public sealed class UpgradeDependencyCommandHandlerInput | ||
{ | ||
/// <summary> | ||
/// The path to the options file. | ||
/// </summary> | ||
public string? Path { get; set; } | ||
|
||
/// <summary> | ||
/// The module to upgrade. | ||
/// </summary> | ||
public string? Module { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/PSRule.EditorServices/Handlers/UpgradeDependencyCommandHandlerOutput.cs
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 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.EditorServices.Handlers; | ||
|
||
/// <summary> | ||
/// Output for the upgrade dependency command handler. | ||
/// </summary> | ||
public sealed class UpgradeDependencyCommandHandlerOutput | ||
{ | ||
|
||
} |
Oops, something went wrong.