PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

Reindent problem with C#

Open stephen147 opened this issue 4 years ago • 2 comments

I assume that this controls the indentation for .ps1 files so hopefully, this is the correct place to post this issue.

With Powershell I have this code:

Function Get-ForegroundWindow {
  Add-Type @"
  using System; using System.Runtime.InteropServices; public class ClassGetForegroundWindow {
    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();
  }
"@
  return [ClassGetForegroundWindow]::GetForegroundWindow()
}

Get-ForegroundWindow

After reindenting it it appears to be:

Function Get-ForegroundWindow {
  Add-Type @"
  using System; using System.Runtime.InteropServices; public class ClassGetForegroundWindow {
    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();
  }
  "@
  return [ClassGetForegroundWindow]::GetForegroundWindow()
}

Get-ForegroundWindow

This then fails to run as the "@ is indented when it shouldn't.

stephen147 avatar May 13 '21 13:05 stephen147

I guess this repo lacks any tmPreferences files controlling indentation, so it uses the defaults. You'd want a unindentedLinePattern matching "@ iirc.

keith-hall avatar May 13 '21 15:05 keith-hall

Oh, I didn't even think to see if there was one. I assumed there was.

Hopefully, this could get added as a rule if the person maintaining this repo sees this as it would be nice to be included out of the box.

stephen147 avatar May 13 '21 16:05 stephen147