Skip to content

Commit

Permalink
Added support for empty query to docset (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
loganintech authored and deerawan committed Jul 5, 2017
1 parent 98fd7d4 commit 4bc8c15
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ Choose in top menu `Code -> Preferences -> Keyboard Shortcuts` or using shortcut

Add one or two lines below
```json
{ "key": "your_shortcut", "command": "extension.dash.specific" }, // search in specific docset
{ "key": "your_shortcut", "command": "extension.dash.specific" }, // search selection in corresponding docset
{ "key": "your_shortcut", "command": "extension.dash.all" } // search in all docset
{ "key": "your_shortcut", "command": "extension.dash.emptySyntax" } // open dash with current file's docset open
{ "key": "your_shortcut", "command": "extension.dash.searchSyntax" } // open dash with custom string and current file's docset
```

## License
Expand Down
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@
"Other"
],
"activationEvents": [
"onCommand:extension.dash.all",
"onCommand:extension.dash.specific",
"onCommand:extension.dash.all"
"onCommand:extension.dash.customSyntax",
"onCommand:extension.dash.emptySyntax"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "extension.dash.specific",
"title": "Search in Dash for current syntax"
"title": "Search in Dash for current selection"
},
{
"command": "extension.dash.all",
"title": "Search in Dash for all documentation"
},
{
"command": "extension.dash.emptySyntax",
"title": "Search in Dash for current language documentation"
},
{
"command": "extension.dash.customSyntax",
"title": "Search in Dash for a custom string"
}
],
"keybindings": [
Expand All @@ -52,6 +62,18 @@
"key": "ctrl+alt+h",
"mac": "ctrl+alt+h",
"when": "editorTextFocus"
},
{
"command": "extension.dash.emptySyntax",
"key": "ctrl+shift+h",
"mac": "ctrl+shift+h",
"when": "editorTextFocus"
},
{
"command": "extension.dash.customSyntax",
"key": "alt+h",
"mac": "alt+h",
"when": "editorTextFocus"
}
],
"configuration": {
Expand Down
50 changes: 47 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { window, workspace, commands, ExtensionContext, TextEditor, Selection } from 'vscode';
import { window, workspace, commands, ExtensionContext, TextEditor, Selection, InputBoxOptions } from 'vscode';
import { exec } from 'child_process';
import { Dash } from './dash';
import { platform } from 'os';
Expand All @@ -14,10 +14,18 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand('extension.dash.all', () => {
searchAll();
}));

context.subscriptions.push(commands.registerCommand('extension.dash.emptySyntax', () => {
searchEmptySyntax();
}));

context.subscriptions.push(commands.registerCommand('extension.dash.customSyntax', () => {
searchCustomWithSyntax();
}));
}

/**
* Search in dash for specific syntax documentation
* Search in dash for selection syntax documentation
*/
function searchSpecific() {
var editor = getEditor();
Expand All @@ -36,12 +44,48 @@ function searchSpecific() {
function searchAll() {
var editor = getEditor();
var query = getSelectedText(editor);

var dash = new Dash(OS);

exec(dash.getCommand(query));
}

/**
* Search in dash for editor syntax documentation
*/
function searchEmptySyntax() {

var editor = getEditor();
var query = "";
var languageId = editor.document.languageId;
var docsets = getDocsets(languageId);
var dash = new Dash(OS);

exec(dash.getCommand(query, docsets));
}

/**
* Search in dash for editor syntax documentation with a custom query
*/
function searchCustomWithSyntax() {

var editor = getEditor();
var languageId = editor.document.languageId;
var docsets = getDocsets(languageId);
var dash = new Dash(OS);

var inputOptions: InputBoxOptions = {
placeHolder: "Something to search in Dash.",
prompt: "Enter something to search for in Dash."
}

window.showInputBox(inputOptions)
.then((query: string) => {
if (query) {//If they actually input code
exec(dash.getCommand(query, docsets)); //Open it in dash
}
})
}

/**
* Get vscode active editor
*
Expand Down

0 comments on commit 4bc8c15

Please sign in to comment.