Skip to content

Commit 38c0566

Browse files
committed
feat: add .clineignore support
1 parent 5eacb76 commit 38c0566

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/integrations/misc/extract-text.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ import pdf from "pdf-parse/lib/pdf-parse"
44
import mammoth from "mammoth"
55
import fs from "fs/promises"
66
import { isBinaryFile } from "isbinaryfile"
7+
import { loadIgnorePatterns } from "../../utils/cline-ignore"
78

89
export async function extractTextFromFile(filePath: string): Promise<string> {
10+
// Convert file path to relative path
11+
const cwd = path.dirname(filePath)
12+
const relativePath = path.relative(cwd, filePath)
13+
14+
// Load and check .clineignore patterns
15+
const { shouldIgnore } = await loadIgnorePatterns(cwd)
16+
if (shouldIgnore(relativePath)) {
17+
throw new Error(`File is ignored by .clineignore: ${filePath}`)
18+
}
19+
920
try {
1021
await fs.access(filePath)
1122
} catch (error) {

src/services/glob/list-files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { globby, Options } from "globby"
22
import os from "os"
33
import * as path from "path"
44
import { arePathsEqual } from "../../utils/path"
5+
import { loadIgnorePatterns } from "../../utils/cline-ignore"
56

67
export async function listFiles(dirPath: string, recursive: boolean, limit: number): Promise<[string[], boolean]> {
78
const absolutePath = path.resolve(dirPath)
@@ -17,6 +18,8 @@ export async function listFiles(dirPath: string, recursive: boolean, limit: numb
1718
return [[homeDir], false]
1819
}
1920

21+
const { patterns } = await loadIgnorePatterns(absolutePath)
22+
2023
const dirsToIgnore = [
2124
"node_modules",
2225
"__pycache__",
@@ -34,6 +37,7 @@ export async function listFiles(dirPath: string, recursive: boolean, limit: numb
3437
"pkg",
3538
"Pods",
3639
".*", // '!**/.*' excludes hidden directories, while '!**/.*/**' excludes only their contents. This way we are at least aware of the existence of hidden directories.
40+
...patterns,
3741
].map((dir) => `**/${dir}/**`)
3842

3943
const options = {

src/services/ripgrep/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as childProcess from "child_process"
33
import * as path from "path"
44
import * as fs from "fs"
55
import * as readline from "readline"
6+
import { loadClineIgnoreFile, loadIgnorePatterns } from "../../utils/cline-ignore"
67

78
/*
89
This file provides functionality to perform regex searches on files using ripgrep.
@@ -178,8 +179,9 @@ export async function regexSearchFiles(
178179
if (currentResult) {
179180
results.push(currentResult as SearchResult)
180181
}
181-
182-
return formatResults(results, cwd)
182+
const { shouldIgnore } = await loadIgnorePatterns(cwd)
183+
const filteredResults = results.filter((result) => !shouldIgnore(result.file.replace(`${cwd}/`, "")))
184+
return formatResults(filteredResults, cwd)
183185
}
184186

185187
function formatResults(results: SearchResult[], cwd: string): string {

0 commit comments

Comments
 (0)