vscode-jupyter-python
vscode-jupyter-python copied to clipboard
Identifying decorator
First thanks for creating this package! It works perfectly most of the time, but I found a problem in identifying decorators for functions. An illustrative example would be like
@ti.kernel
def solver_ti(u):
pass
The package would recognize @ti.kernel
as a single sentence instead of the decorator of the function.
This particular decorator is from taichi, but I guess the other ones like Numba will face the same issue.
Yeah this is mentioned in the readme as a future TODO.
For most code we can expand the selection downward either looking for lines with additional indentation or for specific keywords. That naive approach won't work here, because if we added def
as a keyword, then any selection would propagate downwards for any sequence of function definitions.
The solution https://github.com/nikitakit/hydrogen-python chose is to implement expanding selections upward as well as downward. So if your cursor is on the def
line, it'll search upwards for any lines at the same indentation starting with @
.
A PR is welcome for this. Otherwise I'll probably implement it next time I use a decorator 😄