Add line marker to Python file
Given specific line numbers I want to be able to add line markers to those lines to indicate instructions to the user. I've seen examples of getting the PSI files for Java files, but I haven't seen any examples for Python. Is this supported or is there a work around to get the PSI elements of a python file so that a line marker can be added?
Please sign in to leave a comment.
You can get the PSI files for Python files the same way you do it for Java files. If your VirtualFile or your Document is a Python file, then getting a PsiFile for it will result in a PyFile object.
You can also take a look at the source code of PyCharm that contains lots of examples about working with Python-specific PSI elements (they usually have the Py* prefix). You can also find several Python-specific line marker providers if you search for Py*LineMarkerProvider using Navigate | Class menu.
See also the list of PyCharm API modules. We've recently renamed many modules in the IntelliJ platform to utilize a hierachical structure, see this blog post.