Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formating Problem #1547

Closed
vendolis opened this issue Sep 26, 2018 · 6 comments
Closed

Code formating Problem #1547

vendolis opened this issue Sep 26, 2018 · 6 comments

Comments

@vendolis
Copy link

vendolis commented Sep 26, 2018

EditorServices.zip

Issue Description

I am experiencing a problem with Code formatting.
When the code in the region on the bottom is in the code the code formatting is not working. also sometimes when I do copy and paste of that block the extension crashes.

CodeFormatingIssue.txt
[Contents of TXT file]:

Function Compare-VersionNumber 
{

    param( 
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [AllowEmptyString()]
        [alias("Version1")]
        [string]
        $ver1,

        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
        [AllowEmptyString()]
        [alias("Version2")]
        [string]
        $ver2
    )

    If($ver1 -eq '' -or $ver1 -eq $null) 
    {
        $ver1 = '0'
    }

    if($ver2 -eq '' -or $ver2 -eq $null) 
    {
        $ver2 = '0'
    }
    # returns whether ver1 is Less, Greater, or Equal to ver2
    $ver1Array = $ver1.Split(".")
    $ver2Array = $ver2.Split(".")
 
    # Decide which array has the least amount of subversions and we'll only compare the least amount
    If ($ver1Array.count -ge $ver2Array.count) { $count = $ver1Array.count }
    Else { $count = $ver2Array.count }
 
    # Loop through each sub version and compare them.
    # Once I hit a Greater or Less than I change the count to break
    # Out of the for loop because there is no need to compare further
    For ($i = 0; $i -lt $count; $i++) 
    {
        Switch ( $ver1Array[$i].CompareTo($ver2Array[$i]) ) {
            -1 { $compare = "Less"; $i = $count + 1 }
            0 { $compare = "Equal" }
            1 { $compare = "Greater"; $i = $count + 1 }
        }
    }
 
    return $compare
 
}

#region issue here
$TemplateCollections = @()



$TemplateCollections += New-Object PSObject -Property @{ColNb = "00"
Name ="Clients | All"
Query= "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.Client = 1"
LimitingCollection = $LimitingCollection
Comment = "All devices detected by SCCM"}

#endregion

From the log:

2018-09-26 16:21:33.252 [WARNING] C:\PowerShellEditorServices\src\PowerShellEditorServices\Analysis\AnalysisService.cs: In method 'Format', line 362:
    Errors found while formatting file: 
        'count' must be non-negative.
    Parameter name: count

Attached Logs

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17134
VSCode 1.27.2
PowerShell Extension Version 1.8.4

PowerShell Information

Name Value
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17134.228
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
azure-account ms-vscode 0.4.3
beautify HookyQR 1.4.3
better-comments aaron-bond 1.3.0
Bookmarks alefragnani 9.1.0
code-settings-sync Shan 3.1.2
gitlens eamodio 8.5.6
PowerShell ms-vscode 1.8.4
theme-cobalt2 wesbos 2.1.6
vscode-azurestorage ms-azuretools 0.4.1
vscode-icons robertohuertasm 7.26.0
vsliveshare ms-vsliveshare 0.3.709
@rjmholt
Copy link
Contributor

rjmholt commented Sep 28, 2018

Some of the crash may be this:
PowerShell/PowerShellEditorServices#739

@rjmholt
Copy link
Contributor

rjmholt commented Sep 28, 2018

@vendolis Can you upload your logs to allow the issue to be diagnosed more easily?

@rjmholt
Copy link
Contributor

rjmholt commented Sep 28, 2018

Trying to reproduce this I'm getting no formatting at all -- looks like I'm hitting PowerShell/PSScriptAnalyzer#1070.

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Sep 28, 2018

@rjmholt the logs are at the top of the issue btw

@rjmholt
Copy link
Contributor

rjmholt commented Sep 28, 2018

Ah yep!

@TylerLeonhardt
Copy link
Member

Good news, @vendolis! This is fixed in PSScriptAnalyzer as @rjmholt mentioned above. So this will be fixed in the next release of PSScriptAnalyzer and then we will do a release of the PowerShell extension and you'll get the fix.

So you'll get this fix in the near future.

If you want it now, you can download the CI build of PSScriptAnalyzer here and throw that in your PSModulePath.

I'm going to close this issue since it's an external problem of the PowerShell extension and it's already fixed upstream.

Let me know if you feel otherwise 😄

Hope you had a nice time at Ignite!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants