提交 fa20275d 编写于 作者: R Rob Lourens

EH search - logging in output channel

上级 0242f78a
......@@ -8,18 +8,22 @@ import { RipgrepTextSearchEngine } from './ripgrepTextSearch';
import { RipgrepFileSearchEngine } from './ripgrepFileSearch';
export function activate(): void {
const provider = new RipgrepSearchProvider();
const outputChannel = vscode.window.createOutputChannel('search-rg');
const provider = new RipgrepSearchProvider(outputChannel);
vscode.workspace.registerSearchProvider('file', provider);
}
class RipgrepSearchProvider implements vscode.SearchProvider {
constructor(private outputChannel: vscode.OutputChannel) {
}
provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Thenable<void> {
const engine = new RipgrepTextSearchEngine();
const engine = new RipgrepTextSearchEngine(this.outputChannel);
return engine.provideTextSearchResults(query, options, progress, token);
}
provideFileSearchResults(options: vscode.SearchOptions, progress: vscode.Progress<vscode.Uri>, token: vscode.CancellationToken): Thenable<void> {
const engine = new RipgrepFileSearchEngine();
const engine = new RipgrepFileSearchEngine(this.outputChannel);
return engine.provideFileSearchResults(options, progress, token);
}
}
\ No newline at end of file
......@@ -22,11 +22,18 @@ export class RipgrepFileSearchEngine {
private rgProc: cp.ChildProcess;
private killRgProcFn: (code?: number) => void;
constructor() {
constructor(private outputChannel: vscode.OutputChannel) {
this.killRgProcFn = () => this.rgProc && this.rgProc.kill();
}
provideFileSearchResults(options: vscode.SearchOptions, progress: vscode.Progress<vscode.Uri>, token: vscode.CancellationToken): Thenable<void> {
this.outputChannel.appendLine(`provideFileSearchResults ${JSON.stringify({
...options,
...{
folder: options.folder.toString()
}
})}`);
return new Promise((resolve, reject) => {
let isDone = false;
const cancel = () => {
......@@ -39,11 +46,10 @@ export class RipgrepFileSearchEngine {
const cwd = options.folder.fsPath;
// TODO logging
// const escapedArgs = rgArgs
// .map(arg => arg.match(/^-/) ? arg : `'${arg}'`)
// .join(' ');
// let rgCmd = `rg ${escapedArgs}\n - cwd: ${cwd}`;
const escapedArgs = rgArgs
.map(arg => arg.match(/^-/) ? arg : `'${arg}'`)
.join(' ');
this.outputChannel.appendLine(`rg ${escapedArgs}\n - cwd: ${cwd}\n`);
this.rgProc = cp.spawn(rgDiskPath, rgArgs, { cwd });
process.once('exit', this.killRgProcFn);
......
......@@ -28,11 +28,18 @@ export class RipgrepTextSearchEngine {
private ripgrepParser: RipgrepParser;
constructor() {
constructor(private outputChannel: vscode.OutputChannel) {
this.killRgProcFn = () => this.rgProc && this.rgProc.kill();
}
provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Thenable<void> {
this.outputChannel.appendLine(`provideTextSearchResults ${query.pattern}, ${JSON.stringify({
...options,
...{
folder: options.folder.toString()
}
})}`);
return new Promise((resolve, reject) => {
const cancel = () => {
this.isDone = true;
......@@ -45,11 +52,10 @@ export class RipgrepTextSearchEngine {
const cwd = options.folder.fsPath;
// TODO logging
// const escapedArgs = rgArgs
// .map(arg => arg.match(/^-/) ? arg : `'${arg}'`)
// .join(' ');
// let rgCmd = `rg ${escapedArgs}\n - cwd: ${cwd}`;
const escapedArgs = rgArgs
.map(arg => arg.match(/^-/) ? arg : `'${arg}'`)
.join(' ');
this.outputChannel.appendLine(`rg ${escapedArgs}\n - cwd: ${cwd}\n`);
this.rgProc = cp.spawn(rgDiskPath, rgArgs, { cwd });
process.once('exit', this.killRgProcFn);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册