Skip to content

Commit

Permalink
Fixed an issue with refactoring unsaved files (#76)
Browse files Browse the repository at this point in the history
* Fixed an issue with refactoring unsaved files

* Fixed a startup issue
  • Loading branch information
adamdriscoll committed Jul 18, 2024
1 parent 75f4cdf commit dea3deb
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 141 deletions.
12 changes: 9 additions & 3 deletions HostInjection/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class TextEdit
public string Content { get; set; }
public string FileName { get; set; }
public TextEditType Type { get; set; }

public string Uri { get; set; }


public static TextEdit None
{
Expand All @@ -30,7 +31,8 @@ public override bool Equals(object obj)
EqualityComparer<TextPosition>.Default.Equals(Cursor, edit.Cursor) &&
Content == edit.Content &&
FileName == edit.FileName &&
Type == edit.Type;
Type == edit.Type &&
Uri == edit.Uri;
}

public override int GetHashCode()
Expand All @@ -41,6 +43,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + EqualityComparer<TextPosition>.Default.GetHashCode(Cursor);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Content);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(FileName);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Uri);
hashCode = hashCode * -1521134295 + Type.GetHashCode();
return hashCode;
}
Expand All @@ -62,12 +65,14 @@ public class TextEditorState
public TextPosition SelectionEnd { get; set; }
public TextPosition DocumentEnd { get; set; }
public IPoshToolsServer Server { get; set; }
public string Uri { get; set; }

public override bool Equals(object obj)
{
return obj is TextEditorState state &&
Content == state.Content &&
FileName == state.FileName &&
Uri == state.Uri &&
EqualityComparer<TextPosition>.Default.Equals(SelectionStart, state.SelectionStart) &&
EqualityComparer<TextPosition>.Default.Equals(SelectionEnd, state.SelectionEnd) &&
EqualityComparer<TextPosition>.Default.Equals(DocumentEnd, state.DocumentEnd) &&
Expand All @@ -82,6 +87,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + EqualityComparer<TextPosition>.Default.GetHashCode(SelectionStart);
hashCode = hashCode * -1521134295 + EqualityComparer<TextPosition>.Default.GetHashCode(SelectionEnd);
hashCode = hashCode * -1521134295 + EqualityComparer<TextPosition>.Default.GetHashCode(DocumentEnd);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Uri);
hashCode = hashCode * -1521134295 + EqualityComparer<IPoshToolsServer>.Default.GetHashCode(Server);
return hashCode;
}
Expand Down Expand Up @@ -156,7 +162,7 @@ public RefactorInfo() { }
public RefactorInfo(string name, RefactorType type)
{
Name = name;
Type = type;
Type = type;
}

public string Name { get; set; }
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/ConvertToDollarUnder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = "$_",
FileName = state.FileName,
Type = TextEditType.Replace,
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/ConvertToMultilineCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString().Trim().TrimEnd('`'),
Type = TextEditType.Replace,
Start = new TextPosition
Expand Down
3 changes: 2 additions & 1 deletion HostInjection/Refactoring/ConvertToPsItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl
{
yield break;
}

yield return new TextEdit
{
Uri = state.Uri,
Content = "$PSItem",
FileName = state.FileName,
Type = TextEditType.Replace,
Expand Down
4 changes: 3 additions & 1 deletion HostInjection/Refactoring/ConvertToSplat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Type = TextEditType.Insert,
Start = new TextPosition
Expand All @@ -103,9 +104,10 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl
},
FileName = state.FileName
};

yield return new TextEdit
{
Uri = state.Uri,
Content = $"{commandName} @Parameters",
Type = TextEditType.Replace,
Start = new TextPosition
Expand Down
2 changes: 2 additions & 0 deletions HostInjection/Refactoring/ExportModuleMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl
{
yield return new TextEdit
{
Uri = state.Uri,
Type = TextEditType.Insert,
Content = $"{Environment.NewLine}Export-ModuleMember -Variable '{variableExpression.VariablePath.UserPath}'",
Start = new TextPosition
Expand All @@ -51,6 +52,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl
{
yield return new TextEdit
{
Uri = state.Uri,
Type = TextEditType.Insert,
Content = $"{Environment.NewLine}Export-ModuleMember -Function '{functionDef.Name}'",
Start = new TextPosition
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/ExtractFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = $"& \"$PSScriptRoot\\{fileName}\"",
Start = new TextPosition
{
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/ExtractFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ m is AssignmentStatementAst assignment &&

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Start = new TextPosition
{
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/ExtractVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Start = new TextPosition
{
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/GenerateFunctionFromUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Type = TextEditType.Insert,
Start = new TextPosition
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/GenerateProxyFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerab

edits.Add(new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Type = TextEditType.Insert,
Start = new TextPosition
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/IntroduceUsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = $"using namespace {namespaceName}{Environment.NewLine}",
FileName = state.FileName,
Type = TextEditType.Insert,
Expand Down
3 changes: 2 additions & 1 deletion HostInjection/Refactoring/Reorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl
}

if (direction == "Right")
{
{
if (targetParameterIndex + 1 == currentParameterIndex)
{
yield break;
Expand Down Expand Up @@ -143,6 +143,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Type = TextEditType.Replace,
Start = new TextPosition
Expand Down
1 change: 1 addition & 0 deletions HostInjection/Refactoring/SplitPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public IEnumerable<TextEdit> Refactor(TextEditorState state, Ast ast, IEnumerabl

yield return new TextEdit
{
Uri = state.Uri,
Content = stringBuilder.ToString(),
Type = TextEditType.Replace,
Start = new TextPosition
Expand Down
2 changes: 1 addition & 1 deletion HostInjection/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public IEnumerable<Variable> GetChildren()
yield break;
}

if (_propertyInfo.Value == null) yield break;
if (_propertyInfo?.Value == null) yield break;

foreach (var item in ProcessObject(_propertyInfo.Value))
{
Expand Down
4 changes: 2 additions & 2 deletions PowerShellToolsPro.Cmdlets/PowerShellProTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Ironman Software, LLC
#
# Generated on: 7/10/2024
# Generated on: 7/18/2024
#

@{
Expand All @@ -18,7 +18,7 @@ ModuleVersion = '2024.7.0'
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '67c5dc55-fa45-4f33-856f-fbab0a85e9eb'
GUID = 'c9ea3714-d2c0-4a2d-9e85-e275d09854cd'

# Author of this module
Author = 'Ironman Software, LLC'
Expand Down
Loading

0 comments on commit dea3deb

Please sign in to comment.