Skip to content

Commit 3056448

Browse files
committed
v0.0.4
1 parent 07c48b6 commit 3056448

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## Features
44

5-
## Requirements
5+
Git grep extension for Visual Studio Code.
66

7+
![screenshot](https://github.com/bokuweb/vscode-git-grep/blob/master/docs/screenshot.gif?raw=true)
78

89
## Extension Settings
910

docs/screenshot.gif

425 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-git-grep",
33
"displayName": "vscode-git-grep",
44
"description": "",
5-
"version": "0.0.3",
5+
"version": "0.0.4",
66
"publisher": "bokuweb",
77
"engines": {
88
"vscode": "^1.5.0"

src/extension.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { quote } from 'shell-quote';
55
import { window, commands, ExtensionContext, workspace, Selection, QuickPickItem, QuickPickOptions } from 'vscode';
66

77
interface QuickPickItemWithPath extends QuickPickItem {
8-
fullpath?: string;
8+
fullPath?: string;
99
}
1010

1111
const projectRoot = workspace.rootPath ? workspace.rootPath : '.';
@@ -17,42 +17,40 @@ export function activate(context: ExtensionContext) {
1717
const query = await window.showInputBox({ prompt: 'Please input search word.' })
1818
const command = quote(['git', 'grep', '-H', '-n', query]);
1919

20-
exec(command, { cwd: projectRoot }, async (err, stdout, stderr) => {
21-
if (stderr) {
22-
window.showErrorMessage(stderr);
23-
return Promise.resolve();
24-
}
25-
const lines = stdout.split(/\n/).filter(l => l !== '');
26-
const items: QuickPickItemWithPath[] = lines.map(l => {
27-
const [fullPath, line, ...desc] = l.split(':');
28-
const path = fullPath.split('/');
29-
return {
30-
label: `${path[path.length - 1]} : ${line}`,
31-
description: desc.join(':'),
32-
fullPath: l,
33-
};
34-
});
35-
if (!lines.length) {
36-
window.showInformationMessage('There are no items')
37-
return Promise.resolve();
38-
}
39-
let item;
40-
try {
41-
const options: QuickPickOptions = {
42-
matchOnDescription: true,
20+
const fetchItems = (): Promise<QuickPickItemWithPath[]> => new Promise((resolve, reject) => {
21+
exec(command, { cwd: projectRoot }, (err, stdout, stderr) => {
22+
if (stderr) {
23+
window.showErrorMessage(stderr);
24+
return resolve([]);
25+
}
26+
const lines = stdout.split(/\n/).filter(l => l !== '');
27+
if (!lines.length) {
28+
window.showInformationMessage('There are no items')
29+
return resolve([]);
4330
}
44-
item = await window.showQuickPick(items, options);
45-
} catch (e) {
46-
window.showErrorMessage(e);
47-
}
48-
49-
const [file, line] = item.fullPath.split(':');
50-
const doc = await workspace.openTextDocument(projectRoot + '/' + file);
51-
await window.showTextDocument(doc);
52-
window.activeTextEditor.selection = new Selection(~~line, 0, ~~line, 0);
53-
commands.executeCommand('cursorUp');
54-
context.subscriptions.push(disposable);
31+
return resolve(lines.map(l => {
32+
const [fullPath, line, ...desc] = l.split(':');
33+
const path = fullPath.split('/');
34+
return {
35+
label: `${path[path.length - 1]} : ${line}`,
36+
description: desc.join(':'),
37+
fullPath: l,
38+
};
39+
}));
40+
41+
});
5542
});
43+
44+
const options: QuickPickOptions = {
45+
matchOnDescription: true,
46+
};
47+
const item = await window.showQuickPick(fetchItems(), options);
48+
const [file, line] = item.fullPath.split(':');
49+
const doc = await workspace.openTextDocument(projectRoot + '/' + file);
50+
await window.showTextDocument(doc);
51+
window.activeTextEditor.selection = new Selection(~~line, 0, ~~line, 0);
52+
commands.executeCommand('cursorUp');
53+
context.subscriptions.push(disposable);
5654
});
5755
})().catch((error) => {
5856
window.showErrorMessage(error);

0 commit comments

Comments
 (0)