vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.74k stars 593 forks source link

Cursor jumping to the end of file when format the *.vue file #841

Open transtone opened 6 years ago

transtone commented 6 years ago

macos-10.13.5 vscode-1.25.1

like these issues: https://github.com/Microsoft/vscode/issues/47422 https://github.com/Microsoft/vscode/issues/47666 https://github.com/Microsoft/vscode/issues/47664

use vue(vetur-0.12.5), cursor jumps to the end of file on format, use html mode not.

sometimes happen, not always.

octref commented 6 years ago

Does this still happen? If so, can you give me a vue file and tell me the position where you are running the formatting operation?

Also, if you changed the formatter configuration, please paste that too.

danikane commented 5 years ago

I get that too. Looks random, but I bet it isn't. VS Code 1.29.1 Vetur 0.14.3

.prettierrc

{
  "jsxBracketSameLine": false,
  "singleQuote": true,
  "printWidth": 140
}

Also:

{
  "terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
  "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
  "git.enableSmartCommit": true,
  "vetur.format.defaultFormatter.html": "prettyhtml",
  "files.autoSaveDelay": 1000,
  "editor.tabSize": 2,
  "editor.wordWrap": "on",
  "editor.wordWrapColumn": 140,
  "files.autoSave": "afterDelay",
  "javascript.updateImportsOnFileMove.enabled": "always",
  "files.eol": "\n"
}

Vue file is here: https://gist.github.com/danikane/aada96eb730ef29722a2f693c150a196

When I hit a tab after the closing arrow of the q-item tag on row 139 and then format, the cursor jumps right to beginning of the closing on row 246.

I removed code in rows 185 - 240 (q-card-main) and now that behavior's gone. What the actual f ... Frankly I see no logic. 😄 Thank you for Vetur! I hope this can provide some insight.

octref commented 5 years ago

The problem is upstream. When you send a large formatting edit like Vetur does (replace the whole file's content with new content), VS Code will try to "compute smallest diff for re-rendering". When VS Code fails to do so, it'll move cursor to the bottom.

Would it make more sense to let the cursor go to first line in those cases? I can open an upstream issue for that.

Fusseldieb commented 5 years ago

I have this too... As soon as I format a .vue file, it jumps to the end of the whole document. It's really annoying. It can be just a semicolon and it jumps to the bottom.

At least make it stay on the same line then, please.

intijk commented 5 years ago

I meet this pretty often, could you @octref point to the upstream vscode issue?

About what you said

The problem is upstream. When you send a large formatting edit like Vetur does (replace the whole file's >content with new content), VS Code will try to "compute smallest diff for re-rendering". When VS Code >fails to do so, it'll move cursor to the bottom.

Is this the real reason caused that? I tried with one vue file with over 400 lines. I formatted once, and I change one line in the middle, for example, add one character. Shouldn't compute smallest diff for re-rendering correctly locate to this new added character? But in such a case, my vetur still lead me to the end of the file.