mirror of https://github.com/opensumi/core
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:
parent
2f563f0c69
commit
5472a76aa5
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue