Skip to content

Commit

Permalink
Ripgrep search
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 15, 2017
1 parent 066699c commit 62ec995
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 75 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
"${workspaceRoot}/out/**/*.js"
]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Search process",
"port": 7890,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/**/*.js"
]
},
{
"type": "node",
"request": "attach",
Expand Down
6 changes: 3 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"semver": "4.3.6",
"v8-profiler": "jrieken/v8-profiler#vscode",
"vscode-debugprotocol": "1.17.0",
"vscode-ripgrep": "0.0.8",
"vscode-ripgrep": "0.0.10",
"vscode-textmate": "^3.1.1",
"winreg": "1.2.0",
"xterm": "Tyriar/xterm.js#vscode-release/1.11",
Expand Down
3 changes: 3 additions & 0 deletions src/typings/vscode-ripgrep.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'vscode-ripgrep' {
export const rgPath: string;
}
51 changes: 4 additions & 47 deletions src/vs/workbench/parts/search/browser/searchViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Viewlet } from 'vs/workbench/browser/viewlet';
import { Match, FileMatch, SearchModel, FileMatchOrMatch, IChangeEvent, ISearchWorkbenchService } from 'vs/workbench/parts/search/common/searchModel';
import { QueryBuilder } from 'vs/workbench/parts/search/common/searchQuery';
import { MessageType, InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { getExcludes, ISearchProgressItem, ISearchComplete, ISearchQuery, IQueryOptions, ISearchConfiguration } from 'vs/platform/search/common/search';
import { getExcludes, ISearchComplete, ISearchQuery, IQueryOptions, ISearchConfiguration } from 'vs/platform/search/common/search';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -988,10 +988,7 @@ export class SearchViewlet extends Viewlet {
private onQueryTriggered(query: ISearchQuery, excludePattern: string, includePattern: string): void {
this.viewModel.cancelSearch();

// Progress total is 100.0% for more progress bar granularity
let progressTotal = 1000;
let progressRunner = this.progressService.show(progressTotal);
let progressWorked = 0;
let progressRunner = this.progressService.show(/*infinite=*/true);

this.loading = true;
this.searchWidget.searchInput.clearMessage();
Expand All @@ -1015,14 +1012,7 @@ export class SearchViewlet extends Viewlet {
let isDone = false;
let onComplete = (completed?: ISearchComplete) => {
isDone = true;

// Complete up to 100% as needed
if (completed) {
progressRunner.worked(progressTotal - progressWorked);
setTimeout(() => progressRunner.done(), 200);
} else {
progressRunner.done();
}
progressRunner.done();

this.onSearchResultsChanged().then(() => autoExpand(true));
this.viewModel.replaceString = this.searchWidget.getReplaceValue();
Expand Down Expand Up @@ -1126,18 +1116,7 @@ export class SearchViewlet extends Viewlet {
}
};

let total: number = 0;
let worked: number = 0;
let visibleMatches = 0;
let onProgress = (p: ISearchProgressItem) => {
// Progress
if (p.total) {
total = p.total;
}
if (p.worked) {
worked = p.worked;
}
};

// Handle UI updates in an interval to show frequent progress and results
let uiRefreshHandle = setInterval(() => {
Expand All @@ -1146,28 +1125,6 @@ export class SearchViewlet extends Viewlet {
return;
}

// Progress bar update
let fakeProgress = true;
if (total > 0 && worked > 0) {
let ratio = Math.round((worked / total) * progressTotal);
if (ratio > progressWorked) { // never show less progress than what we have already
progressRunner.worked(ratio - progressWorked);
progressWorked = ratio;
fakeProgress = false;
}
}

// Fake progress up to 90%, or when actual progress beats it
const fakeMax = 900;
const fakeMultiplier = 12;
if (fakeProgress && progressWorked < fakeMax) {
// Linearly decrease the rate of fake progress.
// 1 is the smallest allowed amount of progress.
const fakeAmt = Math.round((fakeMax - progressWorked) / fakeMax * fakeMultiplier) || 1;
progressWorked += fakeAmt;
progressRunner.worked(fakeAmt);
}

// Search result tree update
const fileCount = this.viewModel.searchResult.fileCount();
if (visibleMatches !== fileCount) {
Expand All @@ -1188,7 +1145,7 @@ export class SearchViewlet extends Viewlet {

this.searchWidget.setReplaceAllActionState(false);
// this.replaceService.disposeAllReplacePreviews();
this.viewModel.search(query).done(onComplete, onError, onProgress);
this.viewModel.search(query).done(onComplete, onError);
}

private updateSearchResultCount(): void {
Expand Down
27 changes: 4 additions & 23 deletions src/vs/workbench/services/search/node/rawSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import objects = require('vs/base/common/objects');
import scorer = require('vs/base/common/scorer');
import strings = require('vs/base/common/strings');
import { PPromise, TPromise } from 'vs/base/common/winjs.base';
import { MAX_FILE_SIZE } from 'vs/platform/files/common/files';
import { FileWalker, Engine as FileSearchEngine } from 'vs/workbench/services/search/node/fileSearch';
import { Engine as TextSearchEngine } from 'vs/workbench/services/search/node/textSearch';
import { TextSearchWorkerProvider } from 'vs/workbench/services/search/node/textSearchWorkerProvider';
import { Engine as FileSearchEngine } from 'vs/workbench/services/search/node/fileSearch';
import { RipgrepEngine } from 'vs/workbench/services/search/node/ripgrepTextSearch';
import { IRawSearchService, IRawSearch, IRawFileMatch, ISerializedFileMatch, ISerializedSearchProgressItem, ISerializedSearchComplete, ISearchEngine } from './search';
import { ICachedSearchStats, IProgress } from 'vs/platform/search/common/search';

Expand All @@ -32,29 +30,12 @@ export class SearchService implements IRawSearchService {

private caches: { [cacheKey: string]: Cache; } = Object.create(null);

private textSearchWorkerProvider: TextSearchWorkerProvider;

public fileSearch(config: IRawSearch): PPromise<ISerializedSearchComplete, ISerializedSearchProgressItem> {
return this.doFileSearch(FileSearchEngine, config, SearchService.BATCH_SIZE);
}

public textSearch(config: IRawSearch): PPromise<ISerializedSearchComplete, ISerializedSearchProgressItem> {
if (!this.textSearchWorkerProvider) {
this.textSearchWorkerProvider = new TextSearchWorkerProvider();
}

let engine = new TextSearchEngine(
config,
new FileWalker({
rootFolders: config.rootFolders,
extraFiles: config.extraFiles,
includePattern: config.includePattern,
excludePattern: config.excludePattern,
filePattern: config.filePattern,
maxFilesize: MAX_FILE_SIZE
}),
this.textSearchWorkerProvider);

let engine = new RipgrepEngine(config);
return this.doTextSearch(engine, SearchService.BATCH_SIZE);
}

Expand Down Expand Up @@ -279,7 +260,7 @@ export class SearchService implements IRawSearchService {
});
}

private doTextSearch(engine: TextSearchEngine, batchSize: number): PPromise<ISerializedSearchComplete, IRawProgressItem<ISerializedFileMatch>> {
private doTextSearch(engine: RipgrepEngine, batchSize: number): PPromise<ISerializedSearchComplete, IRawProgressItem<ISerializedFileMatch>> {
return new PPromise<ISerializedSearchComplete, IRawProgressItem<ISerializedFileMatch>>((c, e, p) => {
// Use BatchedCollector to get new results to the frontend every 2s at least, until 50 results have been returned
const collector = new BatchedCollector<ISerializedFileMatch>(batchSize, p);
Expand Down
Loading

0 comments on commit 62ec995

Please sign in to comment.