top | item 41674545

(no title)

desbo | 1 year ago

Would’ve been easy with fastmod: https://github.com/facebookincubator/fastmod

discuss

order

westurner|1 year ago

> I do wish tree-sitter had a mechanism to directly manipulate the AST. I was unable to simply rename/delete nodes and then write the AST back to disk. Instead I had to use Jedi or manually edit the source (and then deal with nasty off-set re-parsing logic).

Or libCST: https://github.com/Instagram/LibCST docs: https://libcst.readthedocs.io/en/latest/ :

> LibCST parses Python 3.0 -> 3.12 source code as a CST tree that keeps all formatting details (comments, whitespaces, parentheses, etc). It’s useful for building automated refactoring (codemod) applications and linters.

libcst_transformer.py: https://gist.github.com/sangwoo-joh/26e9007ebc2de256b0b3deed... :

> example code for renaming variables using libcst [w/ Visitors and Transformers]

Refactoring because it doesn't pass formal verification: https://deal.readthedocs.io/basic/verification.html#backgrou... :

> 2021. deal-solver. We released a tool that converts Python code (including deal contracts) into Z3 theorems that can be formally verified

westurner|1 year ago

Vim python-mode: https://github.com/python-mode/python-mode/blob/e01c27e8c17b... :

> Pymode can rename everything: classes, functions, modules, packages, methods, variables and keyword arguments.

> Keymap for rename method/function/class/variables under cursor

  let g:pymode_rope_rename_bind = '<C-c>rr
python-rope/ropevim also has mappings for refactorings like renaming a variable: https://github.com/python-rope/ropevim#keybinding :

  C-c r r   :RopeRename
  C-c f     find occurrences 
https://github.com/python-rope/ropevim#finding-occurrences

Their README now recommends pylsp-rope:

> If you are using ropevim, consider using pylsp-rope in Vim

python-rope/pylsp-rope: https://github.com/python-rope/pylsp-rope :

> Finding Occurrences: The find occurrences command (C-c f by default) can be used to find the occurrences of a python name. If unsure option is yes, it will also show unsure occurrences; unsure occurrences are indicated with a ? mark in the end. Note that ropevim uses the quickfix feature of vim for marking occurrence locations. [...]

> Rename: When Rename is triggered, rename the symbol under the cursor. If the symbol under the cursor points to a module/package, it will move that module/package files

SpaceVim > Available Layers > lang#python > LSP key Bindings: https://spacevim.org/layers/lang/python/#lsp-key-bindings :

  SPC l e  rename symbol
Vscode Python variable renaming:

Vscode tips and tricks > Multi cursor selection: https://code.visualstudio.com/docs/getstarted/tips-and-trick... :

> You can add additional cursors to all occurrences of the current selection with Ctrl+Shift+L. [And then rename the occurrences in the local file]

https://code.visualstudio.com/docs/editor/refactoring#_renam... :

> Rename symbol: Renaming is a common operation related to refactoring source code, and VS Code has a separate Rename Symbol command (F2). Some languages support renaming a symbol across files. Press F2, type the new desired name, and press Enter. All instances of the symbol across all files will be renamed