Skip to main content

Extended refactoring capabilities for Python LSP Server using Rope.

Project description

pylsp-rope

Tests

Extended refactoring capabilities for Python LSP Server using Rope.

This is a plugin for Python LSP Server, so you also need to have it installed.

python-lsp-server already has basic built-in support for using Rope, but it's currently limited to just renaming and completion. Installing this plugin adds more refactoring functionality to python-lsp-server.

Installation

To use this plugin, you need to install this plugin in the same virtualenv as python-lsp-server itself.

pip install pylsp-rope

Then run pylsp as usual, the plugin will be auto-discovered by python-lsp-server if you've installed it to the right environment. On Vim, refer to Rope in Vim or Neovim. For other editors, refer to your IDE/text editor's documentation on how to setup a language server.

Configuration

There is no configuration yet.

Features

This plugin adds the following features to python-lsp-server:

  • extract method (codeAction)
  • extract variable (codeAction)
  • inline method/variable/parameter (codeAction)
  • use function (codeAction)
  • method to method object (codeAction)
  • convert local variable to field (codeAction)
  • organize imports (codeAction)
  • introduce parameter (codeAction)
  • generate variable/function/class from undefined variable (codeAction)
  • more to come...

Refer to Rope documentation for more details on how these refactoring works.

Usage

Extract method

Variants:

  • Extract method
  • Extract global method
  • Extract method including similar statements
  • Extract global method including similar statements

When CodeAction is triggered and the cursor is on any block of code, extract that expression into a method. Optionally, similar statements can also be extracted.

Extract variable

Variants:

  • Extract variable
  • Extract global variable
  • Extract variable including similar statements
  • Extract global variable including similar statements

When CodeAction is triggered and the cursor is on a expression, extract that expression into a variable. Optionally, similar statements can also be extracted.

Inline

When CodeAction is triggered and the cursor is on a resolvable Python variable, replace all calls to that method with the method body.

Use function

When CodeAction is triggered and the cursor is on the function name of a def statement, try to replace code whose AST matches the selected function with a call to the function.

Method to method object

When CodeAction is triggered and the cursor is on the function name of a def statement, create a callable class to replace that method. You may want to inline the method afterwards to remove the indirection.

Convert local variable to field

When CodeAction is triggered wand the cursor is on a local variable inside a method, convert that local variable to an attribute.

Organize import

Trigger CodeAction anywhere in a Python file to organize imports.

Introduce parameter

When CodeAction is triggered and the cursor is selecting a Python variable or attribute, make that variable/attribute a parameter.

Generate code

Variants:

  • Generate variable
  • Generate function
  • Generate class
  • Generate module
  • Generate package

When CodeAction is triggered and the cursor is on an undefined Python variable, generate an empty variable/function/class/module/package for that name.

Caveat

Support for working on unsaved document is currently experimental.

This plugin is in early development, so expect some bugs. Please report in Github issue tracker if you had any issues with the plugin.

Developing

See CONTRIBUTING.md.

Packaging status

Packaging status

Packaging status

Credits

This package was created with Cookiecutter from python-lsp/cookiecutter-pylsp-plugin project template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylsp-rope-0.1.13.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

pylsp_rope-0.1.13-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pylsp-rope-0.1.13.tar.gz.

File metadata

  • Download URL: pylsp-rope-0.1.13.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for pylsp-rope-0.1.13.tar.gz
Algorithm Hash digest
SHA256 c314d190f439edc158d4ad27e58a5a9e678c31ae87027a0a7c25126137accff8
MD5 ec25e9a0895a3b16cf1f31cad8623d04
BLAKE2b-256 0b0bff45c4594973003b8e41ad9294cd574236a05d1266d6ef2bc189d38d0506

See more details on using hashes here.

File details

Details for the file pylsp_rope-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: pylsp_rope-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for pylsp_rope-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f67d8783b30de491eb562dc88b3587507c17dbb57eccfdbf575bcefeafda4b
MD5 ca19b285298a7b48e90d0f6b1fc3e42e
BLAKE2b-256 adb659b3d070fb27150b062e7fe14788870f0856a58739fa09b89f52e6470568

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page