|
2 | 2 |
|
3 | 3 | [](https://github.com/python-rope/pylsp-rope/actions/workflows/run-test.yml) |
4 | 4 | [](https://codecov.io/gh/python-rope/pylsp-rope) |
| 5 | +[](https://pylsp-rope.readthedocs.io/en/latest/?badge=latest) |
| 6 | +[](https://badge.fury.io/py/pylsp-rope) |
5 | 7 |
|
6 | | -Extended refactoring capabilities for Python LSP Server using |
7 | | -[Rope](https://github.com/python-rope/rope). |
| 8 | +Extended refactoring capabilities for Python LSP Server using [Rope](https://github.com/python-rope/rope). |
8 | 9 |
|
9 | | -This is a plugin for [Python LSP |
10 | | -Server](https://github.com/python-lsp/python-lsp-server), so you also need to |
11 | | -have it installed. |
| 10 | +This is a plugin for [Python LSP Server](https://github.com/python-lsp/python-lsp-server), so you also need to have it installed. |
12 | 11 |
|
13 | | -python-lsp-server already has basic built-in support for using Rope, but it's |
14 | | -currently limited to just renaming and completion. Installing this plugin adds |
15 | | -more refactoring functionality to python-lsp-server. |
16 | | - |
17 | | -## Installation |
18 | | - |
19 | | -To use this plugin, you need to install this plugin in the same virtualenv as |
20 | | -python-lsp-server itself. |
21 | | - |
22 | | -``` bash |
23 | | -pip install pylsp-rope |
24 | | -``` |
25 | | - |
26 | | -Then run `pylsp` as usual, the plugin will be auto-discovered by |
27 | | -python-lsp-server if you've installed it to the right environment. On Vim, |
28 | | -refer to [Rope in Vim or |
29 | | -Neovim](https://github.com/python-rope/rope/wiki/Rope-in-Vim-or-Neovim). For |
30 | | -other editors, refer to your IDE/text editor's documentation on how to setup a |
31 | | -language server. |
| 12 | +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. |
32 | 13 |
|
33 | 14 | ## Features |
34 | 15 |
|
35 | | -This plugin adds the following features to python-lsp-server: |
36 | | - |
37 | | -Rename: |
38 | | - |
39 | | -- implemented: variables, classes, functions (disabled by default) |
40 | | -- coming soon: modules, packages (disabled by default) |
41 | | - |
42 | | -Code Action: |
43 | | - |
44 | | -- extract method |
45 | | -- extract variable |
46 | | -- inline method/variable/parameter |
47 | | -- use function |
48 | | -- method to method object |
49 | | -- convert local variable to field |
50 | | -- organize imports |
51 | | -- introduce parameter |
52 | | -- generate variable/function/class from undefined variable |
53 | | - |
54 | | -Refer to [Rope documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst) |
55 | | -for more details on how these refactoring works. |
56 | | - |
57 | | -## Usage |
58 | | - |
59 | | -### Rename |
60 | | - |
61 | | -When Rename is triggered, rename the symbol under the cursor. If the symbol |
62 | | -under the cursor points to a module/package, it will move that module/package |
63 | | -files. |
64 | | - |
65 | | -### Extract method |
66 | | - |
67 | | -Variants: |
68 | | - |
69 | | -- Extract method |
70 | | -- Extract global method |
71 | | -- Extract method including similar statements |
72 | | -- Extract global method including similar statements |
| 16 | +- **Enhanced Rename**: Advanced cross-file renaming with Rope's refactoring engine |
| 17 | +- **Code Actions**: 12+ refactoring operations including extract method, inline, use function, and more |
| 18 | +- **Code Generation**: Create variables, functions, and classes from undefined symbols |
| 19 | +- **Import Organization**: Automatic cleanup and sorting of imports |
| 20 | +- **Local to Field**: Convert local variables to class attributes |
73 | 21 |
|
74 | | -When CodeAction is triggered and the cursor is on any block of code, extract |
75 | | -that expression into a method. Optionally, similar statements can also be |
76 | | -extracted. |
| 22 | +## Quick Start |
77 | 23 |
|
78 | | -### Extract variable |
| 24 | +### Installation |
79 | 25 |
|
80 | | -Variants: |
| 26 | +Install pylsp-rope in the same virtualenv as python-lsp-server: |
81 | 27 |
|
82 | | -- Extract variable |
83 | | -- Extract global variable |
84 | | -- Extract variable including similar statements |
85 | | -- Extract global variable including similar statements |
86 | | - |
87 | | -When CodeAction is triggered and the cursor is on a expression, extract that |
88 | | -expression into a variable. Optionally, similar statements can also be |
89 | | -extracted. |
90 | | - |
91 | | -### Inline |
92 | | - |
93 | | -When CodeAction is triggered and the cursor is on a resolvable Python variable, |
94 | | -replace all calls to that method with the method body. |
95 | | - |
96 | | -### Use function |
97 | | - |
98 | | -When CodeAction is triggered and the cursor is on the function name of a `def` |
99 | | -statement, try to replace code whose AST matches the selected function with a |
100 | | -call to the function. |
101 | | - |
102 | | -### Method to method object |
103 | | - |
104 | | -When CodeAction is triggered and the cursor is on the function name of a `def` |
105 | | -statement, create a callable class to replace that method. You may want to |
106 | | -inline the method afterwards to remove the indirection. |
107 | | - |
108 | | -### Convert local variable to field |
109 | | - |
110 | | -When CodeAction is triggered wand the cursor is on a local variable inside a |
111 | | -method, convert that local variable to an attribute. |
112 | | - |
113 | | -### Organize import |
114 | | - |
115 | | -Trigger CodeAction anywhere in a Python file to organize imports. |
| 28 | +```bash |
| 29 | +pip install pylsp-rope |
| 30 | +``` |
116 | 31 |
|
117 | | -### Introduce parameter |
| 32 | +### Basic Configuration |
118 | 33 |
|
119 | | -When CodeAction is triggered and the cursor is selecting a Python variable or |
120 | | -attribute, make that variable/attribute a parameter. |
| 34 | +Add to your LSP configuration: |
121 | 35 |
|
122 | | -### Generate code |
| 36 | +```json |
| 37 | +{ |
| 38 | + "pylsp": { |
| 39 | + "plugins": { |
| 40 | + "pylsp_rope": { |
| 41 | + "enabled": true |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
123 | 47 |
|
124 | | -Variants: |
| 48 | +### Enable Rename Support |
| 49 | + |
| 50 | +For advanced rename functionality, enable it explicitly: |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "pylsp": { |
| 55 | + "plugins": { |
| 56 | + "pylsp_rope": { |
| 57 | + "enabled": true, |
| 58 | + "rename": true |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
125 | 64 |
|
126 | | -- [x] Generate variable |
127 | | -- [x] Generate function |
128 | | -- [x] Generate class |
129 | | -- [ ] Generate module |
130 | | -- [ ] Generate package |
| 65 | +## Documentation |
131 | 66 |
|
132 | | -When CodeAction is triggered and the cursor is on an undefined Python |
133 | | -variable, generate an empty variable/function/class/module/package for that |
134 | | -name. |
| 67 | +Complete documentation is available at **[pylsp-rope.readthedocs.io](https://pylsp-rope.readthedocs.io/)** |
135 | 68 |
|
136 | | -## Configuration |
| 69 | +- **[Installation Guide](https://pylsp-rope.readthedocs.io/en/latest/installation.html)** - Setup for various editors |
| 70 | +- **[Configuration Guide](https://pylsp-rope.readthedocs.io/en/latest/configuration.html)** - Complete configuration options |
| 71 | +- **[Features Overview](https://pylsp-rope.readthedocs.io/en/latest/features.html)** - Detailed feature descriptions |
| 72 | +- **[Usage Examples](https://pylsp-rope.readthedocs.io/en/latest/usage.html)** - Practical examples |
| 73 | +- **[Troubleshooting](https://pylsp-rope.readthedocs.io/en/latest/troubleshooting.html)** - Common issues and solutions |
137 | 74 |
|
138 | | -You can enable rename support using pylsp-rope with workspace config key |
139 | | -`pylsp.plugins.pylsp_rope.rename`. |
| 75 | +## Available Refactorings |
140 | 76 |
|
141 | | -Note that this differs from the config key `pylsp.plugins.rope_rename.enabled` |
142 | | -that is used for the rope rename implementation using the python-lsp-rope's |
143 | | -builtin `rope_rename` plugin. To avoid confusion, avoid enabling more than one |
144 | | -python-lsp-server rename plugin. In other words, you should set both |
145 | | -`pylsp.plugins.rope_rename.enabled = false` and `pylsp.plugins.jedi_rename.enabled = false` |
146 | | -when pylsp-rope rename is enabled. |
| 77 | +| Category | Operations | |
| 78 | +|----------|------------| |
| 79 | +| **Extract** | Method, Variable (with similar statement support) | |
| 80 | +| **Inline** | Method, Variable, Parameter | |
| 81 | +| **Restructure** | Use Function, Method to Method Object, Local to Field | |
| 82 | +| **Generate** | Variable, Function, Class | |
| 83 | +| **Utilities** | Organize Imports, Introduce Parameter | |
| 84 | +| **Rename** | Enhanced cross-file renaming (Rope-based) | |
147 | 85 |
|
148 | 86 | ## Caveat |
149 | 87 |
|
150 | | -Support for working on unsaved document is currently experimental, but it should work. |
| 88 | +Support for working on unsaved documents is currently experimental, but it should work. |
151 | 89 |
|
152 | | -This plugin is in early development, so expect some bugs. Please report in |
153 | | -[Github issue tracker](https://github.com/python-lsp/python-lsp-server/issues) |
154 | | -if you had any issues with the plugin. |
| 90 | +This plugin is in early development, so expect some bugs. Please report in the [GitHub issue tracker](https://github.com/python-lsp/python-lsp-server/issues) if you have any issues with the plugin. |
155 | 91 |
|
156 | | -## Developing |
| 92 | +## Contributing |
157 | 93 |
|
158 | 94 | See [CONTRIBUTING.md](https://github.com/python-rope/pylsp-rope/blob/main/CONTRIBUTING.md). |
159 | 95 |
|
160 | 96 | ## Packaging status |
161 | 97 |
|
162 | 98 | [](https://repology.org/project/python:pylsp-rope/versions) |
163 | 99 |
|
164 | | -[](https://repology.org/project/python:lsp-rope/versions) |
165 | | - |
166 | 100 | ## Credits |
167 | 101 |
|
168 | | -This package was created with |
169 | | -[Cookiecutter](https://github.com/audreyr/cookiecutter) from |
170 | | -[python-lsp/cookiecutter-pylsp-plugin](https://github.com/python-lsp/cookiecutter-pylsp-plugin) |
171 | | -project template. |
| 102 | +This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) from [python-lsp/cookiecutter-pylsp-plugin](https://github.com/python-lsp/cookiecutter-pylsp-plugin) project template. |
0 commit comments