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

Fix fenceposting issue with docstring extraction #191

Merged
merged 1 commit into from
May 3, 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
23 changes: 12 additions & 11 deletions src/marginalia/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,9 @@
:else
(dispatch-inner-form form raw nspace-sym)))

(defn extract-docstring [m raw nspace-sym]
(let [raw (join "\n" (subvec raw (-> m :start dec) (:end m)))
form (:form m)]
(dispatch-form form raw nspace-sym)))
(defn extract-docstring [{:keys [start end form]} raw-lines nspace-sym]
(let [new-lines (join "\n" (subvec raw-lines (dec start) (min end (count raw-lines))))]
(dispatch-form form new-lines nspace-sym)))

(defn- ->str [m]
(-> (-> m :form .content)
Expand All @@ -371,15 +370,17 @@
:start (:start f)
:end (:end s)})

(defn comment? [o]
(->> o :form (instance? Comment)))
(defn comment? [{:keys [form]}]
(instance? Comment form))

(defn code? [o]
(and (->> o :form (instance? Comment) not)
(->> o :form nil? not)))
(defn code? [{:keys [form] :as o}]
(and (not (nil? form))
(not (comment? o))))

(defn adjacent? [f s]
(= (-> f :end) (-> s :start dec)))
(defn adjacent?
"Two parsed objects are adjacent if the end of the first is followed by the start of the second."
[{:keys [end] :as _first} {:keys [start] :as _second}]
(= end (dec start)))

(defn arrange-in-sections [parsed-code raw-code]
(loop [sections []
Expand Down
2 changes: 1 addition & 1 deletion test/marginalia/parse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

(deftest test-inline-literals
(is (= (count (marginalia.parser/parse "(ns test)")) 1))
;; (is (= (count (marginalia.parser/parse "(ns test)\n123")) 1)) ;; still failing
(is (= (count (marginalia.parser/parse "(ns test)\n123")) 1))
(is (= (count (marginalia.parser/parse "(ns test)\n123\n")) 1))
(is (= (count (marginalia.parser/parse "(ns test)\n\"string\"")) 1))
(is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1))
Expand Down