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

Feature: rename #14

Closed
1 of 4 tasks
lieryan opened this issue Sep 26, 2022 · 5 comments · Fixed by #15
Closed
1 of 4 tasks

Feature: rename #14

lieryan opened this issue Sep 26, 2022 · 5 comments · Fixed by #15

Comments

@lieryan
Copy link
Member

lieryan commented Sep 26, 2022

  • Implement lsp_rename() #15
  • rename should be toggleable with a config
  • create PR to remove rename from pylsp core
  • pylsp core should have optional dependency on pylsp-rope to add support for rope-based rename
@italovieira
Copy link

Does this also include rename modules (and moving files if necessary)?

@lieryan
Copy link
Member Author

lieryan commented Nov 23, 2023

rope alread internally supports moving modules using rename, but I hadn't figured out how moving files work in lsp protocol yet. That should be fairly easy, but I just hadn't got the chance to look at it yet, but yes, once this is implemented, rename should support moving files as well.

@tkrabel
Copy link

tkrabel commented Dec 24, 2023

@lieryan any progress on this? Happy to help!

@lieryan
Copy link
Member Author

lieryan commented Dec 24, 2023

I have created a work-in-progress PR for this some time ago but had not had the chance to finish it. It was basically just porting the pylsp core's implementation of rope_rename into here. I'm not currently actively working on it so feel free to either pick up the PR and improve on it, or to restart the effort from fresh instead.

Mainly the PR hasn't really been tested on how it interacts if rope rename feature is also enabled in pylsp core. Ideally I think there shouldn't be two separate implementation of rope between pylsp core and pylsp-rope, so removing rope support out of core and into pylsp-rope might be something we want to explore in the future, but this will be something that will need to be coordinated with core pylsp maintainers.

However, in the mean time, if we implement rename in pylsp-core, it's going to be confusing if the user accidentally enabled two separate implementations of rename rope. I think installing pylsp-rope should probably just force disable pylsp core's rename. There's some thinking that needs to be done to plan such transition, if it's even desirable to merge the implementations.

@HAOCHENYE
Copy link

HAOCHENYE commented Aug 19, 2024

This might be a silly question... How should I use the rename file/rename module functionality? For example, if I have two files a.py and b.py:

a.py

a = 1

b.py

from .a import a

Now, I want to rename a.py to something like c.py, and I want the code in b.py to automatically update to import a from c.py.

I'm not sure how to configure my LSP client for this... For renaming variables, the following configuration works fine:

{
  "neovim/nvim-lspconfig",
  ---@class PluginLspOpts
  opts = {
    ---@type lspconfig.options
    servers = {
      -- pyright will be automatically installed with mason and loaded with lspconfig
      pylsp = {
        cmd = { "pylsp", "--verbose", "--log-file", "/tmp/pylsp-log.txt" },
        plugins = {
          pylsp_rope = { rename = true },
          rope_rename = { enabled = false },
          jedi_rename = { enabled = false },
        },
        on_attach = function(client, bufnr)
            vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', { noremap = true, silent = true })
        end,
      },
    },
  },
},

However, I'm not sure how to perform a rename file operation. Any guidance would be appreciated.

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

Successfully merging a pull request may close this issue.

4 participants