pyright-langserver-for-pycharm
pyright-langserver-for-pycharm copied to clipboard
Is it possible to recognise file extensions other than `.py` and `.pyi`?
Feature or enhancement
Is it possible for this plugin to recognise other file extensions apart from just .py and .pyi to communicate with pyright-langserver? If it were, a thin wrapper over pyright-python will allow use of this plugin for adventurous Pyright forks developed for non-Python languages.
Proposed solution
Expose ability for user specification of files or file extensions in the Pyright LS settings to communicate with pyright-langserver.
Alternatives considered
No response
Additional context
I was experimenting and managed to get Cython type checking, code completion, and code navigation working by pointing the Project executable to a modified pyright-langserver which launched vscode-cython.
The result worked surprisingly well, apart from the issue that Cython files themselves (.pyx, .pxd, .pxi) weren't recognised by the LSP, so you could only get the benefits by writing Cython in .py files. Cython syntax is, of course, illegal in Python, so IntelliJ IDEs will complain; it'd be great if it were possible to make this plugin recognise user-specified file extensions.
Note that include/exclude path settings in a pyright configuration file is not currently possible with vscode-cython, so if that's the only way to make this LSP plugin work, I apologise for posting this in the wrong place.
A way forward for IntelliJ's stagnant support of Cython would be much appreciated. Better Cython support in IntelliJ IDEs has been a feature in demand for years (see e.g. Cython support - CLion, which, unlike PyCharm, doesn't even have basic support).
In case anyone wanted to reproduce this:
- Clone
vs-code-cythoninto your platform's<VS Code extensions folder>. - Follow the vscode-cython source installation instructions up to Building source, but run
npm run build:cli:dev(instead ofnpm run build:extension). - Make
pyright._utils::install_pyrightreturnpathlib.Path("<VS Code extensions folder>/vs-code-cython/cyright/packages/pyright") - Set the Pyright executable as usual.
Is it possible for this plugin to recognise other file extensions apart from just
.pyand.pyito communicate withpyright-langserver?
It is. Simple and straightforward, even. Here's how the language server knows that it should be enabled for .py files:
https://github.com/InSyncWithFoo/pyright-langserver-for-pycharm/blob/0e28e9ae1aa553adedecd5474323f842937cd856/src/main/kotlin/com/insyncwithfoo/pyrightls/server/PyrightLSDescriptor.kt#L55
Adding extensions is, obviously, trivial, but this should be made an optional choice. That is, a field should be added for users to configure the file extensions that they want their language server to run on. As a non-Cython user, I certainly don't want to let Pyright blow up the editor with tons of "syntax" errors in some .pyx file I happen to come across.
That said, this will be supported, but only as a nice-to-have byproduct. I'll work on a PR in a few hours (whose build should be automatically uploaded via GitHub Actions). Since I never worked with Cython, I'm relying on you to test it.
By the by, this issue is finely written. Thanks for that.
I was searching in this repo for the string ".pyi", which is probably why I didn't find that line of code. It seems that supporting user-defined extensions would allow Python users to opt-in into running the plugin against .pyi stub files too, which is a more immediate benefit.
Thank you!