Giter VIP home page Giter VIP logo

pyright-langserver-for-pycharm's Introduction

Pyright Language Server for PyCharm Professional

Build Version Rating Downloads

Pyright language server integration for PyCharm Professional.

This plugin acts as a bridge between the Pyright language server and the experimental LSP API added in PyCharm Professional 2023.2 to give you annotations about your code as you edit your Python files.

Note: If you use PyCharm Community, install the Pyright plugin instead.

Usage

Go to Settings | Tools | Pyright LS (Global) / Pyright LS (Project) and set the path to your Pyright language server executable. It is typically named pyright-langserver/pyright-python-langserver.

(Not sure what this means? See the docs for more information.)

You might need to reopen your files or restart the IDE for the files to be recognized by the language server.

Logging

You are strongly encouraged to enable logging. This will allow corresponding logs to be recorded in idea.log for further analysis should a problem arises.

Add the following line to the Help | Diagnostic Tools | Debug Log Settings panel:

#com.intellij.platform.lsp

Installation

This plugin is available on the Marketplace. You can also download the ZIP files manually from the Releases tab or the Actions tab and follow the instructions described here.

Currently supported versions: 2024.1 (build 241.14494.241) - 2024.2.* (build 242.*).

Credits

Most of the code is derived from @koxudaxi/ruff-pycharm-plugin. It is such a fortune that that plugin does almost the same thing and is also written in Kotlin, and hence easily understandable.

The SVG and PNG logos are derived from the README image of the @microsoft/pyright repository, generated using Inkscape's autotrace feature.

Some other files are based on or copied directly from @JetBrains/intellij-platform-plugin-template.

pyright-langserver-for-pycharm's People

Contributors

arvidfm avatar dependabot[bot] avatar insyncwithfoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

arvidfm quilt-ai

pyright-langserver-for-pycharm's Issues

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.

image

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:

  1. Clone vs-code-cython into your platform's <VS Code extensions folder>.
  2. Follow the vscode-cython source installation instructions up to Building source, but run npm run build:cli:dev (instead of npm run build:extension).
  3. Make pyright._utils::install_pyright return pathlib.Path("<VS Code extensions folder>/vs-code-cython/cyright/packages/pyright")
  4. Set the Pyright executable as usual.

Render restructured/"sphinx" docstrings

Feature or enhancement

First - thanks or creating this plugin!

I noticed that docstrings which use the restructured/"sphinx" format is not rendered properly in the quick doc dialog. It would be nice if they where.

image

Proposed solution

microsoft/pylance-release#5363 is maybe related? But the plugin could still render based on the raw text. Ideally the plugin would pass the docstring through pycharms own renderer which respect the project setting for docstring format, but I have no idea how hard that would be to implement

`Literal` autocompletion inserts an extra quote

What happened?

When I accept an autocompleted Literal value it inserts an ' or " at the end

Steps to reproduce

Command = Literal['first', 'second']
s: Command = '' # accept the autocomplete with the caret inside the quotes - Result: 'first''

Relevant log output or stack trace

No response

Operating system

None

Pass Sources Root folders as LSP workspaceFolders

Pyright only supports pyrightconfig.json files at the root of an LSP workspace. I'd like pyright to recognize pyrightconfig.json files in Source Root folders. This plugin currently uses ProjectWideLspServerDescriptor:

internal class PyrightLSDescriptor(
project: Project,
private val executable: Path
) : ProjectWideLspServerDescriptor(project, PRESENTABLE_NAME) {

I think we can instead inherit

LspServerDescriptor(project, PRESENTABLE_NAME, *project.modules.flatMap { m -> ModuleRootManager.getInstance(m).sourceRoots.asIterable() }.toTypedArray())

allow language server settings to be configured in the project

Feature or enhancement

these settings are currently only configurable globally, but it would be useful if they could be configured in the project:

image

Proposed solution

support the same settings available globally in the project as well

Alternatives considered

No response

Additional context

i want to disable pycharm's awful type checking in favor of pyright's for my team, which ideally would include enabling hover and completion support from the language server. ideally my team shouldn't have to manually configure this themselves and i can instead just commit a config file

Add parentheses to autocomplete

Feature or enhancement

The plugin currently completes e.g. functions without adding parentheses. This is more in line with VSCode than Jetbrains IDEs.

Proposed solution

Align it with how the native PyCharm autocomplete works. E.g. complete "my_func()" instead of "my_func"

Alternatives considered

No response

Additional context

No response

use the same plugin for both pycharm community and professional versions

Feature or enhancement

the ruff plugin seems to conditionally use the language server if the user is on pycharm professional: https://github.com/koxudaxi/ruff-pycharm-plugin/blob/befe74aa4558a348c968f66b64e9374fe6b38a6b/resources/META-INF/plugin.xml#L9

Proposed solution

Alternatives considered

No response

Additional context

i work in a team where some users have community and some users have professional. i want to specify this plugin in the "required plugins" list for the project so that users are prompted to install it, but that won't work because depending on which version of pycharm they're using, they'll need to install a different plugin

Installation issues / suggestions

Thank you for this! I have gotten it to work and it is awesome. Here are some of the issues I had getting started:

  1. I do not see this plugin in the marketplace. I installed from source as you describe in the README
  2. I was sure about setting up pyright-langserver. It would be helpful to add something like the following to the README:
    1. brew install pyright (pip or conda would also work)
    2. point Settings | Tools | Pyright LS (Global) / Pyright LS (Project) to, e.g. /opt/homebrew/bin/pyright-langserver (or the pip installation

save settings as configuration files in `.idea` that can be committed

Feature or enhancement

my project uses pyright, but currently everyone in the team needs to manually configure the pycharm plugin themselves to work with our project

Proposed solution

save the settings to a config file inside the .idea folder, which can be committed so that others in my team automatically get the correct settings

Alternatives considered

No response

Additional context

we use basedpyright (a fork of pyright), so we need to configure a different project executable. ideally this should only need to be done once and the config file can be committed, instead of each user having to configure it themselves

image

LSP Pyright | Terminated

What happened?

For some reason {} Pyright shows Terminated status.

CleanShot 2024-05-06 at 14 41 41@2x

I am able to parse file directly using executable:

/Users/Silver/.pyenv/shims/pyright feeds/types.py
/Users/Silver/Projects/sandbox/jetstream/feeds/types.py
  /Users/Silver/Projects/sandbox/jetstream/feeds/types.py:4:13 - information: Type of "x" is "Literal[4]"
0 errors, 0 warnings, 1 information

Steps to reproduce

I believe I've followed the installation instructions.

my pyproject.toml:

[tool.pyright]
include = ["."]
pythonVersion = "3.12"
typeCheckingMode = "strict"

I did:

  • install pyright executable
  • setup pyproject.toml
  • install LSP version of the plugin
  • configured plugin

CleanShot 2024-05-06 at 14 40 18@2x
CleanShot 2024-05-06 at 14 40 41@2x

Relevant log output or stack trace

No response

Operating system

macOS

Import path instead of Auto-Import

Feature or enhancement

The auto import says "Auto-Complete", whereas the native PyCharm import lists the path (e.g. src.utils). When importing something that can be imported from several files that's unpractical. When selecting it a box pops up that lists where the import is coming from but that's a way slower UX than seeing it directly in the autocomplete popup.

Proposed solution

Put the import path directly in the autocomplete popup instead of "Auto-Import".

Alternatives considered

No response

Additional context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.