Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit c28b4d1

Browse files
authored
Merge pull request #8 from larizzatg/feat-so-searcher
feat: stack overflow menu search
2 parents 5794ba2 + cfb2b13 commit c28b4d1

8 files changed

Lines changed: 59 additions & 7 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "larizzatg",
44
"displayName": "voltdev",
55
"description": "Virtual assistant for developers helping ease the burden of daily tasks",
6-
"version": "0.0.1",
6+
"version": "0.1.0",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/larizzatg/voltdev"
@@ -54,8 +54,27 @@
5454
"command": "voltdev.state.clear",
5555
"category": "⚡ Voltdev",
5656
"title": "Clear State"
57+
},
58+
{
59+
"command": "voltdev.stack-overflow.search",
60+
"category": "⚡ Voltdev",
61+
"title": "Search in stack overflow"
5762
}
58-
]
63+
],
64+
"menus": {
65+
"editor/context": [
66+
{
67+
"command": "voltdev.stack-overflow.search",
68+
"when": "editorHasSelection"
69+
}
70+
],
71+
"commandPalette": [
72+
{
73+
"command": "voltdev.stack-overflow.search",
74+
"when": "editorHasSelection"
75+
}
76+
]
77+
}
5978
},
6079
"scripts": {
6180
"vscode:prepublish": "npm run compile",

src/commands/CommandType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export enum CommandType {
88
WORK_SESSION_END = 'voltdev.work-session.end',
99
WORK_SESSION_ADD_TASKS = 'voltdev.work-session.tasks.add',
1010
WORK_SESSION_SET_MIT = 'voltdev.work-session.tasks.mit',
11-
WORK_SESSION_SET_ACTIVE_TASK = 'voltdev.work-session.tasks.active'
11+
WORK_SESSION_SET_ACTIVE_TASK = 'voltdev.work-session.tasks.active',
12+
STACK_OVERFLOW_SEARCH = 'voltdev.stack-overflow.search'
1213
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const STACK_OVERFLOW_URL = 'https://stackoverflow.com';

src/extension.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { TodoRepository } from './repositories/TodoRepository';
33
import { CommandType } from './commands/CommandType';
44
import { Todo } from './entities/Todo';
55
import { WorkSessionRepository } from './repositories/WorkSessionRepository';
6-
import { TodoManager } from './manager/TodoManager';
7-
import { WorkSessionManager } from './manager/WorkSessionManager';
6+
import { TodoManager } from './managers/TodoManager';
7+
import { WorkSessionManager } from './managers/WorkSessionManager';
88
import { ExtensionState } from './repositories/ExtensionState';
99
import { StatusBar } from './ui';
10+
import { StackOverflowManager } from './managers/StackOverflowManager';
1011

1112
export function activate(context: vscode.ExtensionContext): void {
1213
const statusBar = new StatusBar();
@@ -17,6 +18,7 @@ export function activate(context: vscode.ExtensionContext): void {
1718

1819
const todoManager = new TodoManager(state);
1920
const workSessionManager = new WorkSessionManager(state);
21+
const stackOverflowManager = new StackOverflowManager();
2022

2123
context.subscriptions.push(statusBar);
2224
statusBar.update(workSessionManager.getActiveTask());
@@ -88,6 +90,12 @@ export function activate(context: vscode.ExtensionContext): void {
8890
statusBar.update(workSessionManager.getActiveTask());
8991
})
9092
);
93+
94+
context.subscriptions.push(
95+
vscode.commands.registerCommand(CommandType.STACK_OVERFLOW_SEARCH, () => {
96+
stackOverflowManager.searchInBrowser();
97+
})
98+
);
9199
}
92100

93101
// this method is called when your extension is deactivated
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as vscode from 'vscode';
2+
import { STACK_OVERFLOW_URL } from '../constants';
3+
4+
enum StackOverflowManagerErrors {
5+
NOTHING_SELECTED = 'There is nothing selected in the editor'
6+
}
7+
8+
export class StackOverflowManager {
9+
async searchInBrowser(): Promise<void> {
10+
const editor = vscode.window.activeTextEditor;
11+
const selection = editor?.document.getText(editor.selection);
12+
if (!editor || !selection) {
13+
return Promise.reject(
14+
new Error(StackOverflowManagerErrors.NOTHING_SELECTED)
15+
);
16+
}
17+
const question = selection.split(' ').join('+');
18+
const language = editor.document.languageId;
19+
const tags = language !== 'plaintext' ? `+[${language}]` : '';
20+
const search = `${STACK_OVERFLOW_URL}/search?q=${question}${tags}`;
21+
await vscode.env.openExternal(vscode.Uri.parse(search, false));
22+
}
23+
}

0 commit comments

Comments
 (0)