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

getPasteEdits returns wrong range for primary edit #58936

Open
mjbvz opened this issue Jun 19, 2024 · 0 comments Β· May be fixed by #59369
Open

getPasteEdits returns wrong range for primary edit #58936

mjbvz opened this issue Jun 19, 2024 · 0 comments Β· May be fixed by #59369
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jun 19, 2024

πŸ”Ž Search Terms

  • getPasteEdits
  • Paste with imports

πŸ•— Version & Regression Information

5.6.0-dev.20240619

⏯ Playground Link

No response

πŸ’» Code

a.ts

export interface Foo { }

export const foo: Foo = {}
  1. On line 3, copy Foo
  2. Paste into a file b.ts at the | (notice the blank lines before and after):
|

πŸ™ Actual behavior

The returned edits are at the same location:

    {"seq":0,"type":"response","command":"getPasteEdits","request_seq":166,"success":true,"performanceData":{"updateGraphDurationMs":1.7999577522277832},"body":{"edits":[{"fileName":"/Users/matb/projects/sandbox/b.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { Foo } from \"./a\";\n"},{"start":{"line":1,"offset":2},"end":{"line":1,"offset":2},"newText":"Foo"}]}],"fixId":"providePostPasteEdits"}}
Info 567  [13:03:44.720] request:
    {
      "seq": 167,
      "type": "request",
      "command": "updateOpen",
      "arguments": {
        "changedFiles": [
          {
            "fileName": "/Users/matb/projects/sandbox/b.ts",
            "textChanges": [
              {
                "newText": "import { Foo } from \"./a\";\n",
                "start": {
                  "line": 1,
                  "offset": 1
                },
                "end": {
                  "line": 1,
                  "offset": 1
                }
              },
              {
                "newText": "Foo",
                "start": {
                  "line": 1,
                  "offset": 1
                },
                "end": {
                  "line": 1,
                  "offset": 1
                }
              }
            ]
          }
        ],
        "closedFiles": [],
        "openFiles": []
      }
    }

This causes VS Code to place the cursor incorrectly after applying the edit

πŸ™‚ Expected behavior

There should be two edits: the import one on line 1 and the normal paste on line 2

Additional information about the issue

No response

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Jun 20, 2024
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.6.0 milestone Jun 20, 2024
@navya9singh navya9singh linked a pull request Jul 19, 2024 that will close this issue
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants