Skip to content

Feature: rename #14

Closed
Closed

Description

@lieryan
  • 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

Activity

  1. italovieira commented on Nov 20, 2023

    @italovieira

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

  2. lieryan commented on Nov 23, 2023

    @lieryan
    MemberAuthor

    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.

  3. tkrabel commented on Dec 24, 2023

    @tkrabel

    @lieryan any progress on this? Happy to help!

  4. lieryan commented on Dec 24, 2023

    @lieryan
    MemberAuthor

    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.

  5. HAOCHENYE commented on Aug 19, 2024

    @HAOCHENYE

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions