Skip to content

Commit 964cbb9

Browse files
committed
Fix context completion for workspaces that are not git.
Fixes #98
1 parent 96a3eeb commit 964cbb9

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Improve anthropic extraPayload requirement when adding models.
66
- Add message to when config failed to be parsed.
7+
- Fix context completion for workspaces that are not git. #98
78

89
## 0.40.0
910

src/eca/features/index.clj

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
(defn ^:private git-ls-files* [root-path]
1414
(try
15-
(some-> (shell/sh "git" "ls-files" "--others" "--exclude-standard" "--cached"
16-
:dir root-path)
17-
:out
18-
(string/split #"\n"))
19-
15+
(let [{:keys [out exit]} (shell/sh "git" "ls-files" "--others" "--exclude-standard" "--cached"
16+
:dir root-path)]
17+
(when (= 0 exit)
18+
(string/split out #"\n")))
2019
(catch Exception _ nil)))
2120

2221
(def ^:private git-ls-files (memoize/ttl git-ls-files* :ttl/threshold ttl-git-ls-files-ms))
@@ -25,14 +24,16 @@
2524
(reduce
2625
(fn [files {:keys [type]}]
2726
(case type
28-
:gitignore (let [git-files (some->> (git-ls-files root-filename)
29-
(mapv (comp str fs/canonicalize #(fs/file root-filename %)))
30-
set)]
31-
(if (seq git-files)
32-
(filter (fn [file]
33-
(contains? git-files (str file)))
34-
files)
35-
files))
27+
:gitignore (if-let [git-files (git-ls-files root-filename)]
28+
(let [git-paths (some->> git-files
29+
(mapv (comp str fs/canonicalize #(fs/file root-filename %)))
30+
set)]
31+
(if (seq git-paths)
32+
(filter (fn [file]
33+
(contains? git-paths (str file)))
34+
files)
35+
files))
36+
files)
3637
files))
3738
file-paths
3839
(get-in config [:index :ignoreFiles])))

test/eca/features/index_test.clj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818
file1 (fs/path root "ignored.txt")
1919
file2 (fs/path root "not-ignored.txt")]
2020
(testing "returns filtered files when `git ls-files` works"
21-
(with-redefs [shell/sh (fn [& _args] {:exit 0 :out "not-ignored.txt"})
21+
(with-redefs [f.index/git-ls-files #'f.index/git-ls-files*
22+
shell/sh (constantly {:exit 0 :out "not-ignored.txt"})
2223
fs/canonicalize #(fs/path root %)]
2324
(is
2425
(match?
2526
[file2]
2627
(f.index/filter-allowed [file1 file2] root gitignore-config)))))
2728

2829
(testing "returns all files when `git ls-files` exits non-zero"
29-
(with-redefs [shell/sh (fn [& _args] {:exit 1})]
30+
(with-redefs [f.index/git-ls-files #'f.index/git-ls-files*
31+
shell/sh (constantly {:exit 1})]
3032
(is
3133
(match?
32-
[file2]
34+
[file1 file2]
3335
(f.index/filter-allowed [file1 file2] root gitignore-config))))))))
3436

3537
(deftest repo-map-test
@@ -50,7 +52,7 @@
5052
" baz.clj"
5153
" foo.clj"
5254
"")
53-
(eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
55+
(eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
5456
{:index {:repoMap {:maxEntriesPerDir 50 :maxTotalEntries 800}}}
5557
{:as-string? true}))))))
5658

@@ -65,9 +67,9 @@
6567
"src/f.clj"
6668
"src/g.clj"
6769
"src/h.clj"])]
68-
(let [out (eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
70+
(let [out (eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
6971
{:index {:repoMap {:maxTotalEntries 800
70-
:maxEntriesPerDir 3}}}
72+
:maxEntriesPerDir 3}}}
7173
{:as-string? true})]
7274
(is (string/includes? out (str (h/file-path "/fake/repo") "\n")))
7375
;; Under src, only first 3 children (sorted) and a per-dir truncated line should appear
@@ -84,9 +86,9 @@
8486
"LICENSE"
8587
"src/a.clj"
8688
"src/b.clj"])]
87-
(let [out (eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
89+
(let [out (eca.features.index/repo-map {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]}
8890
{:index {:repoMap {:maxTotalEntries 3
89-
:maxEntriesPerDir 800}}}
91+
:maxEntriesPerDir 800}}}
9092
{:as-string? true})]
9193
;; Contains a global truncated line
9294
(is (string/includes? out "\n... truncated output ("))))))

0 commit comments

Comments
 (0)