Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
761462a
commit c5a3448
Showing
8 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "codeseek", | ||
"displayName": "Codeseek", | ||
"description": "Search engine for developers", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.32.3" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"onCommand:extension.codeseek" | ||
], | ||
"main": "./dist/extension", | ||
"main2": "./out/extension.js", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"when": "editorHasSelection", | ||
"command": "extension.codeseek", | ||
"title": "Codeseek this" | ||
} | ||
], | ||
"menus": { | ||
"editor/context": [ | ||
{ | ||
"command": "extension.codeseek", | ||
"group": "navigation" | ||
} | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "webpack --mode production", | ||
"webpack": "webpack --mode development", | ||
"webpack-dev": "webpack --mode development --watch", | ||
"test-compile": "tsc -p ./", | ||
"vscode:prepublish2": "npm run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"pretest": "npm run compile", | ||
"test": "node ./out/test/runTest.js" | ||
}, | ||
"devDependencies": { | ||
"@types/glob": "^7.1.1", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^10.12.21", | ||
"@types/vscode": "^1.32.3", | ||
"glob": "^7.1.4", | ||
"mocha": "^6.1.4", | ||
"ts-loader": "^6.0.4", | ||
"tslint": "^5.12.1", | ||
"typescript": "^3.3.1", | ||
"vscode-test": "^1.0.2", | ||
"webpack": "^4.39.3", | ||
"webpack-cli": "^3.3.7" | ||
}, | ||
"dependencies": { | ||
"open": "^6.4.0", | ||
"querystring": "^0.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// The module 'vscode' contains the VS Code extensibility API | ||
// Import the module and reference it with the alias vscode in your code below | ||
import * as vscode from "vscode"; | ||
|
||
// this method is called when your extension is activated | ||
// your extension is activated the very first time the command is executed | ||
export function activate(context: vscode.ExtensionContext) { | ||
function selectWord(editor: vscode.TextEditor): boolean { | ||
const selection = editor.selection; | ||
const doc = editor.document; | ||
if (selection.isEmpty) { | ||
const cursorWordRange = doc.getWordRangeAtPosition(selection.active); | ||
|
||
if (cursorWordRange) { | ||
const newSe = new vscode.Selection( | ||
cursorWordRange.start.line, | ||
cursorWordRange.start.character, | ||
cursorWordRange.end.line, | ||
cursorWordRange.end.character | ||
); | ||
editor.selection = newSe; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
let disposable = vscode.commands.registerCommand("extension.codeseek", () => { | ||
// The code you place here will be executed every time your command is executed | ||
const editor = vscode.window.activeTextEditor; | ||
|
||
if (!editor) { | ||
return; | ||
} | ||
// check if there is no selection | ||
if (editor.selection.isEmpty) { | ||
selectWord(editor); | ||
} | ||
let text = editor.document.getText(editor.selection); | ||
if (text === "") { | ||
return; | ||
} | ||
var open = require("open"); | ||
if (open) { | ||
if (text.length > 1024) { | ||
text = text.slice(0, 1024); | ||
} | ||
text = require("querystring").escape(text); | ||
const finalUrl = "https://codeseek.com/?s=vscode&q=" + text; | ||
open(finalUrl); | ||
} | ||
}); | ||
context.subscriptions.push(disposable); | ||
} | ||
|
||
// this method is called when your extension is deactivated | ||
export function deactivate() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as path from 'path'; | ||
|
||
import { runTests } from 'vscode-test'; | ||
|
||
async function main() { | ||
try { | ||
// The folder containing the Extension Manifest package.json | ||
// Passed to `--extensionDevelopmentPath` | ||
const extensionDevelopmentPath = path.resolve(__dirname, '../../'); | ||
|
||
// The path to test runner | ||
// Passed to --extensionTestsPath | ||
const extensionTestsPath = path.resolve(__dirname, './suite/index'); | ||
|
||
// Download VS Code, unzip it and run the integration test | ||
await runTests({ extensionDevelopmentPath, extensionTestsPath }); | ||
} catch (err) { | ||
console.error('Failed to run tests'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as assert from 'assert'; | ||
import { before } from 'mocha'; | ||
|
||
// You can import and use all API from the 'vscode' module | ||
// as well as import your extension to test it | ||
import * as vscode from 'vscode'; | ||
// import * as myExtension from '../extension'; | ||
|
||
suite('Extension Test Suite', () => { | ||
before(() => { | ||
vscode.window.showInformationMessage('Start all tests.'); | ||
}); | ||
|
||
test('Sample test', () => { | ||
assert.equal(-1, [1, 2, 3].indexOf(5)); | ||
assert.equal(-1, [1, 2, 3].indexOf(0)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as path from 'path'; | ||
import * as Mocha from 'mocha'; | ||
import * as glob from 'glob'; | ||
|
||
export function run(): Promise<void> { | ||
// Create the mocha test | ||
const mocha = new Mocha({ | ||
ui: 'tdd', | ||
}); | ||
mocha.useColors(true); | ||
|
||
const testsRoot = path.resolve(__dirname, '..'); | ||
|
||
return new Promise((c, e) => { | ||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { | ||
if (err) { | ||
return e(err); | ||
} | ||
|
||
// Add files to the test suite | ||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); | ||
|
||
try { | ||
// Run the mocha test | ||
mocha.run(failures => { | ||
if (failures > 0) { | ||
e(new Error(`${failures} tests failed.`)); | ||
} else { | ||
c(); | ||
} | ||
}); | ||
} catch (err) { | ||
e(err); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": [ | ||
"es6" | ||
], | ||
"sourceMap": true, | ||
"rootDir": "src", | ||
"strict": true /* enable all strict type-checking options */ | ||
/* Additional Checks */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
".vscode-test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"rules": { | ||
"no-string-throw": true, | ||
"no-unused-expression": true, | ||
"no-duplicate-variable": true, | ||
"curly": true, | ||
"class-name": true, | ||
"semicolon": [ | ||
true, | ||
"always" | ||
], | ||
"triple-equals": true | ||
}, | ||
"defaultSeverity": "warning" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//@ts-check | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
/**@type {import('webpack').Configuration}*/ | ||
const config = { | ||
target: 'node', // vscode extensions run in a Node.js-context -> https://webpack.js.org/configuration/node/ | ||
|
||
entry: './src/extension.ts', // the entry point of this extension -> https://webpack.js.org/configuration/entry-context/ | ||
output: { | ||
// the bundle is stored in the 'dist' folder (check package.json) -> https://webpack.js.org/configuration/output/ | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'extension.js', | ||
libraryTarget: 'commonjs2', | ||
devtoolModuleFilenameTemplate: '../[resource-path]' | ||
}, | ||
devtool: 'source-map', | ||
externals: { | ||
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ | ||
}, | ||
resolve: { | ||
// support reading TypeScript and JavaScript files -> https://github.com/TypeStrong/ts-loader | ||
extensions: ['.ts', '.js'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
use: [ | ||
{ | ||
loader: 'ts-loader' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
module.exports = config; |