From cb9f09ba842716343f835eb9757b5deb8dfbdf32 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Fri, 6 Jun 2025 11:43:49 -0500 Subject: [PATCH] hotfix issue with path join Not sure why I didn't test these changes, but the path-join function didn't actually work fully as expected. Now, various edge cases have been ironed out: "/path" + "/foo/bar" -> "/foo/bar", instead of "/path/foo/bar" "" + "code.fnl" -> "code.fnl", instead of "/code.fnl" --- src/fennel-ls/utils.fnl | 17 ++++++++--------- test/misc.fnl | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index 70fb9d6..98d081a 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -198,15 +198,14 @@ WARNING: this is only used in the test code, not in the real language server" (= (path:sub 1 1) "/"))) (λ path-join [path suffix] - (-> (.. path path-sep suffix) - ;; delete duplicate - ;; windows - (: :gsub "^%.\\" "") - (: :gsub "\\+" "\\") - ;; modern society - (: :gsub "^%./" "") - (: :gsub "/+" "/") - (->> (pick-values 1)))) + (if (absolute-path? suffix) suffix + (= path "") suffix + (let [clean-path (path:gsub "[\\/]?$" path-sep) ; ensure trailing slash + clean-suffix (if (or (= (suffix:sub 1 2) "./") + (= (suffix:sub 1 2) ".\\")) + (suffix:sub 3) + suffix)] + (.. clean-path clean-suffix)))) (fn find [t x ?k] (match (next t ?k) (k x) k (k y_) (find t x k))) diff --git a/test/misc.fnl b/test/misc.fnl index 67f47cb..e036680 100644 --- a/test/misc.fnl +++ b/test/misc.fnl @@ -43,6 +43,28 @@ (create-client "(let [map {}] (set (. map (tostring :a)) :b))") nil) +(fn test-path-join [] + ;; Basic path joining + (faith.= "path/file" (utils.path-join "path/" "file")) + (faith.= "path/file" (utils.path-join "path" "file")) + (faith.= "path/file" (utils.path-join "path" "./file")) + + ; Empty path - return suffix as-is + (faith.= "file" (utils.path-join "" "file")) + (faith.= "main.fnl" (utils.path-join "" "main.fnl")) + (faith.= "path/" (utils.path-join "path" "")) + + ; Absolute suffix should override base path + (faith.= "/usr/share/awesome/lib" (utils.path-join "/home/myusername/.config/awesome/" "/usr/share/awesome/lib")) + + ; Leading ./ in suffix should be stripped + (faith.= "/home/myusername/my-project/main.fnl" (utils.path-join "/home/myusername/my-project" "./main.fnl")) + + ; Nested relative paths + (faith.= "a/b/c/d" (utils.path-join "a/b" "c/d")) + nil) + {: test-multi-sym-split : test-find-symbol - : test-failure} + : test-failure + : test-path-join}