Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[file-search] Fixed Windows file search inconsistencies #6029

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
label: this.labelProvider.getName(uri),
iconClass: await this.labelProvider.getIcon(uri) + ' file-icon',
description,
tooltip: uri.path.toString(),
tooltip: this.labelProvider.getLongName(uri),
uri: uri,
hidden: false,
run: this.getRunFunction(uri)
Expand Down
2 changes: 1 addition & 1 deletion packages/file-search/src/common/file-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface FileSearchService {

/**
* finds files by a given search pattern.
* @return the matching paths, relative to the given `options.rootUri`.
* @return the matching file uris
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

*/
find(searchPattern: string, options: FileSearchService.Options, cancellationToken?: CancellationToken): Promise<string[]>;

Expand Down
13 changes: 11 additions & 2 deletions packages/file-search/src/node/file-search-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import { rgPath } from 'vscode-ripgrep';
import { injectable, inject } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { CancellationTokenSource, CancellationToken, ILogger } from '@theia/core';
import { CancellationTokenSource, CancellationToken, ILogger, isWindows } from '@theia/core';
import { RawProcessFactory } from '@theia/process/lib/node';
import { FileSearchService } from '../common/file-search-service';
import * as path from 'path';

@injectable()
export class FileSearchServiceImpl implements FileSearchService {
Expand Down Expand Up @@ -70,13 +71,21 @@ export class FileSearchServiceImpl implements FileSearchService {

const exactMatches = new Set<string>();
const fuzzyMatches = new Set<string>();

if (isWindows) {
// Allow users on Windows to search for paths using either forwards or backwards slash
searchPattern = searchPattern.replace(/\//g, '\\');
}

const stringPattern = searchPattern.toLocaleLowerCase();
await Promise.all(Object.keys(roots).map(async root => {
try {
const rootUri = new URI(root);
const rootPath = FileUri.fsPath(rootUri);
const rootOptions = roots[root];
await this.doFind(rootUri, rootOptions, candidate => {
const fileUri = rootUri.resolve(candidate).toString();
// Convert OS-native candidate path to a file URI string
const fileUri = FileUri.create(path.resolve(rootPath, candidate)).toString();
if (exactMatches.has(fileUri) || fuzzyMatches.has(fileUri)) {
return;
}
Expand Down