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

Refactoring in VS Code destroys and/or falsifies .vue file! #1273

Closed
h-h-h-h opened this issue May 7, 2022 · 9 comments
Closed

Refactoring in VS Code destroys and/or falsifies .vue file! #1273

h-h-h-h opened this issue May 7, 2022 · 9 comments

Comments

@h-h-h-h
Copy link

h-h-h-h commented May 7, 2022

This is a very serious bug! It may also change logic without the developer noticing.

I tried to write specific steps for reproduction and at first the bug was reproducible. But as I went, the bug disappeared and I couldn't understand why.

I had a file MyComposable.ts with code like this:

export type MyComposable { foo: number };
export function useMyComposable(): MyComposable { /*...*/ }

...and a file MyComponent.vue that used the composable:

<!--
bla
bla
bla
-->

<!--
foo
bar
-->

<script setup lang="ts">
import { useMyComposable } from "MyComponent.vue";

const myComposable = useMyComposable();

// [Code with `if`, `for` and comments referencing `myComposable.foo`.]
</script>

<template></template>

When I refactored foo from type MyComposable in MyComposable.ts by renaming it with F2, the spots in MyComponent.vue where the new name was inserted were wrong, they were shifted into different lines, between unrelated if and comment parts! When I removed the empty line in MyComponent.vue between --> and <!-- at the time the bug didn't yet disappear, the inserting spots were influenced (shifted differently). At some point, the problem also happened when I renamed myComposable from MyComponent.vue.

Then, I did some things like duplicating MyComposable.vue into a new file Foo.vue. In that file, a new bug happened where renaming didn't work at all and VS Code told me with a little bottom-right error pop-up: "Rename failed to apply edits". I don't exactly remember how it all took place exactly, but I also deleted Foo.vue in VS Code, closed VS Code, renamed MyComposable.vue to Foo.vue and reopened VS Code. Then, VS Code told me with a bottom-right warning pop-up: "The 2 extension(s) below, in workspace recommendations have issues: johnsoncodehk.volar (not found in marketplace) johnsoncodehk.vscode-typescript-vue-plugin (not found in marketplace)". The still opened tab of MyComposable.vue didn't show code in my monospace font, but a little message in a proportional sans-serif font; I think it said that the file didn't exist anymore. When I opened Foo.vue, renaming also always failed with the message: "Rename failed to apply edits".

Then, the bug disappeared and the warning pop-up is now shown on every start of VS Code. The bug also wasn't reproducible anymore when going back in the bug test repository to earlier commits where the bug previously happened, also not after a fresh VS Code start with the earlier commit.

A third bug that happened some time in between the previously described actions was that I began to first mention the composable function useMyComposable(), clicked the light bulb icon and chose to add an import for it; but the import was added in an XML comment (between <!-- and -->). I could do this multiple times and every time an additional import line was added in the comment.

@yoyo837
Copy link

yoyo837 commented May 9, 2022

I keep getting this prompt but don't know why.

The 2 extension(s) below, in workspace recommendations have issues: johnsoncodehk.volar (not found in marketplace) johnsoncodehk.vscode-typescript-vue-plugin (not found in marketplace)

@yaegassy
Copy link
Collaborator

yaegassy commented May 9, 2022

@yoyo837 Please check here.

@yoyo837
Copy link

yoyo837 commented May 9, 2022

It may be related to the plugin Sync feature of vscode.
vscode is trying to install plugin with old name.

@Doeke
Copy link

Doeke commented May 9, 2022

Also keep getting johnsoncodehk.volar (not found in marketplace)

@yoyo837
Copy link

yoyo837 commented May 9, 2022

See #1273 (comment).

I fixed it. If the Sync feature of vscode is enable, please reinstall these two plugins and manually sync it once.

@suhayebh
Copy link

Sync feature of vscode

could you elaborate, not sure what steps to take

@yoyo837
Copy link

yoyo837 commented May 11, 2022

I mean https://code.visualstudio.com/docs/editor/settings-sync.

  1. Uninstall these two plugins;
  2. Make sure the synchronization succeeds once;
  3. Reinstall these two plugins;

@YoRolling
Copy link

I keep getting this prompt but don't know why.

The 2 extension(s) below, in workspace recommendations have issues: johnsoncodehk.volar (not found in marketplace) johnsoncodehk.vscode-typescript-vue-plugin (not found in marketplace)

Check extensions.json in `${PROJECT_ROOT}/.vscode'. I got same warning, finally I found in there, delete them and waning went away.

@h-h-h-h
Copy link
Author

h-h-h-h commented May 22, 2022

Off topic:

@YoRolling's solution worked for me to get rid of the warning pop-up, because the problem was workspace-related. The other solutions didn't work.

On topic:

Perhaps related: While renaming a .ts file itself, I clicked the "Show Preview" button in the message box that appeared. When clicking one of the change lines with checkboxes, no matter whether for a .ts or a .vue file, the following was shown in the refactor-preview tab:

Visual Studio Code

After clicking the "Discard" button (instead of "Apply"), irritatingly I got another message box:

Update imports for '[...].ts'?

[No] [Yes] [Always automatically update imports] [Never automatically update imports]

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

6 participants