emacs-lsp / lsp-pyright

lsp-mode :heart: pyright
https://emacs-lsp.github.io/lsp-pyright
GNU General Public License v3.0
291 stars 25 forks source link

Disabling type checking (typeCheckingMode "off") in basedpyright #102

Closed tsoernes closed 2 months ago

tsoernes commented 2 months ago

I use the basedpyright fork.

Is there a way to temporarily disable pyright type checking?

Something like this:

(defun disable-pyright-type-errors ()
  "Disable type-related errors in Pyright."
  (interactive)
  (setq lsp-pyright-diagnostic-mode "workspace")
  (setq lsp-pyright-typechecking-mode "off")
  (lsp-restart-workspace))

However there is no variable lsp-pyright-typechecking-mode, however there is a typeCheckingMode setting for pyright in vscode: https://github.com/microsoft/pyright/blob/main/docs/configuration.md . I have tried this also but no luck:

(defun disable-pyright-type-errors ()
  "Disable type-related errors in Pyright."
  (interactive)
  (lsp--set-configuration
   `(:pyright
     (:typeCheckingMode "off")))
  (lsp-restart-workspace))
seagle0128 commented 2 months ago

How about this?

(lsp-register-custom-settings
 `((,(concat lsp-pyright-langserver-command ".typeCheckingMode") "off"))

Or use pyrightconfig.json.

tsoernes commented 2 months ago

This worked:

(defun disable-pyright-type-errors ()
  "Disable type-related errors in Pyright."
  (interactive)
  (lsp-register-custom-settings
   '(("python.analysis.typeCheckingMode" "off")
     ("basedpyright.analysis.typeCheckingMode" "off")))
  (lsp-restart-workspace))

(defun enable-pyright-type-errors ()
  "Enable strict type-related errors in Pyright."
  (interactive)
  (lsp-register-custom-settings
   '(("python.analysis.typeCheckingMode" "basic")
     ("basedpyright.analysis.typeCheckingMode" "basic")))
  (lsp-restart-workspace))

(defun enable-standard-pyright-type-errors ()
  "Enable strict type-related errors in Pyright."
  (interactive)
  (lsp-register-custom-settings
   '(("python.analysis.typeCheckingMode" "standard")
     ("basedpyright.analysis.typeCheckingMode" "standard")))
  (lsp-restart-workspace))

(defun enable-strict-pyright-type-errors ()
  "Enable strict type-related errors in Pyright."
  (interactive)
  (lsp-register-custom-settings
   '(("python.analysis.typeCheckingMode" "strict")
     ("basedpyright.analysis.typeCheckingMode" "strict")))
  (lsp-restart-workspace))

(defun enable-all-pyright-type-errors ()
  "Enable strict type-related errors in Pyright."
  (interactive)
  (lsp-register-custom-settings
   '(("python.analysis.typeCheckingMode" "strict")
     ("basedpyright.analysis.typeCheckingMode" "all")))
  (lsp-restart-workspace))