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

Paste into editor with format on paste removes pasted word #48006

Closed
bpasero opened this issue Feb 8, 2022 · 9 comments · Fixed by #48921
Closed

Paste into editor with format on paste removes pasted word #48006

bpasero opened this issue Feb 8, 2022 · 9 comments · Fixed by #48921
Assignees
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Fix Available A PR has been opened for this issue VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone

Comments

@bpasero
Copy link
Member

bpasero commented Feb 8, 2022

TS Template added by @mjbvz

TypeScript Version: @4.7.0-dev.20220222

Search Terms

  • Format on paste
  • format

I have auto save enabled and format on paste. When I paste a string into a another string, that string is removed. See

Recording 2022-02-08 at 12 51 17

//cc @sandy081

@hediet hediet added the Bug A bug in TypeScript label Feb 9, 2022
@hediet
Copy link
Member

hediet commented Feb 21, 2022

I cannot reproduce this on windows. Up for a quick meeting?

@hediet hediet added the Needs More Info The issue still hasn't been fully clarified label Feb 21, 2022
@bpasero
Copy link
Member Author

bpasero commented Feb 21, 2022

Yes

@bpasero bpasero added typescript and removed Needs More Info The issue still hasn't been fully clarified labels Feb 21, 2022
@bpasero bpasero assigned mjbvz and unassigned hediet Feb 21, 2022
@bpasero
Copy link
Member Author

bpasero commented Feb 21, 2022

Henning figured out that this is a bug in the typescript formatter and it reproduces as simple as with this:

const x = f('aaaa', 'aaaa').x()

When you try to paste the aaaa into the second location.

@mjbvz mjbvz transferred this issue from microsoft/vscode Feb 23, 2022
@mjbvz mjbvz removed their assignment Feb 23, 2022
@mjbvz mjbvz removed Bug A bug in TypeScript typescript labels Feb 23, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Feb 23, 2022

Here's the format request I see pasting into the first argument in the above example:

[Trace  - 00:27:06.888] <syntax> Sending request: format (5). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "/Users/matb/projects/san/index.ts",
    "line": 1,
    "offset": 14,
    "endLine": 1,
    "endOffset": 18
}
[Trace  - 00:27:06.919] <syntax> Response received: format (5). Request took 32 ms. Success: true 
Result: [
    {
        "start": {
            "line": 1,
            "offset": 13
        },
        "end": {
            "line": 1,
            "offset": 23
        },
        "newText": ""
    }
]

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 23, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 23, 2022
@RyanCavanaugh
Copy link
Member

Repro explained:

Turn on Format on Paste, then write

const a = f('').x();

Put the caret between the quotes and paste bar (or anything really?) and the new text is

const a = f().x();

instead of

const a = f('bar').x();

@RyanCavanaugh RyanCavanaugh added the Domain: Formatter The issue relates to the built-in formatter label Feb 23, 2022
@mjbvz mjbvz added the VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone label Mar 8, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Mar 8, 2022

@RyanCavanaugh I'm marking this as a VSCode priority for 4.7 as we've seen a few reports of it now

@sandersn
Copy link
Member

So far, it looks like the tree walking part of the formatter doesn't correctly increment the scanner, so the end-of-tree section of the code ends up formatting ( ) instead of ( "bar".

Now I have to go understand how the tree walk works.

@sandersn
Copy link
Member

sandersn commented Apr 29, 2022

Broken in #46875, which is not surprising since that PR adds the end-of-tree section.

Edit: The tree walk was probably already incorrect, it's just the new end-of-tree code relies on it being correct.

sandersn added a commit that referenced this issue May 2, 2022
processChildNodes needs to skip processing when the node array is
outside the target range, just like processChildNode already does for a
single node.

Fixes #48006
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label May 2, 2022
sandersn added a commit that referenced this issue May 2, 2022
processChildNodes needs to skip processing when the node array is
outside the target range, just like processChildNode already does for a
single node.

Fixes #48006
@DarinDev1000
Copy link

I also have this issue on mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Fix Available A PR has been opened for this issue VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants