From e1e14cc9e4e371cc9c706dea27512ed83315c144 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Date: Wed, 9 Sep 2020 12:45:37 +0800 Subject: [PATCH 1/4] Simplify logic. --- dap-python.el | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/dap-python.el b/dap-python.el index 3ae061bb..0a84cea8 100644 --- a/dap-python.el +++ b/dap-python.el @@ -59,14 +59,13 @@ as the pyenv version then also return nil. This works around https://github.com/ (pyenv-version-names (split-string (string-trim (shell-command-to-string "pyenv version-name")) ":")) (executable nil) (i 0)) - (if (not (string-match "not found" pyenv-string)) - (while (and (not executable) - (< i (length pyenv-version-names))) - (if (string-match (elt pyenv-version-names i) (string-trim pyenv-string)) - (setq executable (string-trim pyenv-string))) - (if (string-match (elt pyenv-version-names i) "system") - (setq executable (string-trim (executable-find command)))) - (setq i (1+ i)))) + (unless (string-match "not found" pyenv-string) + (while (and (not executable) (< i (length pyenv-version-names))) + (when (string-match (elt pyenv-version-names i) (string-trim pyenv-string)) + (setq executable (string-trim pyenv-string))) + (when (string-match (elt pyenv-version-names i) "system") + (setq executable (string-trim (executable-find command)))) + (setq i (1+ i)))) executable)) (executable-find command))) @@ -140,28 +139,28 @@ as the pyenv version then also return nil. This works around https://github.com/ (defun dap-python--test-p (lsp-symbol) (let ((name (dap-python--symbol-name lsp-symbol))) (and (dap-python--equal (dap-python--symbol-type lsp-symbol) "Function") - (s-starts-with? "test_" name)))) + (s-starts-with? "test_" name)))) (defun dap-python--test-class-p (test-symbol lsp-symbol) (when (dap-python--equal (dap-python--symbol-type lsp-symbol) "Class") - (let* ((class-location (dap-python--symbol-location lsp-symbol)) - (class-start-line (-> class-location dap-python--location-start dap-python--point-line)) - (class-end-line (-> class-location dap-python--location-end dap-python--point-line)) - (test-start-line (-> test-symbol dap-python--symbol-location dap-python--location-start dap-python--point-line))) - (and (> test-start-line class-start-line) - (< test-start-line class-end-line))))) + (let* ((class-location (dap-python--symbol-location lsp-symbol)) + (class-start-line (-> class-location dap-python--location-start dap-python--point-line)) + (class-end-line (-> class-location dap-python--location-end dap-python--point-line)) + (test-start-line (-> test-symbol dap-python--symbol-location dap-python--location-start dap-python--point-line))) + (and (> test-start-line class-start-line) + (< test-start-line class-end-line))))) (defun dap-python--nearest-test (lsp-symbols) (let* ((reversed (reverse lsp-symbols)) - (test-symbol (-first 'dap-python--test-p reversed)) - (class-symbol (-first (-partial 'dap-python--test-class-p test-symbol) reversed))) + (test-symbol (-first 'dap-python--test-p reversed)) + (class-symbol (-first (-partial 'dap-python--test-class-p test-symbol) reversed))) (if (eq nil class-symbol) - (concat "::" (dap-python--symbol-name test-symbol)) - (concat "::" (dap-python--symbol-name class-symbol) "::" (dap-python--symbol-name test-symbol))))) + (concat "::" (dap-python--symbol-name test-symbol)) + (concat "::" (dap-python--symbol-name class-symbol) "::" (dap-python--symbol-name test-symbol))))) (defun dap-python--cursor-position () (make-dap-python--point :line (line-number-at-pos) - :character (current-column))) + :character (current-column))) (defun dap-python--test-at-point () (->> (lsp--get-document-symbols) @@ -258,11 +257,11 @@ as the pyenv version then also return nil. This works around https://github.com/ (dap-register-debug-provider "python-test-at-point" 'dap-python--populate-test-at-point) (dap-register-debug-template "Python :: Run pytest (at point)" - (list :type "python-test-at-point" - :args "" - :module "pytest" - :request "launch" - :name "Python :: Run pytest (at point)")) + (list :type "python-test-at-point" + :args "" + :module "pytest" + :request "launch" + :name "Python :: Run pytest (at point)")) (provide 'dap-python) ;;; dap-python.el ends here From 12425fe0c382cc28cd769f22ac11978ec09820d4 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Date: Wed, 9 Sep 2020 12:57:50 +0800 Subject: [PATCH 2/4] Revert line here. --- dap-python.el | 1 - 1 file changed, 1 deletion(-) diff --git a/dap-python.el b/dap-python.el index 0a84cea8..4cb75bdc 100644 --- a/dap-python.el +++ b/dap-python.el @@ -245,7 +245,6 @@ as the pyenv version then also return nil. This works around https://github.com/ :program nil :request "launch" :name "Python :: Run file (buffer)")) - (dap-register-debug-template "Python :: Run pytest (buffer)" (list :type "python" :args "" From 570a587341c0dd4d3f16c8d4a2ce0afeefffbd9e Mon Sep 17 00:00:00 2001 From: Jen-Chieh Date: Wed, 9 Sep 2020 13:00:12 +0800 Subject: [PATCH 3/4] Fix existing docstring.' --- dap-python.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dap-python.el b/dap-python.el index 4cb75bdc..c9e5c911 100644 --- a/dap-python.el +++ b/dap-python.el @@ -50,9 +50,9 @@ For example you may set it to `xterm -e' which will pop xterm console when you a (defun dap-python--pyenv-executable-find (command) "Find executable taking pyenv shims into account. -If the executable is a system executable and not in the same path -as the pyenv version then also return nil. This works around https://github.com/pyenv/pyenv-which-ext -" +If the executable is a system executable and not in the same path as the pyenv + version then also return nil. +This works around https://github.com/pyenv/pyenv-which-ext." (if (executable-find "pyenv") (progn (let ((pyenv-string (shell-command-to-string (concat "pyenv which " command))) From 51b760ac763316e53316a03153e31a1aaa73e246 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Date: Wed, 9 Sep 2020 13:04:10 +0800 Subject: [PATCH 4/4] Fixed byte compile warnings. --- dap-python.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dap-python.el b/dap-python.el index c9e5c911..16c8832b 100644 --- a/dap-python.el +++ b/dap-python.el @@ -70,17 +70,17 @@ This works around https://github.com/pyenv/pyenv-which-ext." (executable-find command))) (cl-defstruct dap-python--point - (line (:type integer) :named t) - (character (:type integer) :named t)) + (line '(:type integer) :named t) + (character '(:type integer) :named t)) (cl-defstruct dap-python--location - (start (:type dap-python--point) :named t) - (end (:type dap-python--point) :named t)) + (start '(:type dap-python--point) :named t) + (end '(:type dap-python--point) :named t)) (cl-defstruct dap-python--symbol - (name (:type string) :named t) - (type (:type string) :named t) - (location (:type dap-python--location) :named t)) + (name '(:type string) :named t) + (type '(:type string) :named t) + (location '(:type dap-python--location) :named t)) (cl-defgeneric dap-python--equal (lhs rhs) (:documentation "Check if lhs and rhs are equal"))