summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-20 15:00:53 -0500
committerCraig Jennings <c@cjennings.net>2025-10-20 15:00:53 -0500
commitce8477e80e0a837ac462b97c1a4b5d834838d6d3 (patch)
tree260f63889b9b733364c8ce9fbe4c24a5f4cef4c1 /modules
parentaca199997de2515c971bfcb8818eb1eb43da59de (diff)
feat:python: Enhance Python LSP setup with plugins and config
Add detailed configuration for LSP in the Python programming environment. Include forward declarations for LSP and external packages, and enable LSP with pylsp server if available. Set up pylsp plugin preferences and update relevant settings in python-mode initialization.
Diffstat (limited to 'modules')
-rw-r--r--modules/prog-python.el65
1 files changed, 60 insertions, 5 deletions
diff --git a/modules/prog-python.el b/modules/prog-python.el
index 20992aeb..2775061d 100644
--- a/modules/prog-python.el
+++ b/modules/prog-python.el
@@ -2,11 +2,42 @@
;; author Craig Jennings <c@cjennings.net>
;;; Commentary:
+;; Python programming environment with LSP, tree-sitter, and formatting.
+;;
+;; Installation:
+;; pip install python-lsp-server[all] flake8
+;;
+;; LSP will provide:
+;; - Intelligent code completion
+;; - Jump to definition (M-.)
+;; - Find references
+;; - On-the-fly error checking (flake8)
+;; - Documentation on hover
;;; Code:
(defvar python-ts-mode-map)
+;; Forward declarations for LSP
+(declare-function lsp-deferred "lsp-mode")
+(defvar lsp-pylsp-server-command)
+(defvar lsp-pylsp-plugins-flake8-enabled)
+(defvar lsp-pylsp-plugins-pylint-enabled)
+(defvar lsp-pylsp-plugins-pycodestyle-enabled)
+(defvar lsp-pylsp-plugins-autopep8-enabled)
+(defvar lsp-pylsp-plugins-yapf-enabled)
+(defvar lsp-pylsp-plugins-pydocstyle-enabled)
+(defvar lsp-pylsp-plugins-rope-completion-enabled)
+
+;; Forward declarations for external packages
+(declare-function company-mode "company")
+(defvar poetry-tracking-strategy)
+
+(defvar pylsp-path "pylsp"
+ "Path to Python LSP server (pylsp or pyright).
+Install with: pip install python-lsp-server[all]
+Or for pyright: pip install pyright")
+
;; -------------------------------- Python Setup -------------------------------
;; preferences for Python programming
@@ -15,11 +46,16 @@
(company-mode) ;; completion framework
(flyspell-prog-mode) ;; spell check comments
(superword-mode) ;; see-this-as-one-word
- (setq-default fill-column 80) ;; wrap at 80 columns
- (setq-default tab-width 4) ;; set the tab width to 4 spaces
- (setq-default standard-indent 4) ;; indent 4 spaces
- (setq-default indent-tabs-mode nil) ;; disable tab characters
- (electric-pair-mode t)) ;; match delimiters automatically
+ (setq-local fill-column 80) ;; wrap at 80 columns
+ (setq-local tab-width 4) ;; set the tab width to 4 spaces
+ (setq-local standard-indent 4) ;; indent 4 spaces
+ (setq-local indent-tabs-mode nil) ;; disable tab characters
+ (electric-pair-mode t) ;; match delimiters automatically
+
+ ;; Enable LSP if available
+ (when (and (fboundp 'lsp-deferred)
+ (executable-find pylsp-path))
+ (lsp-deferred)))
;; ----------------------------------- Python ----------------------------------
;; configuration for python-ts-mode (treesit-based Python editing)
@@ -37,6 +73,25 @@
(setq auto-mode-alist
(rassq-delete-all 'python-mode auto-mode-alist)))
+;; ------------------------------- LSP for Python ------------------------------
+;; Python-specific LSP configuration
+;; Core LSP setup is in prog-general.el
+
+(use-package lsp-mode
+ :hook (python-ts-mode . lsp-deferred)
+ :config
+ ;; Use pylsp (python-lsp-server) - more lightweight than pyright
+ (setq lsp-pylsp-server-command pylsp-path)
+
+ ;; Configure pylsp plugins
+ (setq lsp-pylsp-plugins-flake8-enabled t)
+ (setq lsp-pylsp-plugins-pylint-enabled nil) ;; too slow
+ (setq lsp-pylsp-plugins-pycodestyle-enabled nil) ;; use flake8 instead
+ (setq lsp-pylsp-plugins-autopep8-enabled nil) ;; use blacken instead
+ (setq lsp-pylsp-plugins-yapf-enabled nil)
+ (setq lsp-pylsp-plugins-pydocstyle-enabled t)
+ (setq lsp-pylsp-plugins-rope-completion-enabled t))
+
;; ----------------------------------- Poetry ----------------------------------
;; virtual environments and dependencies