Skip to content

Commit

Permalink
GH-1584: Fixed file search in Windows.
Browse files Browse the repository at this point in the history
 - Fixed `rigrep` path. It did not have the `.exe` suffix on Windows.
 - Fixed the `rootPath`.
 - Replaced it with a URI, so that backend can resolve it.

Closes #1584

Signed-off-by: Akos Kitta <kittaakos@gmail.com>
  • Loading branch information
kittaakos committed Mar 27, 2018
1 parent e41a77e commit 1b13fdf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ export class QuickFileOpenService implements QuickOpenModel {
this.cancelIndicator = new CancellationTokenSource();
const token = this.cancelIndicator.token;
const proposed = new Set<string>();
const rootUri = new URI(this.wsRoot.uri);
const rootPath = rootUri.path.toString();
const rootUri = this.wsRoot.uri;
const handler = async (result: string[]) => {
if (!token.isCancellationRequested) {
const root = new URI(rootUri);
result.forEach(p => {
const uri = rootUri.withPath(rootUri.path.join(p)).toString();
const uri = root.withPath(root.path.join(p)).toString();
proposed.add(uri);
});
const itemPromises = Array.from(proposed).map(uri => this.toItem(uri));
acceptor(await Promise.all(itemPromises));
}
};
this.fileSearchService.find(lookFor, { rootPath, fuzzyMatch: true, limit: 200 }, token).then(handler);
this.fileSearchService.find(lookFor, { rootUri, fuzzyMatch: true, limit: 200 }, token).then(handler);
}

private async toItem(uriString: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/file-search/src/common/file-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface FileSearchService {

/**
* finds files by a given search pattern.
* @return the matching pathes, relative to the given options.rootPath
* @return the matching paths, relative to the given `options.rootUri`.
*/
find(searchPattern: string, options: FileSearchService.Options, cancellationToken?: CancellationToken): Promise<string[]>;

Expand All @@ -25,7 +25,7 @@ export interface FileSearchService {
export const FileSearchService = Symbol('FileSearchService');
export namespace FileSearchService {
export interface Options {
rootPath: string,
rootUri: string,
fuzzyMatch?: boolean
limit?: number
useGitignore?: boolean
Expand Down
18 changes: 10 additions & 8 deletions packages/file-search/src/node/file-search-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { FileSearchService } from '../common/file-search-service';
import { RawProcessFactory } from "@theia/process/lib/node";
import { rgPath } from "vscode-ripgrep";
import { Deferred } from "@theia/core/lib/common/promise-util";
import { CancellationToken, ILogger } from '@theia/core';
import { CancellationToken, ILogger, isWindows } from '@theia/core';
import { FileUri } from '@theia/core/lib/node/file-uri';

@injectable()
export class FileSearchServiceImpl implements FileSearchService {
Expand All @@ -36,21 +37,22 @@ export class FileSearchServiceImpl implements FileSearchService {
'--sort-files',
'-u',
];
const command = `${rgPath}${isWindows ? '.exe' : ''}`;
const process = this.rawProcessFactory({
command: rgPath,
command,
args,
options: {
cwd: opts.rootPath
cwd: FileUri.fsPath(opts.rootUri)
}
});
const result: string[] = [];
const fuzzyMatches: string[] = [];
const resultDeffered = new Deferred<string[]>();
const resultDeferred = new Deferred<string[]>();
if (cancellationToken) {
const cancel = () => {
this.logger.debug('Search cancelled');
process.kill();
resultDeffered.resolve([]);
resultDeferred.resolve([]);
};
if (cancellationToken.isCancellationRequested) {
cancel();
Expand All @@ -74,14 +76,14 @@ export class FileSearchServiceImpl implements FileSearchService {
}
});
process.onError(e => {
resultDeffered.reject(e);
resultDeferred.reject(e);
});
process.onExit(e => {
const left = opts.limit - result.length;
result.push(...fuzzyMatches.slice(0, Math.min(left, fuzzyMatches.length)));
resultDeffered.resolve(result);
resultDeferred.resolve(result);
});
return resultDeffered.promise;
return resultDeferred.promise;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SearchInWorkspaceServer, SearchInWorkspaceOptions, SearchInWorkspaceRes
import { ILogger } from "@theia/core";
import { inject, injectable } from "inversify";
import { RawProcess, RawProcessFactory, RawProcessOptions } from '@theia/process/lib/node';
import { isWindows } from '@theia/core/lib/common/os';

import * as rg from 'vscode-ripgrep';

Expand Down Expand Up @@ -51,8 +52,9 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
// line, --color=always to get color control characters that
// we'll use to parse the lines.
const searchId = this.nextSearchId++;
const command = `${rg.rgPath}${isWindows ? '.exe' : ''}`;
const processOptions: RawProcessOptions = {
command: rg.rgPath,
command,
args: ["--vimgrep", "-S", "--color=always",
"--colors=path:fg:red",
"--colors=line:fg:green",
Expand Down

0 comments on commit 1b13fdf

Please sign in to comment.