feat: enhance file search service to handle absolute paths and update… (#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
This commit is contained in:
大表哥 2025-02-05 14:36:06 +08:00 committed by GitHub
parent 2f563f0c69
commit 5472a76aa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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(
@ -40,6 +44,15 @@ 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]) {
@ -47,6 +60,7 @@ export class FileSearchService implements IFileSearchService {
}
}
}
// eslint-disable-next-line guard-for-in
for (const rootUri in roots) {
const rootOptions = roots[rootUri];
@ -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 {
@ -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) {