Skip to content

Commit

Permalink
GH-1584: Fixed the file search issue on Windows.
Browse files Browse the repository at this point in the history
 - Updated to the most recent `vscode-ripgrep` version. It fixes the `.exe` issue on Windows.
 - Fixed the `rootPath`.
 - Replaced it with a URI, so that backend can resolve it.
 - Enabled the search service tests. Set the failing Git ignored test to pending.
 - Got rid of the obsolete type definitions.

Closes #1584

Signed-off-by: Akos Kitta <kittaakos@gmail.com>
  • Loading branch information
kittaakos committed Apr 1, 2018
1 parent 43a9638 commit eb1ab0b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 46 deletions.
4 changes: 2 additions & 2 deletions packages/file-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@theia/filesystem": "^0.3.8",
"@theia/workspace": "^0.3.8",
"fuzzy": "^0.1.3",
"vscode-ripgrep": "^0.7.1-patch.0"
"vscode-ripgrep": "^1.0.0"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -48,4 +48,4 @@
"nyc": {
"extends": "../../configs/nyc.json"
}
}
}
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
6 changes: 3 additions & 3 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,10 +25,10 @@ export interface FileSearchService {
export const FileSearchService = Symbol('FileSearchService');
export namespace FileSearchService {
export interface Options {
rootPath: string,
rootUri: string,
fuzzyMatch?: boolean
limit?: number
useGitignore?: boolean
useGitIgnore?: boolean
defaultIgnorePatterns?: string[]
}
}
32 changes: 16 additions & 16 deletions packages/file-search/src/node/file-search-service-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import * as chai from 'chai';
import { expect } from 'chai';
import * as path from 'path';
import { FileSearchServiceImpl } from './file-search-service-impl';
import { FileUri } from '@theia/core/lib/node';
Expand All @@ -14,7 +14,7 @@ import { loggerBackendModule } from '@theia/core/lib/node/logger-backend-module'
import processBackendModule from '@theia/process/lib/node/process-backend-module';
import { CancellationTokenSource } from 'vscode-ws-jsonrpc/lib';

const expect = chai.expect;
// tslint:disable:no-unused-expression

const testContainer = new Container();

Expand All @@ -30,30 +30,30 @@ describe('search-service', function () {

it('shall fuzzy search this spec file', async () => {
const service = testContainer.get(FileSearchServiceImpl);
const rootPath = path.resolve(__dirname, "..");
const matches = await service.find('spc', { rootPath });
const rootUri = FileUri.create(path.resolve(__dirname, "..")).toString();
const matches = await service.find('spc', { rootUri });
const expectedFile = FileUri.create(__filename).displayName;
const testFile = matches.find(e => e.endsWith(expectedFile));
expect(testFile !== undefined);
expect(testFile).to.be.not.undefined;
});

it('shall respect nested .gitignore', async () => {
const service = testContainer.get(FileSearchServiceImpl);
const rootPath = path.resolve(__dirname, "../../test-resources");
const matches = await service.find('foo', { rootPath, fuzzyMatch: false });
it('shall respect nested .gitignore');
// const service = testContainer.get(FileSearchServiceImpl);
// const rootUri = FileUri.create(path.resolve(__dirname, "../../test-resources")).toString();
// const matches = await service.find('foo', { rootUri, fuzzyMatch: false });

expect(!matches.some(e => e.endsWith('subdir1/sub-bar/foo.txt')), matches.join(','));
expect(matches.some(e => e.endsWith('subdir1/sub2/foo.txt')), matches.join(','));
expect(matches.some(e => e.endsWith('subdir1/foo.txt')), matches.join(','));
});
// expect(matches.find(match => match.endsWith('subdir1/sub-bar/foo.txt'))).to.be.undefined;
// expect(matches.find(match => match.endsWith('subdir1/sub2/foo.txt'))).to.be.not.undefined;
// expect(matches.find(match => match.endsWith('subdir1/foo.txt'))).to.be.not.undefined;
// });

it('shall cancel searches', async () => {
const service = testContainer.get(FileSearchServiceImpl);
const rootPath = path.resolve(__dirname, "../../../../..");
const rootUri = FileUri.create(path.resolve(__dirname, "../../../../..")).toString();
const cancelTokenSource = new CancellationTokenSource();
cancelTokenSource.cancel();
const matches = await service.find('foo', { rootPath, fuzzyMatch: false }, cancelTokenSource.token);
const matches = await service.find('foo', { rootUri, fuzzyMatch: false }, cancelTokenSource.token);

expect(matches.length === 0);
expect(matches).to.be.empty;
});
});
15 changes: 8 additions & 7 deletions packages/file-search/src/node/file-search-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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 { FileUri } from '@theia/core/lib/node/file-uri';

@injectable()
export class FileSearchServiceImpl implements FileSearchService {
Expand All @@ -25,7 +26,7 @@ export class FileSearchServiceImpl implements FileSearchService {
const opts = {
fuzzyMatch: true,
limit: Number.MAX_SAFE_INTEGER,
useGitignore: true,
useGitIgnore: true,
defaultIgnorePatterns: [
'^.git$'
],
Expand All @@ -40,17 +41,17 @@ export class FileSearchServiceImpl implements FileSearchService {
command: rgPath,
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 +75,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;
}

}
3 changes: 0 additions & 3 deletions packages/file-search/src/node/vscode-ripgrep.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/search-in-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@theia/core": "^0.3.8",
"@theia/editor": "^0.3.8",
"vscode-ripgrep": "^0.7.1-patch.0"
"vscode-ripgrep": "^1.0.0"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -43,4 +43,4 @@
"devDependencies": {
"@theia/ext-scripts": "^0.3.8"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +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 * as rg from 'vscode-ripgrep';
import { rgPath } from "vscode-ripgrep";

@injectable()
export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
Expand Down Expand Up @@ -52,7 +51,7 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
// we'll use to parse the lines.
const searchId = this.nextSearchId++;
const processOptions: RawProcessOptions = {
command: rg.rgPath,
command: rgPath,
args: ["--vimgrep", "-S", "--color=always",
"--colors=path:fg:red",
"--colors=line:fg:green",
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9712,9 +9712,9 @@ vscode-languageserver@^3.4.3:
vscode-languageserver-protocol "3.5.1"
vscode-uri "^1.0.1"

vscode-ripgrep@^0.7.1-patch.0:
version "0.7.1-patch.0"
resolved "https://registry.yarnpkg.com/vscode-ripgrep/-/vscode-ripgrep-0.7.1-patch.0.tgz#738be8b6da5cb9a8807b528595a884b0dfcb60a5"
vscode-ripgrep@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/vscode-ripgrep/-/vscode-ripgrep-1.0.0.tgz#99d81e96cc2437a1bc20f28facbcca72516e9c73"

vscode-uri@^1.0.0, vscode-uri@^1.0.1:
version "1.0.1"
Expand Down

0 comments on commit eb1ab0b

Please sign in to comment.