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

"Rename Symbol" deletes some content when one of the renames is last line in file #1340

Closed
nkinkade opened this issue Apr 7, 2018 · 2 comments
Labels
bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@nkinkade
Copy link

nkinkade commented Apr 7, 2018

Environment data

  • VS Code version: 1.22.1
  • Extension version: 2018.3.1
  • OS and version: Debian / Buster (testing)
  • Python version: 2.7.14
  • Type of virtual environment used: N/A
  • Relevant/affected Python packages and their versions:
    • rope 0.10.7

Actual behavior

When one of the symbols being renamed is on the last line of the file, that line disappears after renaming the symbol. Take this tiny file for example:

def testme(num):
    x = num + 2
    return x

print testme(2)

If you select testme in the function and press F2, then rename the function to, for example, testyou and press Enter. The last line in the file (print testme(2)) vanishes. I've verified that putting a newline character at the end of the last line fixes the issue. It appears to have something do with one of the symbols being renamed being on the last line of the file.

Expected behavior

I would have expected the line print testme(2) to turn into print testyou(2), instead of the line disappearing.

Steps to reproduce:

  1. Create a file with the above minimal content, making sure that there are no newline characters after the last line.
  2. Select testme in the function.
  3. Press F2.
  4. Rename the function to whatever you want.
  5. Press Enter.
  6. The last line disappears from the file.

Logs

Output for Python in the Output panel:

It is empty. Well, some git commands show up, but it seems highly unlikely they are relevant.

> git status -z -u
> git symbolic-ref --short HEAD
> git rev-parse master
> git rev-parse --symbolic-full-name master@{u}
fatal: no upstream configured for branch 'master'
> git for-each-ref --format %(refname) %(objectname) --sort -committerdate
> git remote --verbose

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

None. There is no output at all in the Console of the Developer Tools.

Comments

While looking to see if there were any other issues filed for this problem, I did come across issue #52, in which the last comment (from puzzler10) seems to be related to this issue. They were asked to create a separate issue, but I can't find any issues opened by puzzler10, so I assume the person never did.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug feature-refactoring labels Apr 8, 2018
@brettcannon brettcannon added x-rope and removed x-rope labels May 2, 2018
@brettcannon brettcannon added this to the May 2018 milestone May 4, 2018
@brettcannon
Copy link
Member

I can verify this seems to be an issue on our end and not with Rope:

# Creating a project
from rope.base.project import Project
project = Project('.')

# Working with files to create a module
code = """def testme(num):
    x = num + 2
    return x

print(testme(2))"""
mod1 = project.root.create_file('mod1.py')
mod1.write(code)

# Performing rename refactoring on `mod1.a_var`
from rope.refactor.rename import Rename
changes = Rename(project, mod1, 4).get_changes('tested')
project.do(changes)
print(repr(mod1.read()))  # 'def tested(num):\n    x = num + 2\n    return x\n\nprint(tested(2))'

@DonJayamanne
Copy link

Closing as a duplicate of #695

@lock lock bot locked as resolved and limited conversation to collaborators Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants