Skip to content

Commit 53a62c6

Browse files
committed
dap-python: refactor: remove `dap-python--equal'
`dap-python--equal' just replicated the functionality of `equal', and increased the complexity of `dap-python'. Replace all uses of it with `equal' instead.
1 parent 5ac66f6 commit 53a62c6

File tree

2 files changed

+45
-71
lines changed

2 files changed

+45
-71
lines changed

dap-python.el

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,6 @@ https://github.com/pyenv/pyenv-which-ext."
8484
(type nil :type string)
8585
(location nil :type dap-python--location))
8686

87-
(cl-defgeneric dap-python--equal (lhs rhs)
88-
(:documentation "Check if lhs and rhs are equal"))
89-
90-
(cl-defmethod dap-python--equal ((lhs symbol) (rhs symbol))
91-
(eq lhs rhs))
92-
93-
(cl-defmethod dap-python--equal ((lhs integer) (rhs integer))
94-
(eq lhs rhs))
95-
96-
(cl-defmethod dap-python--equal ((lhs string) (rhs string))
97-
(string-equal lhs rhs))
98-
99-
(cl-defmethod dap-python--equal ((lhs list) (rhs list))
100-
(and (dap-python--equal (length lhs) (length rhs))
101-
(-reduce (lambda (x y) (and x y)) (-zip-with 'dap-python--equal lhs rhs))))
102-
103-
(cl-defmethod dap-python--equal ((lhs dap-python--point) (rhs dap-python--point))
104-
(and (dap-python--equal (dap-python--point-line lhs) (dap-python--point-line rhs))
105-
(dap-python--equal (dap-python--point-character lhs) (dap-python--point-character rhs))))
106-
107-
(cl-defmethod dap-python--equal ((lhs dap-python--location) (rhs dap-python--location))
108-
(and (dap-python--equal (dap-python--location-start lhs) (dap-python--location-start rhs))
109-
(dap-python--equal (dap-python--location-end lhs) (dap-python--location-end rhs))))
110-
111-
(cl-defmethod dap-python--equal ((lhs dap-python--symbol) (rhs dap-python--symbol))
112-
(and (dap-python--equal (dap-python--symbol-name lhs) (dap-python--symbol-name rhs))
113-
(dap-python--equal (dap-python--symbol-type lhs) (dap-python--symbol-type rhs))
114-
(dap-python--equal (dap-python--symbol-location lhs) (dap-python--symbol-location rhs))))
115-
11687
(lsp-defun dap-python--parse-lsp-symbol
11788
((&DocumentSymbol
11889
:name :kind
@@ -141,17 +112,17 @@ https://github.com/pyenv/pyenv-which-ext."
141112

142113
(defun dap-python--test-p (lsp-symbol)
143114
(let ((name (dap-python--symbol-name lsp-symbol)))
144-
(and (dap-python--equal (dap-python--symbol-type lsp-symbol) "Function")
145-
(s-starts-with? "test_" name))))
115+
(and (string= (dap-python--symbol-type lsp-symbol) "Function")
116+
(s-starts-with? "test_" name))))
146117

147118
(defun dap-python--test-class-p (test-symbol lsp-symbol)
148-
(when (dap-python--equal (dap-python--symbol-type lsp-symbol) "Class")
119+
(when (string= (dap-python--symbol-type lsp-symbol) "Class")
149120
(let* ((class-location (dap-python--symbol-location lsp-symbol))
150-
(class-start-line (-> class-location dap-python--location-start dap-python--point-line))
151-
(class-end-line (-> class-location dap-python--location-end dap-python--point-line))
152-
(test-start-line (-> test-symbol dap-python--symbol-location dap-python--location-start dap-python--point-line)))
153-
(and (> test-start-line class-start-line)
154-
(< test-start-line class-end-line)))))
121+
(class-start-line (-> class-location dap-python--location-start dap-python--point-line))
122+
(class-end-line (-> class-location dap-python--location-end dap-python--point-line))
123+
(test-start-line (-> test-symbol dap-python--symbol-location dap-python--location-start dap-python--point-line)))
124+
(and (> test-start-line class-start-line)
125+
(< test-start-line class-end-line)))))
155126

156127
(defun dap-python--nearest-test (lsp-symbols)
157128
(cl-callf reverse lsp-symbols)
@@ -175,11 +146,14 @@ https://github.com/pyenv/pyenv-which-ext."
175146
dap-python--nearest-test))
176147

177148
(defun dap-python--template (template-name)
178-
(->> dap-debug-template-configurations
179-
(-first (-lambda ((name)) (dap-python--equal name template-name)))
180-
cdr))
181-
182-
(defun dap-python--debug-test-at-point ()
149+
"Return the debug template whose name is TEMPLATE-NAME.
150+
For the name, only the template's `car' is checked, not its
151+
`:name' property."
152+
(--first (string= template-name it) dap-debug-template-configurations))
153+
154+
(defalias 'dap-python--debug-test-at-point #'dap-python-debug-test-at-point)
155+
(defun dap-python-debug-test-at-point ()
156+
"Debug the pytest test under the cursor."
183157
(interactive)
184158
(dap-debug (dap-python--template "Python :: Run pytest (at point)")))
185159

test/dap-test.el

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,33 @@
6565

6666
(ert-deftest dap--python-test-free-function ()
6767
(let* ((document-symbols
68-
(list
69-
#s(dap-python--symbol "dataclass" "Function" #s(dap-python--location #s(dap-python--point 0 0) #s(dap-python--point 0 33)))
70-
#s(dap-python--symbol "Foo" "Class" #s(dap-python--location #s(dap-python--point 4 0) #s(dap-python--point 6 0)))
71-
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 5 4) #s(dap-python--point 5 14)))
72-
#s(dap-python--symbol "Bar" "Class" #s(dap-python--location #s(dap-python--point 9 0) #s(dap-python--point 11 0)))
73-
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 10 4) #s(dap-python--point 10 14)))
74-
#s(dap-python--symbol "test_foo" "Function" #s(dap-python--location #s(dap-python--point 13 0) #s(dap-python--point 16 0)))
75-
#s(dap-python--symbol "foo" "Variable" #s(dap-python--location #s(dap-python--point 14 4) #s(dap-python--point 14 20)))
76-
#s(dap-python--symbol "test_bar" "Function" #s(dap-python--location #s(dap-python--point 18 0) #s(dap-python--point 21 0)))
77-
#s(dap-python--symbol "bar" "Variable" #s(dap-python--location #s(dap-python--point 19 4) #s(dap-python--point 19 20)))))
78-
79-
(cursor #s(dap-python--point 15 4))
80-
81-
(actual (dap-python--symbols-before-point cursor document-symbols))
82-
83-
(expected
84-
(list
85-
#s(dap-python--symbol "dataclass" "Function" #s(dap-python--location #s(dap-python--point 0 0) #s(dap-python--point 0 33)))
86-
#s(dap-python--symbol "Foo" "Class" #s(dap-python--location #s(dap-python--point 4 0) #s(dap-python--point 6 0)))
87-
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 5 4) #s(dap-python--point 5 14)))
88-
#s(dap-python--symbol "Bar" "Class" #s(dap-python--location #s(dap-python--point 9 0) #s(dap-python--point 11 0)))
89-
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 10 4) #s(dap-python--point 10 14)))
90-
#s(dap-python--symbol "test_foo" "Function" #s(dap-python--location #s(dap-python--point 13 0) #s(dap-python--point 16 0)))
91-
#s(dap-python--symbol "foo" "Variable" #s(dap-python--location #s(dap-python--point 14 4) #s(dap-python--point 14 20))))))
92-
93-
(should (dap-python--equal actual expected))
94-
(should (dap-python--equal (dap-python--nearest-test expected) "::test_foo"))))
68+
(list
69+
#s(dap-python--symbol "dataclass" "Function" #s(dap-python--location #s(dap-python--point 0 0) #s(dap-python--point 0 33)))
70+
#s(dap-python--symbol "Foo" "Class" #s(dap-python--location #s(dap-python--point 4 0) #s(dap-python--point 6 0)))
71+
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 5 4) #s(dap-python--point 5 14)))
72+
#s(dap-python--symbol "Bar" "Class" #s(dap-python--location #s(dap-python--point 9 0) #s(dap-python--point 11 0)))
73+
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 10 4) #s(dap-python--point 10 14)))
74+
#s(dap-python--symbol "test_foo" "Function" #s(dap-python--location #s(dap-python--point 13 0) #s(dap-python--point 16 0)))
75+
#s(dap-python--symbol "foo" "Variable" #s(dap-python--location #s(dap-python--point 14 4) #s(dap-python--point 14 20)))
76+
#s(dap-python--symbol "test_bar" "Function" #s(dap-python--location #s(dap-python--point 18 0) #s(dap-python--point 21 0)))
77+
#s(dap-python--symbol "bar" "Variable" #s(dap-python--location #s(dap-python--point 19 4) #s(dap-python--point 19 20)))))
78+
79+
(cursor #s(dap-python--point 15 4))
80+
81+
(actual (dap-python--symbols-before-point cursor document-symbols))
82+
83+
(expected
84+
(list
85+
#s(dap-python--symbol "dataclass" "Function" #s(dap-python--location #s(dap-python--point 0 0) #s(dap-python--point 0 33)))
86+
#s(dap-python--symbol "Foo" "Class" #s(dap-python--location #s(dap-python--point 4 0) #s(dap-python--point 6 0)))
87+
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 5 4) #s(dap-python--point 5 14)))
88+
#s(dap-python--symbol "Bar" "Class" #s(dap-python--location #s(dap-python--point 9 0) #s(dap-python--point 11 0)))
89+
#s(dap-python--symbol "value" "Variable" #s(dap-python--location #s(dap-python--point 10 4) #s(dap-python--point 10 14)))
90+
#s(dap-python--symbol "test_foo" "Function" #s(dap-python--location #s(dap-python--point 13 0) #s(dap-python--point 16 0)))
91+
#s(dap-python--symbol "foo" "Variable" #s(dap-python--location #s(dap-python--point 14 4) #s(dap-python--point 14 20))))))
92+
93+
(should (equal actual expected))
94+
(should (equal (dap-python--nearest-test expected) "::test_foo"))))
9595

9696
(ert-deftest dap--python-test-class-method ()
9797
(let* ((document-symbols
@@ -121,8 +121,8 @@
121121
#s(dap-python--symbol "TestClass" "Class" #s(dap-python--location #s(dap-python--point 13 0) #s(dap-python--point 21 0)))
122122
#s(dap-python--symbol "test_foo" "Function" #s(dap-python--location #s(dap-python--point 14 4) #s(dap-python--point 17 0))))))
123123

124-
(should (dap-python--equal actual expected))
125-
(should (dap-python--equal (dap-python--nearest-test expected) "::TestClass::test_foo"))))
124+
(should (equal actual expected))
125+
(should (equal (dap-python--nearest-test expected) "::TestClass::test_foo"))))
126126

127127
(defun dap-launch-test--sanitize-json (s)
128128
"Delete all comments in S."

0 commit comments

Comments
 (0)