Skip to content

Commit

Permalink
feat: enhance file search service to handle absolute paths and update… (
Browse files Browse the repository at this point in the history
#4334)

* feat: enhance file search service to handle absolute paths and update search arguments

* feat: enhance absolute path handling in file search service

* chore: update e2e yml
  • Loading branch information
Aaaaash authored Feb 5, 2025
1 parent 2f563f0 commit 5472a76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: tools/playwright/test-results
18 changes: 16 additions & 2 deletions packages/file-search/src/node/file-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class FileSearchService implements IFileSearchService {
@Autowired(INodeLogger)
logger: INodeLogger;

private isAbsolutePathPattern(pattern: string): boolean {
return path.isAbsolute(pattern) || pattern.startsWith('/') || pattern.startsWith('\\');
}

// 这里应该返回文件的 `fsPath` 而非 `file://` 协议文件路径
// 否则在 Windows 下,盘符路径会被隐藏
async find(
Expand All @@ -40,13 +44,23 @@ export class FileSearchService implements IFileSearchService {
};

const roots: IFileSearchService.RootOptions = options.rootOptions || {};
let stringPattern = searchPattern.toLocaleLowerCase();

// 如果传入绝对路径,则将父级目录作为根目录
if (this.isAbsolutePathPattern(searchPattern)) {
const parent = path.dirname(searchPattern);
roots[parent] = {};
stringPattern = path.basename(searchPattern).toLocaleLowerCase();
}

if (options.rootUris) {
for (const rootUri of options.rootUris) {
if (!roots[rootUri]) {
roots[rootUri] = {};
}
}
}

// eslint-disable-next-line guard-for-in
for (const rootUri in roots) {
const rootOptions = roots[rootUri];
Expand All @@ -68,7 +82,7 @@ export class FileSearchService implements IFileSearchService {

const exactMatches = new Set<string>();
const fuzzyMatches = new Set<string>();
const stringPattern = searchPattern.toLocaleLowerCase();

await Promise.all(
Object.keys(roots).map(async (cwd) => {
try {
Expand Down Expand Up @@ -147,7 +161,7 @@ export class FileSearchService implements IFileSearchService {
}

private getSearchArgs(options: IFileSearchService.BaseOptions): string[] {
const args = ['--files', '--hidden', '--case-sensitive'];
const args = ['--files', '--hidden', '--case-sensitive', '--no-require-git'];
if (options.includePatterns) {
for (const includePattern of options.includePatterns) {
if (includePattern) {
Expand Down

0 comments on commit 5472a76

Please sign in to comment.