7 ms·
Would’ve been easy with fastmod: https://github.com/facebookincubator/fastmod https://github.com/facebookincubator/fastmod
by desbo 2y ago
Would’ve been easy with fastmod: https://github.com/facebookincubator/fastmod https://github.com/facebookincubator/fastmod
- westurner 2y 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 https://github.com/Instagram/LibCST docs: https://libcst.readthedocs.io/en/latest/ 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/26e9007ebc2de256b0b3deeda051772d 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#background 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 2y agoVim python-mode: https://github.com/python-mode/python-mode/blob/e01c27e8c17b3af2b9df7f6fc5a8a44afc3ad020/doc/pymode.txt#L556 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 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 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 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 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-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#_rename-symbol 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
- morningsam 2y agoBut does Rope understand pytest fixtures? I doubt it, but would be happy to be proven wrong.
- westurner 2y agoYeah, there `sed` and `git diff` with one or more filenames in a variable might do. Because pytest requires a preprocessing step, renaming fixtures is tough, and also for jupyter notebooks %%ipytest is necessary to call functions that start with test_ and upgrade assert keywords to expressions; e.g `assert a == b, error_expr` is preprocessed into `assertEqual(a,b, error_expr)` with an AssertionError message even for comparisons of large lists and strings.