├── .eslintrc.json ├── .gitignore ├── .prettierrc ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE.md ├── PUBLISH.md ├── README.md ├── assets └── images │ ├── demo.gif │ └── logo.png ├── jsconfig.json ├── package-lock.json ├── package.json ├── src ├── Configuration.js ├── InputAutoCompletionProvider.js └── extension.js ├── test ├── extension.test.js └── index.js └── webpack.config.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb-base", 3 | "env": { 4 | "browser": false, 5 | "commonjs": true, 6 | "es6": true, 7 | "node": true 8 | }, 9 | "parserOptions": { 10 | "ecmaFeatures": { 11 | "jsx": true 12 | }, 13 | "sourceType": "module" 14 | }, 15 | "rules": { 16 | "comma-dangle": [ 17 | "error", 18 | "never" 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix 3 | .vscode-test 4 | .vscode-test-web 5 | dist -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "singleQuote": true, 4 | "jsxSingleQuote": true, 5 | "printWidth": 100, 6 | "tabWidth": 2, 7 | "semi": true, 8 | "endOfLine": "auto", 9 | "useEditorConfig": false 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | { 3 | "version": "0.1.0", 4 | "configurations": [ 5 | { 6 | "name": "Launch Extension", 7 | "type": "extensionHost", 8 | "request": "launch", 9 | "runtimeExecutable": "${execPath}", 10 | "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], 11 | }, 12 | { 13 | "name": "Launch Tests", 14 | "type": "extensionHost", 15 | "request": "launch", 16 | "runtimeExecutable": "${execPath}", 17 | "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ], 18 | }, 19 | { 20 | "name": "Run Web Extension ", 21 | "type": "extensionHost", 22 | "debugWebWorkerHost": true, 23 | "request": "launch", 24 | "args": [ 25 | "--extensionDevelopmentPath=${workspaceFolder}", 26 | "--extensionDevelopmentKind=web" 27 | ], 28 | "outFiles": [ 29 | "${workspaceFolder}/dist/web/**/*.js" 30 | ], 31 | "preLaunchTask": "npm: watch-web" 32 | }, 33 | { 34 | "name": "Extension Tests", 35 | "type": "extensionHost", 36 | "debugWebWorkerHost": true, 37 | "request": "launch", 38 | "args": [ 39 | "--extensionDevelopmentPath=${workspaceFolder}", 40 | "--extensionDevelopmentKind=web", 41 | "--extensionTestsPath=${workspaceFolder}/dist/web/test/suite/index" 42 | ], 43 | "outFiles": [ 44 | "${workspaceFolder}/dist/web/**/*.js" 45 | ], 46 | "preLaunchTask": "npm: watch-web" 47 | } 48 | ] 49 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "python.pythonPath": "/usr/local/bin/python", 4 | "yaml.customTags": [ 5 | "!And", 6 | "!And sequence", 7 | "!If", 8 | "!If sequence", 9 | "!Not", 10 | "!Not sequence", 11 | "!Equals", 12 | "!Equals sequence", 13 | "!Or", 14 | "!Or sequence", 15 | "!FindInMap", 16 | "!FindInMap sequence", 17 | "!Base64", 18 | "!Join", 19 | "!Join sequence", 20 | "!Cidr", 21 | "!Ref", 22 | "!Sub", 23 | "!Sub sequence", 24 | "!GetAtt", 25 | "!GetAZs", 26 | "!ImportValue", 27 | "!ImportValue sequence", 28 | "!Select", 29 | "!Select sequence", 30 | "!Split", 31 | "!Split sequence" 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | test/** 4 | .gitignore 5 | jsconfig.json 6 | vsc-extension-quickstart.md 7 | .eslintrc.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "google-input-tools" extension will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | ## v0.0.25 - 03-Aug-2023 8 | 9 | - Fix security vulnerabilities with dependent libs 10 | 11 | ## v0.0.24 - 03-Jan-2023 12 | 13 | - Fix badges in README 14 | 15 | ## v0.0.23 - 03-Jan-2023 16 | 17 | - Fixed security vulnerabilities with dependent libs 18 | 19 | ## v0.0.22 - 17-Nov-2022 20 | 21 | - Fixed security vulnerabilities with dependent libs 22 | 23 | ## v0.0.21 - 01-Sep-2022 24 | 25 | - Add support for VS Code web 26 | 27 | ## v0.0.20 - 11-Jun-2022 28 | 29 | - Open up the extension for sponsors. 30 | 31 | ## v0.0.19 - 26-Apr-2022 32 | 33 | - Fixed security vulnerabilities with dependent libs 34 | 35 | ## v0.0.18 - 06-Feb-2022 36 | 37 | - Fix for auto-suggestion failures 38 | 39 | ## v0.0.17 - 06-Feb-2022 40 | 41 | - Fix for auto-suggestion failures 42 | 43 | ## v0.0.16 - 24-Jan-2022 44 | 45 | - Improve the error reporting on transliteration failure 46 | 47 | ## v0.0.15 - 24-Jan-2022 48 | 49 | - Improve the error reporting on transliteration failure 50 | 51 | ## v0.0.14 - 23-Jan-2022 52 | 53 | - Improve the startup time by loading the extension `onStartupFinished` event 54 | 55 | ## v0.0.13 - 23-Jan-2022 56 | 57 | - Fixed security vulnerabilities with dependent libs 58 | 59 | ## v0.0.12 - 17-Aug-2021 60 | 61 | - Fixed security vulnerabilities with dependent libs 62 | 63 | ## v0.0.11 - 11-May-2021 64 | 65 | - Fixed security vulnerabilities with dependent libs 66 | 67 | ## v0.0.10 - 17-Apr-2021 68 | 69 | - Fixed security vulnerabilities with dependent libs 70 | 71 | ## v0.0.9 - 26-Oct-2020 72 | 73 | - Fixed security vulnerabilities with dependent libs 74 | 75 | ## v0.0.8 - 10-Jun-2019 76 | 77 | ### Fixed 78 | 79 | - Fixed security vulnerabilities with dependent libs https://npmjs.com/advisories/886 https://npmjs.com/advisories/803 https://npmjs.com/advisories/813 https://npmjs.com/advisories/788 80 | 81 | ## v0.0.7 - 12-Dec-2018 82 | 83 | ### Fixed 84 | 85 | - Fixed security vulnerabilities with dependent libs https://github.com/dominictarr/event-stream/issues/116 86 | 87 | ## v0.0.6 - 12-Oct-2018 88 | 89 | ### Fixed 90 | 91 | - Fixed security vulnerabilities with dependent libs https://nvd.nist.gov/vuln/detail/CVE-2018-1000620 https://nvd.nist.gov/vuln/detail/CVE-2017-16028 https://nvd.nist.gov/vuln/detail/CVE-2018-3774 92 | 93 | ## v0.0.5 - 03-May-2018 94 | 95 | ### Fixed 96 | 97 | - Fixed security vulnerabilities with dependent libs https://nvd.nist.gov/vuln/detail/CVE-2018-3728 98 | 99 | ## v0.0.4 - 25-Oct-2017 100 | 101 | ### Changed 102 | 103 | - Added support for toggling google input tools from Mac OSX TouchBar 104 | 105 | ## v0.0.3 - 07-Sep-2017 106 | 107 | ### Changed 108 | 109 | - Reversed the order of suggestions to show better match at the top 110 | 111 | ### Fixed 112 | 113 | - Fixed the issue with parsing of search terms (only alphanumeric). 114 | 115 | ## v0.0.2 - 07-Sep-2017 116 | 117 | ### Changed 118 | 119 | - Added description for 'contributes.configuration' 120 | 121 | ## v0.0.1 - 07-Sep-2017 122 | 123 | - Initial release 124 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## License 2 | 3 | The source code is available [here](https://github.com/varunkumar/google-input-tools) under [MIT license](https://varunkumar.mit-license.org/). Please send any bugs, feedback, complaints, patches to me at varunkumar[dot]n[at]gmail[dot]com. 4 | 5 | -- [Varun](https://varunkumar.dev) 6 | -------------------------------------------------------------------------------- /PUBLISH.md: -------------------------------------------------------------------------------- 1 | ## Steps to publish 2 | 3 | - Update [CHANGELOG.md](./CHANGELOG.md). 4 | - Bump up the version in package.json. Follow semantic versions. 5 | - Commit and push master to GitHub 6 | - Test the changes by packaging the extension. `vsce package` 7 | - Test the changes by deleting node_modules and do a fresh install 8 | - `vsce login varunkumar` 9 | - Generate new Personal Access Token from https://varunkumarn.visualstudio.com/ > Profile > Security 10 | (Organizations: All accessible organizations, Scopes: Marketplace-Manage) 11 | - `vsce publish` to publish the package 12 | 13 | ## Steps to publish to open-vsx 14 | 15 | - Generate new access token from https://open-vsx.org/user-settings/tokens 16 | - `ovsx publish -p $OVSX_PAT` to publish the package 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Google Input Tools](https://github.com/varunkumar/google-input-tools) 2 | 3 | [![Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/varunkumar.google-input-tools)](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools) 4 | [![Installs](https://img.shields.io/visual-studio-marketplace/i/varunkumar.google-input-tools)](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools) 5 | [![Downloads](https://img.shields.io/visual-studio-marketplace/d/varunkumar.google-input-tools)](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools) 6 | [![Rating](https://img.shields.io/visual-studio-marketplace/r/varunkumar.google-input-tools)](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools)[![Last Updated](https://img.shields.io/visual-studio-marketplace/last-updated/varunkumar.google-input-tools)](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools) [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](https://varunkumar.mit-license.org/) 7 | 8 | An extension which adds support for Google Input Tools (Transliteration) in VS Code. 9 | 10 | ``` 11 | ext install google-input-tools 12 | ``` 13 | 14 | [Extension marketplace](https://marketplace.visualstudio.com/items?itemName=varunkumar.google-input-tools) 15 | 16 | [Open VSX](https://open-vsx.org/extension/varunkumar/google-input-tools) 17 | 18 | [![Marketplace Version](https://img.shields.io/open-vsx/v/varunkumar/google-input-tools)](https://open-vsx.org/extension/varunkumar/google-input-tools) 19 | [![Installs](https://img.shields.io/open-vsx/dt/varunkumar/google-input-tools)](https://open-vsx.org/extension/varunkumar/google-input-tools) 20 | [![Rating](https://img.shields.io/open-vsx/rating/varunkumar/google-input-tools)](https://open-vsx.org/extension/varunkumar/google-input-tools) [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](https://varunkumar.mit-license.org/) 21 | 22 | ## Usage 23 | 24 | Google Input Tools can be activated through the command 'Toggle Google Input Tools' or using the keybinding (defaults to shift+cmd+i). Once you activate and type any word, it will be transliterated to the chosen language. You can toggle it once you are done typing in your chosen language. Status bar will indicate if Google input tools is active or not. 25 | 26 | ![IDE](assets/images/demo.gif) 27 | 28 | ## Requirements 29 | 30 | No external dependency 31 | 32 | ## Extension Settings 33 | 34 | This extension contributes the following settings: 35 | 36 | - `google.input.tools.language`: [ISO 639-1 Code](https://www.loc.gov/standards/iso639-2/php/code_list.php) of language to transliterate to. For example, 'ta' for Tamil (தமிழ்). List of [supported languages](https://www.google.com/inputtools/help/languages.html). 37 | - `google.input.tools.suggestions`: Number of suggestions to show for the word. Defaults to 5. 38 | 39 | ## TouchBar support 40 | 41 | This extension contributes `Toggle Google Input Tools` TouchBar menu item. You need to have MacBook Pro 2016+ for using this feature. 42 | 43 | ## Keybindings 44 | 45 | You can also set custom shortcut in `keybindings.json` via `Code => Preferences => Keyboard Shortcuts` 46 | For example: 47 | 48 | ``` 49 | [ 50 | { "key": "shift+cmd+i", // set to your favorite shortcut 51 | "command": "extension.googleInputTools", 52 | "when": "editorTextFocus" } 53 | ] 54 | ``` 55 | 56 | ## Known Issues 57 | 58 | None 59 | 60 | ## License 61 | 62 | The source code is available [here](https://github.com/varunkumar/google-input-tools) under [MIT license](https://varunkumar.mit-license.org/). Feel free to use any part of the code. Please send any bugs, feedback, complaints, patches to me at varunkumar[dot]n[at]gmail[dot]com. 63 | 64 | -- [Varun](https://varunkumar.dev) 65 | -------------------------------------------------------------------------------- /assets/images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunkumar/google-input-tools/5f6dec69aa6fcbe745dc08a5a96da8e1ddd5509b/assets/images/demo.gif -------------------------------------------------------------------------------- /assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunkumar/google-input-tools/5f6dec69aa6fcbe745dc08a5a96da8e1ddd5509b/assets/images/logo.png -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "lib": [ 6 | "es6" 7 | ] 8 | }, 9 | "exclude": [ 10 | "node_modules" 11 | ] 12 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google-input-tools", 3 | "displayName": "Google Input Tools", 4 | "description": "Google Input Tools for Code", 5 | "version": "0.0.25", 6 | "publisher": "varunkumar", 7 | "author": "Varunkumar Nagarajan (வருண்குமார் நாகராஜன்)", 8 | "engines": { 9 | "vscode": "^1.64.0" 10 | }, 11 | "sponsor": { 12 | "url": "https://github.com/sponsors/varunkumar" 13 | }, 14 | "categories": [ 15 | "Formatters", 16 | "Other", 17 | "Language Packs" 18 | ], 19 | "activationEvents": [ 20 | "onStartupFinished" 21 | ], 22 | "icon": "assets/images/logo.png", 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/varunkumar/google-input-tools" 26 | }, 27 | "main": "src/extension", 28 | "browser": "dist/web/extension.js", 29 | "contributes": { 30 | "commands": [ 31 | { 32 | "command": "extension.googleInputTools", 33 | "title": "Toggle Google Input Tools", 34 | "icon": "assets/images/logo.png" 35 | } 36 | ], 37 | "keybindings": [ 38 | { 39 | "command": "extension.googleInputTools", 40 | "key": "ctrl+shift+i", 41 | "mac": "cmd+shift+i", 42 | "when": "editorTextFocus" 43 | } 44 | ], 45 | "configuration": { 46 | "title": "Google Input Tools", 47 | "properties": { 48 | "google.input.tools.language": { 49 | "type": "string", 50 | "description": "ISO 639-1 Code of language to transliterate to.", 51 | "default": "ta" 52 | }, 53 | "google.input.tools.suggestions": { 54 | "type": "integer", 55 | "description": "Number of suggestions to show for the word.", 56 | "default": 5 57 | } 58 | } 59 | }, 60 | "menus": { 61 | "touchBar": [ 62 | { 63 | "command": "extension.googleInputTools", 64 | "when": "editorHasCompletionItemProvider && editorTextFocus && !editorReadonly", 65 | "group": "google-input-tools-group" 66 | } 67 | ] 68 | } 69 | }, 70 | "scripts": { 71 | "test": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js", 72 | "pretest": "npm run compile-web", 73 | "vscode:prepublish": "npm run package-web", 74 | "compile-web": "webpack", 75 | "watch-web": "webpack --watch", 76 | "package-web": "webpack --mode production --devtool hidden-source-map", 77 | "lint": "eslint src", 78 | "run-in-browser": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ." 79 | }, 80 | "devDependencies": { 81 | "@types/mocha": "^9.1.0", 82 | "@types/node": "^17.0.15", 83 | "@types/vscode": "^1.64.0", 84 | "eslint": "^8.8.0", 85 | "eslint-config-airbnb-base": "^15.0.0", 86 | "eslint-plugin-import": "^2.25.4", 87 | "mocha": "~9.2.0", 88 | "nanoid": "~3.2.0", 89 | "@vscode/test-web": "^0.0.29", 90 | "ts-loader": "^9.3.1", 91 | "webpack": "^5.76.0", 92 | "webpack-cli": "^4.10.0" 93 | }, 94 | "dependencies": { 95 | "node-fetch": "^2.6.7" 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Configuration.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); // eslint-disable-line 2 | 3 | class Configuration { 4 | static getLanguageCode() { 5 | return vscode.workspace 6 | .getConfiguration() 7 | .get('google.input.tools.language', 'ta'); 8 | } 9 | 10 | static getSuggestionsCount() { 11 | return vscode.workspace 12 | .getConfiguration() 13 | .get('google.input.tools.suggestions', 5); 14 | } 15 | 16 | static getErrrorMessage() { 17 | return 'Unable to transliterate your text.'; 18 | } 19 | } 20 | 21 | module.exports = Configuration; 22 | -------------------------------------------------------------------------------- /src/InputAutoCompletionProvider.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); // eslint-disable-line 2 | const fetch = require('node-fetch'); 3 | const Configuration = require('./Configuration'); 4 | 5 | const getSearchText = (lineText, position) => { 6 | const matches = lineText.substr(0, position.character).trim().match(/\w*$/); 7 | if (matches) { 8 | return matches[0]; 9 | } 10 | return ''; 11 | }; 12 | 13 | /** 14 | * Input auto-completion provider 15 | */ 16 | class InputAutoCompletionProvider { 17 | // eslint-disable-next-line class-methods-use-this 18 | provideCompletionItems(document, position) { 19 | const lineAt = document.lineAt(position); 20 | const lineText = document.getText(lineAt.range); 21 | 22 | const searchText = getSearchText(lineText, position); 23 | const language = Configuration.getLanguageCode(); 24 | const suggestionsCount = Configuration.getSuggestionsCount(); 25 | 26 | if (searchText !== '') { 27 | return new Promise((resolve, reject) => { 28 | fetch( 29 | `https://inputtools.google.com/request?text=${searchText}&itc=${language}-t-i0-und&num=${suggestionsCount}` 30 | ) 31 | // eslint-disable-next-line arrow-parens 32 | .then((res) => res.json()) 33 | .then((response) => { 34 | if (typeof response[0] === 'string' && response[0] !== 'SUCCESS') { 35 | vscode.window.showWarningMessage( 36 | Configuration.getErrrorMessage() + response[0] 37 | ); 38 | reject(new Error(response[0])); 39 | } 40 | const results = response[1][0][1]; 41 | const items = []; 42 | let i = 0; 43 | for (i = 0; i < results.length; i += 1) { 44 | const result = results[i]; 45 | const item = new vscode.CompletionItem(result); 46 | item.filterText = searchText; 47 | item.sortText = String(i); // eslint-disable-line no-plusplus 48 | items.push(item); 49 | } 50 | 51 | // Add the actual typed text to suggestions list 52 | const item = new vscode.CompletionItem(searchText); 53 | item.sortText = String(i); 54 | items.push(item); 55 | 56 | resolve(items); 57 | }) 58 | .catch((err) => { 59 | vscode.window.showWarningMessage( 60 | Configuration.getErrrorMessage() + err 61 | ); 62 | reject(err); 63 | }); 64 | }); 65 | } 66 | return []; 67 | } 68 | } 69 | 70 | module.exports = InputAutoCompletionProvider; 71 | -------------------------------------------------------------------------------- /src/extension.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); // eslint-disable-line 2 | const Configuration = require('./Configuration'); 3 | const InputAutoCompletionProvider = require('./InputAutoCompletionProvider'); 4 | 5 | let disposableProvider; 6 | let disposableStatus; 7 | let isProviderEnabled = false; 8 | 9 | function activate(context) { 10 | const disposable = vscode.commands.registerCommand( 11 | 'extension.googleInputTools', 12 | () => { 13 | if (isProviderEnabled) { 14 | isProviderEnabled = false; 15 | vscode.Disposable.from(disposableProvider).dispose(); 16 | vscode.Disposable.from(disposableStatus).dispose(); 17 | } else { 18 | isProviderEnabled = true; 19 | disposableStatus = vscode.window.setStatusBarMessage( 20 | `Google Input Tools Active (${Configuration.getLanguageCode()})` 21 | ); 22 | const provider = new InputAutoCompletionProvider(); 23 | disposableProvider = vscode.languages.registerCompletionItemProvider( 24 | '*', 25 | provider, 26 | 'a', 27 | 'b', 28 | 'c', 29 | 'd', 30 | 'e', 31 | 'f', 32 | 'g', 33 | 'h', 34 | 'i', 35 | 'j', 36 | 'k', 37 | 'l', 38 | 'm', 39 | 'n', 40 | 'o', 41 | 'p', 42 | 'q', 43 | 'r', 44 | 's', 45 | 't', 46 | 'v', 47 | 'w', 48 | 'x', 49 | 'y', 50 | 'z', 51 | '1', 52 | '2', 53 | '3', 54 | '4', 55 | '5', 56 | '6', 57 | '7', 58 | '8', 59 | '9', 60 | '0' 61 | ); 62 | } 63 | } 64 | ); 65 | 66 | context.subscriptions.push(disposable); 67 | } 68 | exports.activate = activate; 69 | 70 | // this method is called when your extension is deactivated 71 | function deactivate() {} 72 | exports.deactivate = deactivate; 73 | -------------------------------------------------------------------------------- /test/extension.test.js: -------------------------------------------------------------------------------- 1 | /* global suite, test */ 2 | 3 | // 4 | // Note: This example test is leveraging the Mocha test framework. 5 | // Please refer to their documentation on https://mochajs.org/ for help. 6 | // 7 | 8 | // The module 'assert' provides assertion methods from node 9 | const assert = require('assert'); 10 | 11 | // You can import and use all API from the 'vscode' module 12 | // as well as import your extension to test it 13 | const vscode = require('vscode'); // eslint-disable-line 14 | const myExtension = require('../src/extension'); // eslint-disable-line 15 | 16 | suite('Configuration', () => { 17 | const Configuration = require('../src/Configuration'); // eslint-disable-line 18 | test('language code', () => { 19 | assert.notEqual(Configuration.getLanguageCode(), null); 20 | assert.notEqual(Configuration.getLanguageCode(), undefined); 21 | }); 22 | 23 | test('suggestions count', () => { 24 | assert.notEqual(Configuration.getSuggestionsCount(), null); 25 | assert.notEqual(Configuration.getSuggestionsCount(), undefined); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | // 2 | // PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING 3 | // 4 | // This file is providing the test runner to use when running extension tests. 5 | // By default the test runner in use is Mocha based. 6 | // 7 | // You can provide your own test runner if you want to override it by exporting 8 | // a function run(testRoot: string, clb: (error:Error) => void) that the extension 9 | // host can call to run the tests. The test runner is expected to use console.log 10 | // to report the results back to the caller. When the tests are finished, return 11 | // a possible error to the callback or null if none. 12 | 13 | const testRunner = require('vscode/lib/testrunner'); 14 | 15 | // You can directly control Mocha options by uncommenting the following lines 16 | // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info 17 | testRunner.configure({ 18 | ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.) 19 | useColors: true, // colored output from test results 20 | }); 21 | 22 | module.exports = testRunner; 23 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------------------- 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for license information. 4 | *--------------------------------------------------------------------------------------------*/ 5 | 6 | // @ts-check 7 | 8 | // @ts-check 9 | /** @typedef {import('webpack').Configuration} WebpackConfig * */ 10 | 11 | const path = require('path'); 12 | const webpack = require('webpack'); 13 | 14 | /** @type WebpackConfig */ 15 | const webExtensionConfig = { 16 | mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') 17 | target: 'webworker', // extensions run in a webworker context 18 | entry: { 19 | extension: './src/extension.js' 20 | // 'test/suite/index': './src/web/test/suite/index.ts' 21 | }, 22 | output: { 23 | filename: '[name].js', 24 | path: path.join(__dirname, './dist/web'), 25 | libraryTarget: 'commonjs', 26 | devtoolModuleFilenameTemplate: '../../[resource-path]' 27 | }, 28 | resolve: { 29 | mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules 30 | extensions: ['.ts', '.js'], // support ts-files and js-files 31 | alias: { 32 | // provides alternate implementation for node module and source files 33 | }, 34 | fallback: { 35 | // Webpack 5 no longer polyfills Node.js core modules automatically. 36 | // see https://webpack.js.org/configuration/resolve/#resolvefallback 37 | // for the list of Node.js core module polyfills. 38 | assert: require.resolve('assert') 39 | } 40 | }, 41 | module: { 42 | rules: [ 43 | { 44 | test: /\.js$/, 45 | exclude: /node_modules/ 46 | } 47 | ] 48 | }, 49 | plugins: [ 50 | new webpack.optimize.LimitChunkCountPlugin({ 51 | maxChunks: 1 // disable chunks by default since web extensions must be a single bundle 52 | }), 53 | new webpack.ProvidePlugin({ 54 | process: 'process/browser' // provide a shim for the global `process` variable 55 | }) 56 | ], 57 | externals: { 58 | vscode: 'commonjs vscode' // ignored because it doesn't exist 59 | }, 60 | performance: { 61 | hints: false 62 | }, 63 | devtool: 'nosources-source-map', // create a source map that points to the original source file 64 | infrastructureLogging: { 65 | level: 'log' // enables logging required for problem matchers 66 | } 67 | }; 68 | 69 | module.exports = [webExtensionConfig]; 70 | --------------------------------------------------------------------------------