Skip to content

Rename symbol doesn't work in JS sometimes #31800

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

Closed
john-cj opened this issue Jun 6, 2019 · 3 comments
Closed

Rename symbol doesn't work in JS sometimes #31800

john-cj opened this issue Jun 6, 2019 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@john-cj
Copy link

john-cj commented Jun 6, 2019

(Not sure is it a bug or not.)

There are no extensions installed, just a fresh install of VS Code. The "rename symbol" fails under some circumstances.

In this JS example you can successfully rename function name foo or variable name name to something different:

function foo() {
    var name = "John", surname = "Doe";
    if (name == "John") {
        alert("The full name is " + name + " " + surname);
    }
}

// TODO: Change function name from foo to
//       something better!
foo()

However, if you remove the function:

  • if you put the cursor on the first occurrence of name and then try to rename this symbol - it will be renamed only this occurrence
  • if you put the cursor on the second occurrence of name - it will be a message "You cannot rename elements that are defined in the standard TypeScript library"
var name = "John", surname = "Doe";
if (name == "John") {
    alert("The full name is " + name + " " + surname);
}

vscode

Version: 1.35.0 (user setup)
Commit: 553cfb2c2205db5f15f3ee8395bbd5cf066d357d
Date: 2019-06-04T01:18:19.664Z
Electron: 3.1.8
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT ia32 6.1.7600

@vscodebot vscodebot bot assigned mjbvz Jun 6, 2019
@mjbvz mjbvz transferred this issue from microsoft/vscode Jun 6, 2019
@mjbvz mjbvz removed their assignment Jun 6, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Jun 6, 2019

This issue has the same root cause as #31783. There is a global value in the DOM typings called name conflicts with the local name. If you are working in a module this is not an issue but for global style javascript files, you hit this.

You can see this warning more easily by adding //@ts-check to the top of the file to enable type checking in it.

Moving upstream to see if the UX can be improved for this

@fatcerberus
Copy link

At first I was going to say "Shouldn't the global name be shadowed?" but then I realize that in this case it is the global name because top-level var puts things on the global object...

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 13, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants