Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for basedpyright #106

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ lsp-mode client leveraging [pyright](https://github.com/microsoft/pyright) and [
- `basedpyright.` / `pyright.disableOrganizeImports` via `lsp-pyright-disable-organize-imports`
- `basedpyright.` / `pyright.disableTaggedHints` via `lsp-pyright-disable-tagged-hints`
- `basedpyright.` / `python.typeCheckingMode` via `lsp-pyright-type-checking-mode`
- `basedpyright.analysis.inlayHints.variableTypes` via `lsp-pyright-basedpyright-inlay-hints-variable-types`
- `basedpyright.analysis.inlayHints.callArgumentNames` via `lsp-pyright-basedpyright-inlay-hints-call-argument-names`
- `basedpyright.analysis.inlayHints.functionReturnTypes` via `lsp-pyright-basedpyright-inlay-hints-function-return-types`
- `basedpyright.analysis.inlayHints.genericTypes` via `lsp-pyright-basedpyright-inlay-hints-generic-types`
- `python.analysis.autoImportCompletions` via `lsp-pyright-auto-import-completions`
- `python.analysis.diagnosticMode` via `lsp-pyright-diagnostic-mode`
- `python.analysis.logLevel` via `lsp-pyright-log-level`
Expand Down
32 changes: 32 additions & 0 deletions lsp-pyright.el
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,34 @@ Only available in Emacs 27 and above."
:type 'list
:group 'lsp-pyright)

(defcustom lsp-pyright-basedpyright-inlay-hints-variable-types t
"Whether to show inlay hints on assignments to variables.

Basedpyright only."
:type 'boolean
:group 'lsp-pyright)

(defcustom lsp-pyright-basedpyright-inlay-hints-call-argument-names t
"Whether to show inlay hints on function arguments.

Basedpyright only."
:type 'boolean
:group 'lsp-pyright)

(defcustom lsp-pyright-basedpyright-inlay-hints-function-return-types t
"Whether to show inlay hints on function return types.

Basedpyright only."
:type 'boolean
:group 'lsp-pyright)

(defcustom lsp-pyright-basedpyright-inlay-hints-generic-types nil
"Whether to show inlay hints on inferred generic types.

Basedpyright only."
:type 'boolean
:group 'lsp-pyright)

(defun lsp-pyright--locate-venv ()
"Look for virtual environments local to the workspace."
(or lsp-pyright-venv-path
Expand Down Expand Up @@ -228,6 +256,10 @@ Current LSP WORKSPACE should be passed in."
(,(concat lsp-pyright-langserver-command ".disableOrganizeImports") lsp-pyright-disable-organize-imports t)
(,(concat lsp-pyright-langserver-command ".disableTaggedHints") lsp-pyright-disable-tagged-hints t)
(,(concat lsp-pyright-langserver-command ".typeCheckingMode") lsp-pyright-type-checking-mode)
("basedpyright.analysis.inlayHints.variableTypes" lsp-pyright-basedpyright-inlay-hints-variable-types t)
Copy link
Contributor

@wyuenho wyuenho Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ROCKTAKEY

Does Pyright ignore settings it doesn't recognize? Have you tested this with Pyright? If this works, does Pyright make any guarantees it'll always ignore settings it doesn't recognize?

Copy link
Contributor Author

@ROCKTAKEY ROCKTAKEY Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wyuenho

As you can see the S expression, lsp-register-custom-settings does NOT associate settings with lsp-client.

In order to get configuration, each client executable server executable sends workspace/configuration request. lsp-mode send the configuration ONLY if pyright send request to get basedpyright.*

In the other word, if pyright executable should require even java section, lsp-mode pass the setting for lsp-java to pyright.

If we need the proof that this configuration does not affect pyright, we should see all lsp-client in lsp-mode, since all lsp-register-custom-settings expressions can affect pyright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In conclusion, as long as pyright do not send request to get basedpyright.*, lsp-mode never send this configuration.

Copy link
Contributor

@wyuenho wyuenho Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, just to aid my understanding, it's actually the server that sends the workspace/configuration request, not the client right? This seems to be what the latest version of the protocol requires. The server requests a section, and then the client finds that section and then respond, is this right?

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was confused. You are right. The server sends workspace/configuraiton request.

("basedpyright.analysis.inlayHints.callArgumentNames" lsp-pyright-basedpyright-inlay-hints-call-argument-names t)
("basedpyright.analysis.inlayHints.functionReturnTypes" lsp-pyright-basedpyright-inlay-hints-function-return-types t)
("basedpyright.analysis.inlayHints.genericTypes" lsp-pyright-basedpyright-inlay-hints-generic-types t)
("python.analysis.typeCheckingMode" lsp-pyright-type-checking-mode)
("python.analysis.autoImportCompletions" lsp-pyright-auto-import-completions t)
("python.analysis.diagnosticMode" lsp-pyright-diagnostic-mode)
Expand Down