Text search - format results more nicely

This commit is contained in:
Rob Lourens
2018-07-11 20:23:05 -07:00
parent d77781882e
commit e7bd806c87

View File

@ -8,16 +8,25 @@ import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const outputChannel = vscode.window.createOutputChannel('Text Search');
context.subscriptions.push(outputChannel);
context.subscriptions.push(vscode.commands.registerCommand('textsearch.doSearch', async () => {
const result = await vscode.window.showInputBox();
if (result) {
outputChannel.show();
let count = 0;
await vscode.workspace.findTextInFiles({ pattern: result }, { }, result => {
outputChannel.appendLine(`${result.uri.fsPath}(${result.range.start.line}, ${result.range.start.character}): ${result.preview.text}`);
count++;
const before = result.preview.text.substring(0, result.preview.match.start.character)
const match = result.preview.text.substring(result.preview.match.start.character, result.preview.match.end.character);
const after = result.preview.text.substring(result.preview.match.end.character);
const annotatedMatchText = `${before}👉${match}👈${after}`;
outputChannel.appendLine(`${result.uri.fsPath}(${result.range.start.line}, ${result.range.start.character}): ${annotatedMatchText}`);
});
outputChannel.appendLine('\n');
outputChannel.appendLine(`Found ${count} results`);
}
}));
}