SublimeText / PowerShell

Support for the MS PowerShell programming language.
MIT License
312 stars 80 forks source link

Powershell "Here-Strings" breaks syntax highlighting #151

Closed jordigg closed 6 years ago

jordigg commented 8 years ago

When using

$var = @"
Long text inside a variable
Long text inside a variable 2
Long text inside a variable 3
Long text inside a variable 4
"@

breaks syntax highlighting. Removing the first @ fixes the highlight so I guess the error is how that @ is parsed.

Here a screen-shoot, with and without the first @ Image of bug2 Image of bug1

jordigg commented 8 years ago

Now I saw #130 with the same problem. I see that it's because the indentation. I have that code inside an if condition and that's why I use the indentation but it's still located at the same level as the opening @.

Without identation

$var = @"
Long text inside a variable
Long text inside a variable 2
Long text inside a variable 3
Long text inside a variable 4
"@
New-Item -path C:\temp -name bla.conf -type "file" -value $var -force

With identation

if($bla){
    $var = @"
    Long text inside a variable
    Long text inside a variable 2
    Long text inside a variable 3
    Long text inside a variable 4
    "@
    New-Item -path C:\temp -name bla.conf -type "file" -value $var -force
}

Seems that Github have the same problem or I'm doing something wrong. How should I write that "Here-Strings" variable? At the top of my script outside any indentation?

Jaykul commented 8 years ago

That's not a bug, that's a feature.

Here strings in PowerShell have 3 character delimiters: at, quote, newline ---> newline, quote, at.

If there's whitespace between the newline and the quote, it's not valid powershell.

vors commented 6 years ago

Yes, thank you @Jaykul ! The indentation makes it invalid here-string.