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

Copying code with a here string is incorrect #961

Closed
DarkLite1 opened this issue Jul 17, 2017 · 10 comments
Closed

Copying code with a here string is incorrect #961

DarkLite1 opened this issue Jul 17, 2017 · 10 comments
Labels
Bug: VS Code Bugs in VS Code itself.

Comments

@DarkLite1
Copy link

DarkLite1 commented Jul 17, 2017

System Details

  • Operating system name and version: Win Srv 2012 64 bit
  • VS Code version: 1.15.0 insider
  • PowerShell extension version: 1.4.1
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.14409.1005
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1005
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

$pseditor.EditorServicesVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
1      4      1      0

Issue Description

When copying code from one file to another, the code isn't correctly copied when a here string is used.

Test code:

<# 
    .SYNOPSIS   
        Some stuff.

    .DESCRIPTION
        Some stuff.

    .NOTES
        CHANGELOG
        2015/04/01 Script born #>

[CmdletBinding()]
Param(
    [String]$ScriptName
)
        
Begin {
    Get-Date
}
        
Process {
    Get-Date
}
        
End {
    Foreach ($J in $JobResults) {
        $Rows += @"
                    My custom here string
"@
    }
    $HTML = @"
                More custom stuff that uses $Row
"@
}

Result when copying from left to right:
image

You can see that the ending "@ isn't respected and white spaces are added. This results in code that wont run. It's even adding tabs in front of other code, which is not desirable but isn't a showstopper.

@rkeithhill
Copy link
Contributor

And IMO, the param, begin, process and end blocks should not be indented.

@DarkLite1
Copy link
Author

Probably related to microsoft/vscode#3422

@rkeithhill
Copy link
Contributor

Hmm, I cannot reproduce this on the 1.15 build from 7/28. Can you share your user settings for the Insider's build where you are able to repro this? Also, if there are any workspace settings, share those as well.

@DarkLite1
Copy link
Author

DarkLite1 commented Aug 1, 2017

So after testing this again with the latest insider build on 1/08 I've noticed the following:

  • Select the test code above, press CTRL + C and CTRL + V in VS Code. The result is that when the code is pasted it gets indented which breaks the here string. When doing CTRL + V in the PowerShell ISE, with the same code in memory, the code is not indented and works/looks fine:

image
image

  • A change between the original reported bug is that copying code from within VS Code, for instance from the left open file to the right, does preserve the formatting correctly now.

User settings:
image

Workspace settings:
image

When running Reindent Lines as stated in #977 the problem is clearly visible.

@rkeithhill
Copy link
Contributor

Thanks for the settings info. Now I can repro the issue. I couldn't repro before because I have this setting:

	"editor.formatOnPaste": true

which apparently fixes the issue. So for now, perhaps use that as a work-around?

@DarkLite1
Copy link
Author

DarkLite1 commented Aug 2, 2017

Thx Keith, good catch! It's actually weird, because according to your findings, if "editor.formatOnPaste is set to false or it's totally absent as in my case, it shouldn't do any formatting at all.

So yes, I believe setting this is a valid workaround. However, it's still a bug and should be fixed internally at some point. I'm sure others will run into the same issue. Thx again for the good investigation, now where is that thumbs up icon? ;)

@daviwil
Copy link
Contributor

daviwil commented Aug 14, 2017

In VS Code 1.15.0, they've turned on editor.autoIndent on by default (it used to be off by default). This seems to be the culprit: when I turn off that setting the code gets pasted correctly. VS Code seems to be deciding that anything inside of the function's curly braces should be indented so it incorrectly chooses to indent the here string. Not sure if there's anything we can do about that in the short term but I'll look into it in the future.

@daviwil daviwil added this to the Future milestone Aug 14, 2017
@daviwil daviwil added Area-General Bug: VS Code Bugs in VS Code itself. and removed Needs-Repro-Info labels Aug 14, 2017
@DarkLite1
Copy link
Author

Thx for the feedback @daviwil I'd rather not mess with custom settings because I think this should indeed be handled by the editor in all cases. So code awareness might be needed to make this work properly. Thank you for putting this on the agenda, as it might play for other languages too.

@DarkLite1
Copy link
Author

Tested this today again in the newest insiders build:

Version 1.24.0-insider
Commit 2404210629c744e6237a14d7b5fa852e24c6e898
Date 2018-05-04T08:10:40.288Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

When user settings does not contain "editor.formatOnPaste": true. the problem with copy pasting the code is still present. The here string is incorrectly pasted.

@DarkLite1
Copy link
Author

Duplicate with #1517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: VS Code Bugs in VS Code itself.
Projects
None yet
Development

No branches or pull requests

3 participants