Skip to content

Commit 33bd996

Browse files
Fix more breaking changes (#60)
* Fix more breaking changes Also add case type setting to splat refactor * fix for PowerShell preview 3+
1 parent 234ddd7 commit 33bd996

File tree

14 files changed

+97
-43
lines changed

14 files changed

+97
-43
lines changed

module/EditorServicesCommandSuite.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ PrivateData = @{
9292
'@
9393

9494
# Prerelease string of this module
95-
Prerelease = 'beta2'
95+
Prerelease = 'beta3'
9696

9797
} # End of PSData hashtable
9898

module/EditorServicesCommandSuite.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Update-FormatData -AppendPath $PSScriptRoot/EditorServicesCommandSuite.format.ps
44

55
if ($null -ne $psEditor) {
66
if ($PSVersionTable.PSVersion.Major -ge 6) {
7-
$extensionService = [Microsoft.PowerShell.EditorServices.Extensions.EditorObjectExtensions, Microsoft.PowerShell.EditorServices]::
8-
GetExtensionServiceProvider($psEditor)
7+
$psesAlc = [System.Runtime.Loader.AssemblyLoadContext]::GetLoadContext(
8+
[Microsoft.PowerShell.EditorServices.Extensions.EditorObjectExtensions, Microsoft.PowerShell.EditorServices].Assembly)
99

10-
$assembly = $extensionService.LoadAssemblyInPsesLoadContext((
11-
Join-Path $PSScriptRoot -ChildPath 'EditorServicesCommandSuite.EditorServices.dll'))
10+
$assembly = $psesAlc.LoadFromAssemblyPath((
11+
Join-Path $PSScriptRoot -ChildPath EditorServicesCommandSuite.EditorServices.dll))
1212

1313
$type = $assembly.GetType('EditorServicesCommandSuite.EditorServices.Internal.CommandSuite')
1414
} else {

src/EditorServicesCommandSuite.Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<AdditionalFiles Include="..\EditorServicesCommandSuite\stylecop.json" />
1414
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
15-
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
15+
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
1616
</ItemGroup>
1717
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
1818
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-04" PrivateAssets="All" />

src/EditorServicesCommandSuite.EditorServices/DocumentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using EditorServicesCommandSuite.Internal;
99
using Microsoft.PowerShell.EditorServices.Extensions;
1010
using Microsoft.PowerShell.EditorServices.Extensions.Services;
11+
using OmniSharp.Extensions.LanguageServer.Protocol;
1112
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1213

1314
namespace EditorServicesCommandSuite.EditorServices
@@ -76,7 +77,7 @@ public async Task WriteDocumentEditsAsync(IEnumerable<DocumentEdit> edits, Cance
7677

7778
var versionedIdentifier = new VersionedTextDocumentIdentifier
7879
{
79-
Uri = editGroup.Key ?? context.Uri,
80+
Uri = DocumentUri.From(editGroup.Key ?? context.Uri),
8081
Version = default,
8182
};
8283

src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\EditorServicesCommandSuite.Common.props" />
3+
<PropertyGroup>
4+
<RestoreAdditionalProjectSources>
5+
$(RestoreAdditionalProjectSources)
6+
https://www.myget.org/F/omnisharp/api/v3/index.json
7+
</RestoreAdditionalProjectSources>
8+
</PropertyGroup>
39
<ItemGroup>
4-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.16.0" PrivateAssets="all" />
10+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
511
<ProjectReference Include="..\EditorServicesCommandSuite\EditorServicesCommandSuite.csproj" />
612
<Reference Include="Microsoft.PowerShell.EditorServices">
713
<HintPath>..\..\lib\PowerShellEditorServices\bin\Microsoft.PowerShell.EditorServices.dll</HintPath>

src/EditorServicesCommandSuite.EditorServices/LspPosition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ namespace EditorServicesCommandSuite.EditorServices
44
{
55
internal class LspPosition : ILspFilePosition
66
{
7-
public LspPosition(long line, long character)
7+
public LspPosition(int line, int character)
88
{
99
Line = line;
1010
Character = character;
1111
}
1212

13-
public long Line { get; }
13+
public int Line { get; }
1414

15-
public long Character { get; }
15+
public int Character { get; }
1616
}
1717
}

src/EditorServicesCommandSuite.PSReadLine/EditorServicesCommandSuite.PSReadLine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</Reference>
99
</ItemGroup>
1010
<ItemGroup>
11-
<PackageReference Include="System.Buffers" Version="4.4.0" />
11+
<PackageReference Include="System.Buffers" Version="4.5.1" />
1212
</ItemGroup>
1313
</Project>

src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ public override async Task Invoke(DocumentContextBase context)
7171
return;
7272
}
7373

74+
var config = context.GetConfiguration<CommandSplatRefactorSettings>();
7475
await ProcessActionForInvoke(
7576
context,
76-
CreateCodeAction(command, AdditionalParameterTypes.None))
77+
CreateCodeAction(command, config.AdditionalParameters))
7778
.ConfigureAwait(false);
7879
}
7980

@@ -123,7 +124,7 @@ internal static async Task SplatCommandAsync(
123124

124125
var config = context.GetConfiguration<CommandSplatRefactorSettings>();
125126
string splatVariable = string.IsNullOrWhiteSpace(config.VariableName)
126-
? GetSplatVariableName(command.CommandElements[0])
127+
? GetSplatVariableName(command.CommandElements[0], config.CaseType)
127128
: config.VariableName;
128129

129130
IEnumerable<DocumentEdit> edits = await GetEdits(
@@ -135,8 +136,9 @@ internal static async Task SplatCommandAsync(
135136
splatVariable,
136137
parameterTypes,
137138
config.ExcludeHints,
138-
config.NewLineAfterHashtable,
139-
context.CancellationToken))
139+
config.NoNewLineAfterHashtable,
140+
context.CancellationToken,
141+
config.CaseType))
140142
.ConfigureAwait(false);
141143

142144
await context.RegisterWorkspaceChangeAsync(
@@ -389,7 +391,7 @@ await args.UI.ShowWarningMessageAsync(
389391

390392
splatWriter.CloseHashtable();
391393

392-
if (args.NewLineAfterHashtable)
394+
if (!args.NoNewLineAfterHashtable)
393395
{
394396
splatWriter.WriteLine();
395397
}
@@ -527,7 +529,7 @@ private static bool TryGetDefaultParameterSet(CommandInfo commandInfo, out strin
527529
return false;
528530
}
529531

530-
private static string GetSplatVariableName(CommandElementAst element)
532+
private static string GetSplatVariableName(CommandElementAst element, CaseType caseType)
531533
{
532534
var nameConstant = element as StringConstantExpressionAst;
533535
if (element == null)
@@ -549,14 +551,24 @@ private static string GetSplatVariableName(CommandElementAst element)
549551
.Replace(Symbols.Dash.ToString(), string.Empty)
550552
+ SplatVariableSuffix;
551553

552-
if (!char.IsUpper(variableName[0]))
554+
bool isFirstLetterCap = char.IsUpper(variableName[0]);
555+
bool isPascalCase = caseType == CaseType.PascalCase;
556+
if (isPascalCase)
557+
{
558+
if (isFirstLetterCap)
559+
{
560+
return variableName;
561+
}
562+
563+
return char.ToUpperInvariant(variableName[0]) + variableName.Substring(1);
564+
}
565+
566+
if (!isFirstLetterCap)
553567
{
554568
return variableName;
555569
}
556570

557-
return
558-
char.ToLower(variableName[0])
559-
+ variableName.Substring(1);
571+
return char.ToLowerInvariant(variableName[0]) + variableName.Substring(1);
560572
}
561573

562574
private CodeAction CreateCodeAction(
@@ -594,7 +606,9 @@ private struct CommandSplatArguments
594606

595607
internal readonly bool ExcludeHints;
596608

597-
internal readonly bool NewLineAfterHashtable;
609+
internal readonly bool NoNewLineAfterHashtable;
610+
611+
internal readonly CaseType CaseType;
598612

599613
internal CommandSplatArguments(
600614
ThreadController pipelineThread,
@@ -604,8 +618,9 @@ internal CommandSplatArguments(
604618
string variableName,
605619
AdditionalParameterTypes includedParameterTypes,
606620
bool excludeHints,
607-
bool newLineAfterHashtable,
608-
CancellationToken cancellationToken)
621+
bool noNewLineAfterHashtable,
622+
CancellationToken cancellationToken,
623+
CaseType caseType)
609624
{
610625
PipelineThread = pipelineThread;
611626
UI = ui;
@@ -614,8 +629,9 @@ internal CommandSplatArguments(
614629
VariableName = variableName;
615630
IncludedTypes = includedParameterTypes;
616631
ExcludeHints = excludeHints;
617-
NewLineAfterHashtable = newLineAfterHashtable;
632+
NoNewLineAfterHashtable = noNewLineAfterHashtable;
618633
CancellationToken = cancellationToken;
634+
CaseType = caseType;
619635
}
620636
}
621637
}

src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactorSettings.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Management.Automation;
2+
using EditorServicesCommandSuite.Language;
23

34
namespace EditorServicesCommandSuite.CodeGeneration.Refactors
45
{
@@ -10,15 +11,19 @@ internal class CommandSplatRefactorSettings : RefactorConfiguration
1011
public string VariableName { get; set; }
1112

1213
[Parameter]
13-
[DefaultFromSetting("CommandSplatRefactor.NewLineAfterHashtable", Default = "$true")]
14-
public SwitchParameter NewLineAfterHashtable { get; set; }
14+
[DefaultFromSetting("CommandSplatRefactor.NoNewLineAfterHashtable", Default = "$false")]
15+
public SwitchParameter NoNewLineAfterHashtable { get; set; }
1516

1617
[Parameter]
17-
[DefaultFromSetting("CommandSplatRefactor.AdditionalParameters", Default = "\"None\"")]
18+
[DefaultFromSetting("CommandSplatRefactor.AdditionalParameters", Default = "\'None\'")]
1819
public AdditionalParameterTypes AdditionalParameters { get; set; }
1920

2021
[Parameter]
2122
[DefaultFromSetting("CommandSplatRefactor.ExcludeHints", Default = "$false")]
2223
public SwitchParameter ExcludeHints { get; set; }
24+
25+
[Parameter]
26+
[DefaultFromSetting("CommandSplatRefactor.VariableCaseType", Default = "\'CamelCase\'")]
27+
public CaseType CaseType { get; set; }
2328
}
2429
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\EditorServicesCommandSuite.Common.props" />
3+
<PropertyGroup>
4+
<RestoreAdditionalProjectSources>
5+
$(RestoreAdditionalProjectSources)
6+
https://www.myget.org/F/omnisharp/api/v3/index.json
7+
</RestoreAdditionalProjectSources>
8+
</PropertyGroup>
39
<ItemGroup>
410
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
5-
<PackageReference Include="System.Buffers" Version="4.4.0" />
6-
<PackageReference Include="System.Memory" Version="4.5.2" />
7-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.16.0" PrivateAssets="all" />
11+
<PackageReference Include="System.Buffers" Version="4.5.1" />
12+
<PackageReference Include="System.Memory" Version="4.5.4" />
13+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
814
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
915
</ItemGroup>
1016
</Project>
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
namespace EditorServicesCommandSuite.Language
22
{
3-
internal enum CaseType
3+
/// <summary>
4+
/// Represents a style of capitalization for identifiers.
5+
/// </summary>
6+
public enum CaseType
47
{
5-
PascalCase,
8+
/// <summary>
9+
/// Case style will default based on the action taken.
10+
/// </summary>
11+
Default = 0,
612

7-
CamelCase,
13+
/// <summary>
14+
/// The first letter of each word in the identifier will be capitalized.
15+
/// </summary>
16+
PascalCase = 1,
17+
18+
/// <summary>
19+
/// The first letter of each word in the identifier will be capitalized,
20+
/// except for the first word which will be all lowercase.
21+
/// </summary>
22+
CamelCase = 2,
823
}
924
}

src/EditorServicesCommandSuite/resources/SettingsStrings.resx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,26 @@
153153
<data name="CommandSplatRefactor_VariableNameDescription" xml:space="preserve">
154154
<value>The variable name to use when creating the splat expression variable. The default behavior is to name the string similar to "getCommandNameHereSplat". Setting this to $null will enforce the default behavior.</value>
155155
</data>
156-
<data name="CommandSplatRefactor_NewLineAfterHashtableDescription" xml:space="preserve">
156+
<data name="CommandSplatRefactor_NoNewLineAfterHashtableDescription" xml:space="preserve">
157157
<value>Specifies whether a new line should be placed between the hashtable and the original command expression.</value>
158158
</data>
159159
<data name="CommandSplatRefactor_AdditionalParametersDescription" xml:space="preserve">
160160
<value>Specifies if additional parameters that have not been should be added to the splat expression. The following options are available:
161-
"None" - Only bound parameters. This is the default.
162-
"Mandatory" - Mandatory parameters that have not yet been bound will be added.
163-
"All" - All resolved parameters will be added.</value>
161+
'None' - Only bound parameters. This is the default.
162+
'Mandatory' - Mandatory parameters that have not yet been bound will be added.
163+
'All' - All resolved parameters will be added.</value>
164164
</data>
165165
<data name="CommandSplatRefactor_ExcludeHintsDescription" xml:space="preserve">
166166
<value>Specifies whether the value for additional unbound parameters should be a variable of the same name as the parameter, or if it should be decorated with mandatoriness and parameter type.
167167
$true - Path = $path
168168
$false - Path = $mandatoryStringPath</value>
169169
</data>
170-
<data name="ExpandMemberExpression_AllowNonPublicMembers" xml:space="preserve">
170+
<data name="CommandSplatRefactor_VariableCaseTypeDescription" xml:space="preserve">
171+
<value>Specifies the case style to use for generated variable names.
172+
'CamelCase' - $getChildItemSplat. This is the default.
173+
'PascalCase' - $GetChildItemSplat</value>
174+
</data>
175+
<data name="ExpandMemberExpression_AllowNonPublicMembersDescription" xml:space="preserve">
171176
<value>Specifies whether non-public members should be included in the list of resolved members. If a non-public member is selected, an expression utilizing reflection will be generated to access the member.</value>
172177
</data>
173178
<data name="UsingStatements_SeparateGroupsWithNewLineDescription" xml:space="preserve">

test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ await GetRefactoredTextAsync(
396396
private async Task<string> GetRefactoredTextAsync(
397397
string testString,
398398
string variableName = "splat",
399-
bool newLineAfterHashtable = false,
399+
bool noNewLineAfterHashtable = true,
400400
bool allParameters = false,
401401
bool mandatoryParameters = false,
402402
bool noHints = false,
@@ -411,7 +411,7 @@ private async Task<string> GetRefactoredTextAsync(
411411
{
412412
AdditionalParameters = includedTypes,
413413
ExcludeHints = noHints,
414-
NewLineAfterHashtable = newLineAfterHashtable,
414+
NoNewLineAfterHashtable = noNewLineAfterHashtable,
415415
VariableName = variableName,
416416
};
417417

tools/AssertPSES.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[CmdletBinding()]
22
param(
33
[ValidateNotNull()]
4-
[string] $RequiredVersion = '2.1.0'
4+
[string] $RequiredVersion = '2.2.0'
55
)
66
begin {
77
Add-Type -AssemblyName System.IO.Compression

0 commit comments

Comments
 (0)