Skip to content

Use the word under the cursor as default for git grep search #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"name": "Launch Extension",
"type": "extensionHost",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
"type": "pwa-extensionHost"
}
]
}
10 changes: 2 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
"version": "2.0.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isWatching": true,
"isBackground": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.3.0",
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
"mocha": "^2.3.3",
"typescript": "^2.3.0",
"vscode": "^1.0.0"
},
"dependencies": {
"shell-escape": "^0.2.0",
Expand Down
15 changes: 14 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ const projectRoot = workspace.rootPath ? workspace.rootPath : '.';
export function activate(context: ExtensionContext) {
(async () => {
const disposable = commands.registerCommand('extension.gitGrep', async () => {
const query = await window.showInputBox({ prompt: 'Please input search word.' })
// Get the current editor
let wordText = ''
let editor = window.activeTextEditor;
if (editor) {
// Get word under cursor position
let wordRange = editor.document.getWordRangeAtPosition(editor.selection.start);
if (!wordRange) {
wordText = '';
}
// Get word text
wordText = editor.document.getText(wordRange);
}

const query = await window.showInputBox({ prompt: 'Please input search word.', value: wordText })
const command = quote(['git', 'grep', '-H', '-n', '-e', query]);
const fetchItems = (): Promise<QuickPickItemWithPath[]> => new Promise((resolve, reject) => {
exec(command, { cwd: projectRoot, maxBuffer: 2000 * 1024 }, (err, stdout, stderr) => {
Expand Down