├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── images ├── QEboost.png ├── QEboost100.png ├── QEboost200.png ├── QEboost_wide200.png ├── QueryEditorBoost_1.gif ├── QueryEditorBoost_2.gif ├── QueryReconnect.gif ├── QuerySegment.gif ├── setNewQueryTemplate.gif ├── snippetPlaceholders.gif ├── snippetSave.gif ├── snippetVariables.gif └── useDatabase.gif ├── installTypings.js ├── package-lock.json ├── package.json ├── src ├── FileSaver.ts ├── changeDatabase.ts ├── contextSettings.ts ├── extension.ts ├── media │ ├── newquery-inverse.svg │ └── newquery.svg ├── placescript.ts ├── runQuery.ts ├── settingsUpdates.ts ├── snippetHelper.ts ├── telemetryConnect.ts ├── telemetryHelper.ts ├── test │ ├── extension.test.ts │ └── index.ts ├── uninstallQEB.ts └── vscode-snippet-creator │ ├── Snippet.ts │ └── SnippetsManager.ts ├── tsconfig.json └── webpack.config.js /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Expected Behavior 11 | 12 | ## Current Behavior 13 | 14 | 15 | 16 | ## Steps to Reproduce 17 | 1. 18 | 19 | 20 | ## Your Environment 21 | * QEB Version used: 22 | 23 | * Azure Data Studio Version: 24 | * Operating System and version: 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | 14 | **Additional context** 15 | Add any other context or screenshots about the feature request here. 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | extensionListing.json 6 | resources.txt 7 | telemetryConnect.json 8 | dist -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | 6 | // To debug the extension: 7 | // 1. please install the "Azure Data Studio Debug" extension into VSCode 8 | // 2. Ensure azuredatastudio is added to your path: 9 | // - open Azure Data Studio 10 | // - run the command "Install 'azuredatastudio' command in PATH" 11 | { 12 | "version": "0.2.0", 13 | "configurations": [ 14 | { 15 | "name": "Extension", 16 | "type": "sqlopsExtensionHost", 17 | "request": "launch", 18 | "runtimeExecutable": "azuredatastudio", 19 | "args": [ 20 | "--extensionDevelopmentPath=${workspaceFolder}" 21 | ], 22 | "outFiles": [ 23 | "${workspaceFolder}/out/**/*.js" 24 | ], 25 | "preLaunchTask": "npm: watch" 26 | }, 27 | { 28 | "name": "Extension Tests", 29 | "type": "sqlopsExtensionHost", 30 | "request": "launch", 31 | "runtimeExecutable": "azuredatastudio", 32 | "args": [ 33 | "--extensionDevelopmentPath=${workspaceFolder}", 34 | "--extensionTestsPath=${workspaceFolder}/out/test" 35 | ], 36 | "outFiles": [ 37 | "${workspaceFolder}/out/test/**/*.js" 38 | ], 39 | "preLaunchTask": "npm: watch" 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | } 9 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | out/**/*.map 5 | src/** 6 | typings/** 7 | .gitignore 8 | tsconfig.json 9 | vsc-extension-quickstart.md 10 | tslint.json 11 | node_modules 12 | out/ 13 | webpack.config.js -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to the "query-power-pack" extension will be documented in this file. 3 | 4 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 5 | 6 | ## [Unreleased] 7 | - Initial release -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | 78 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Query Editor Boost 2 | 3 | Thank you for your interest in contributing to Query Editor Boost! Everyone is welcome, regardless of skill level. 4 | 5 | ## Code of Conduct 6 | 7 | Just a reminder that you're expected to adhere to the [Code of Conduct](https://github.com/dzsquared/query-editor-boost/blob/master/CODE_OF_CONDUCT.md). 8 | 9 | ## Ways to Contribute 10 | 11 | On overview of ways you can help out the Query Editor Boost extension for Azure Data Studio: 12 | 1. [Submitting Issues (Bugs and Feature Requests)](#submitting-issues) 13 | 2. [Tell Your Friends About QEB](#tell-your-friends) 14 | 3. [Submitting Fixes](#submitting-fixes) 15 | 4. [Submitting New Features](#submitting-new-features) 16 | 17 | 18 | # Get Started Contributing 19 | 20 | ## Submitting Issues 21 | 1. Check the [currently open issues](https://github.com/dzsquared/query-editor-boost/issues) for a duplicate issue. 22 | 2. If you find a duplicate, please let us know you are also interested in that issue by adding a :+1: (or other reaction) and/or a comment. 23 | 3. If you're reporting a bug, include as much information as possible. Check for errors in the Dev Tools Console (Help | Toggle Developer Tools). 24 | 4. If you're requesting a new feature and would like to take a stab at implementing it, feel free to let us know! 25 | 26 | ## Test Early Versions 27 | Feel free to "watch" this repository - we will release early versions here before submitting to the Azure Data Studio marketplace. 28 | 29 | ## Tell Your Friends 30 | Consider sharing this extension with your friends. The more the merrier. 31 | 32 | ## Submitting Fixes 33 | 34 | ## Submitting New Features 35 | 36 | 37 | # An Overview of Contributing Code To This Extension 38 | TODO: add more detail 39 | 1. Fork the Query Editor Boost repository 40 | 2. Clone your fork to your machine 41 | 3. Open the fork in VS Code with the Azure Data Studio Debug extension installed 42 | 43 | 44 | # Resources for Building Extensions in Azure Data Studio 45 | TODO: add links to example projects and walk-throughs 46 | 47 | 48 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Expected Behavior 4 | 5 | 6 | 7 | ## Current Behavior 8 | 9 | 10 | 11 | ## Possible Solution 12 | 13 | 14 | 15 | ## Steps to Reproduce (for bugs) 16 | 17 | 18 | 1. 19 | 20 | 21 | ## Your Environment 22 | 23 | * QEB Version used: 24 | 25 | * Azure Data Studio Version: 26 | * Operating System and version: 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 DrewSK 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Azure Data Studio - Query Editor Boost 2 | 3 | This extension adds several features helpful with query writing in Azure Data Studio: 4 | * [new query template](#new-query-from-template) 5 | * [use database keyboard shortcut](#use-database) 6 | * [run current query section](#run-query-section) 7 | * ~~[reconnects query editor](#reconnects-query-editor)~~ 8 | * [friendly snippet editor](#create-new-snippets) 9 | 10 | ![Query Editor Boost](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/QEboost_wide200.png) 11 | 12 | 13 | If you have any questions, feel free to reach out to @SysAdminDrew on Twitter or SQLcommunity.slack.com. 14 | 15 | Report any bugs or request features here: https://github.com/dzsquared/query-editor-boost/issues 16 | 17 | Interested in contributing to this project? Please check out [CONTRIBUTING](https://github.com/dzsquared/query-editor-boost/blob/master/CONTRIBUTING.md) - a work in progress. 18 | 19 | 20 | ## Installation 21 | The current release is available to [download as a .vsix file](https://github.com/dzsquared/query-editor-boost/releases/download/0.4.1/query-editor-boost-0.4.1.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...` 22 | 23 | ### Setup: New Query Template 24 | Edit the setting for "New Query Template" by creating a new query template in the editor and running the command "QE Boost: Set New Query Template". This setting includes the line and character of the cursor position such that the new query window can place the cursor at the beginning, middle, or end of the template. The new query template settings can also be updated directly in the Azure Data Studio settings. 25 | 26 | 27 | # Features 28 | * [new query template](#new-query-from-template) 29 | * [use database keyboard shortcut](#use-database) 30 | * [run current query section](#run-query-section) 31 | * ~~[reconnects query editor](#reconnects-query-editor)~~ 32 | * [friendly snippet editor](#create-new-snippets) 33 | 34 | ## New Query from Template 35 | This extension overrides the default "New Query" keyboard shortcut (`ctrl+n`) with a new query window with a query template of your design. Set the query template with the command "QE Boost: Set New Query Template" or from the Azure Data Studio settings (`ctrl+,`). 36 | *Note: This extension does not override "New Query" in the file or object explorer menus.* 37 | 38 | ![Set and Use New Query Template](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/setNewQueryTemplate.gif) 39 | 40 | 41 | ## Use Database 42 | Change the connected database in a query editor with the "QE Boost: Use Database" command (`ctrl+u`), which opens a searchable picklist. Return to the query editor by hitting `Enter` and your hands never leave the keyboard. 43 | 44 | ![Use Database Shortcut](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/useDatabase.gif) 45 | 46 | ## Run Query Section 47 | With multiple queries in the editor, you can run them by "section" - as delineated by line breaks - with the "QE Boost: Run Query Section" (`ctrl+shift+e`). This command determines where your code is bound by line breaks, highlights that code, then executes the query selection. 48 | 49 | ![Set and Use New Query Template](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/QuerySegment.gif) 50 | 51 | 52 | ## Reconnects Query Editor 53 | As of January 2020, the Azure Data Studio query editor does not automatically reconnect/stay connected when an "untitled" editor is saved for the first time. Query Editor Boost handles this for you and immediately reconnects a query the first time you save it. 54 | 55 | ![Reconnects Query Editor](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/QueryReconnect.gif) 56 | 57 | **Feature removed in February 2020.** 58 | 59 | ## Create New Snippets 60 | 61 | When creating new snippets, move quickly through the syntax and manual JSON editing with friendly snippet creation. QEB makes writing new snippet queries easier by placing placeholders (tab stops) and supported variables in the editor window. When your new snippet is ready, save it right away! 62 | 63 | ### Save the Current Query as a Snippet 64 | Write a new snippet in the query editor and save it directly to your local snippet repository with the command "QE Boost: Save New Snippet." 65 | 66 | Extension for VS Code, licensed under MIT license, adapted for use in this extension. 67 | - https://github.com/nikitaKunevich/vscode-snippet-creator (original JavaScript) 68 | - https://github.com/VincentKos/vscode-snippet-creator (TypeScript refactor) 69 | 70 | ![Save New Snippet](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/snippetSave.gif) 71 | 72 | ### Insert Placeholders 73 | 74 | Use the command "QE Boost: Add Snippet Placeholder" to add placeholders to your query text. Query Editor Boost will parse repetive use of a placeholder through 99 distinct placeholders. 75 | 76 | ![Snippet Placeholders](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/snippetPlaceholders.gif) 77 | 78 | ### Insert Variables 79 | 80 | Use the command "QE Boost: Add Snippet Variable" to add snippet variables to your query text. These variables can automatically insert information such as the current date or directory. 81 | 82 | ![Snippet Variables](https://raw.githubusercontent.com/dzsquared/query-editor-boost/master/images/snippetVariables.gif) 83 | 84 | More info on variables: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets 85 | 86 | 87 | 88 | # Housekeeping 89 | 90 | ## Extension Settings 91 | 92 | This extension contributes the following settings: 93 | 94 | * `newquerytemplate.DefaultQueryTemplate`: the default new query template, an array of strings 95 | * `newquerytemplate.DefaultQueryLine`: the line of the location of cursor placement for new query template, a number 96 | * `newquerytemplate.DefaultQueryCharacter`: the character of the location of cursor placement for new query template, a number 97 | * `queryeditorboost.EagerRunQuery`: ability to disable ctrl/cmd+shift+E shortcut to run current query segment 98 | * `queryeditorboost.telemetry`: ability to disable to telemetry for Query Editor Boost 99 | 100 | ## Known Issues 101 | None at this time 102 | 103 | ## Unknown Issues 104 | Can be raised here: https://github.com/dzsquared/query-editor-boost/issues 105 | 106 | ## Release Notes 107 | 108 | ### 0.4.1 109 | - Removes reconnect on query editor after editor save due to fix in ADS v1.15.0 110 | - Changes to how new query editor creation and connects is handled to align with ADS v1.15.0 111 | 112 | ### 0.4.0 113 | 114 | - Reconnects query editor after editor save 115 | - Packaged with webpack for performance improvement 116 | - Run current query section shortcut (delineated by empty lines) 117 | - New query option in object explorer context menu 118 | - Moves uninstall script to extension manifest 119 | - Adds telemetry 120 | 121 | ### 0.3.0 122 | 123 | - Adds cursor position to new query template 124 | - Adds MacOS keybindings (cmd) 125 | 126 | ### 0.2.0 127 | 128 | - Fixes to new query from template 129 | - Improvements to snippet placeholder creation 130 | 131 | ### 0.1.0 132 | 133 | - Initial release 134 | 135 | ## License 136 | [MIT](https://github.com/dzsquared/query-editor-boost/blob/master/LICENSE) 137 | 138 | -------------------------------------------------------------------------------- /images/QEboost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QEboost.png -------------------------------------------------------------------------------- /images/QEboost100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QEboost100.png -------------------------------------------------------------------------------- /images/QEboost200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QEboost200.png -------------------------------------------------------------------------------- /images/QEboost_wide200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QEboost_wide200.png -------------------------------------------------------------------------------- /images/QueryEditorBoost_1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QueryEditorBoost_1.gif -------------------------------------------------------------------------------- /images/QueryEditorBoost_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QueryEditorBoost_2.gif -------------------------------------------------------------------------------- /images/QueryReconnect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QueryReconnect.gif -------------------------------------------------------------------------------- /images/QuerySegment.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/QuerySegment.gif -------------------------------------------------------------------------------- /images/setNewQueryTemplate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/setNewQueryTemplate.gif -------------------------------------------------------------------------------- /images/snippetPlaceholders.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/snippetPlaceholders.gif -------------------------------------------------------------------------------- /images/snippetSave.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/snippetSave.gif -------------------------------------------------------------------------------- /images/snippetVariables.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/snippetVariables.gif -------------------------------------------------------------------------------- /images/useDatabase.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dzsquared/query-editor-boost/fca540e2dcf7252feab0509e5b3365f20a35b2d2/images/useDatabase.gif -------------------------------------------------------------------------------- /installTypings.js: -------------------------------------------------------------------------------- 1 | var https = require('https'); 2 | var fs = require('fs'); 3 | 4 | function download(filename, url) { 5 | var file = fs.createWriteStream(filename); 6 | var request = https.get(url, function(response) { 7 | response.pipe(file); 8 | }); 9 | } 10 | 11 | console.log('Downloading azdata proposed typings'); 12 | download('src/typings/azdata.proposed.d.ts', 'https://raw.githubusercontent.com/Microsoft/azuredatastudio/master/src/sql/azdata.proposed.d.ts'); 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "query-editor-boost", 3 | "displayName": "Query Editor Boost", 4 | "description": "Helpful add-ons for query editing", 5 | "version": "0.4.1", 6 | "publisher": "drewsk", 7 | "engines": { 8 | "vscode": "^1.38.0", 9 | "azdata": "^1.15.0" 10 | }, 11 | "categories": [ 12 | "Other" 13 | ], 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/dzsquared/query-editor-boost.git" 17 | }, 18 | "activationEvents": [ 19 | "*" 20 | ], 21 | "main": "./dist/extension", 22 | "contributes": { 23 | "commands": [ 24 | { 25 | "command": "dsk.useDatabase", 26 | "title": "QE Boost: Use Database", 27 | "when": "queryEditorVisible && connectionProvider == 'MSSQL'" 28 | }, 29 | { 30 | "command": "dsk.newqueryoption", 31 | "title": "QE Boost: New Query", 32 | "icon": { 33 | "light": "./dist/src/media/newquery.svg", 34 | "dark": "./dist/src/media/newquery-inverse.svg" 35 | } 36 | }, 37 | { 38 | "command": "dsk.createQueryTemplate", 39 | "title": "QE Boost: Set New Query Template", 40 | "when": "queryEditorVisible" 41 | }, 42 | { 43 | "command": "dsk.addSnippetPlaceholder", 44 | "title": "QE Boost: Add Snippet Placeholder", 45 | "when": "queryEditorVisible" 46 | }, 47 | { 48 | "command": "dsk.addSnippetVariable", 49 | "title": "QE Boost: Add Snippet Variable", 50 | "when": "queryEditorVisible" 51 | }, 52 | { 53 | "command": "dsk.saveNewSnippet", 54 | "title": "QE Boost: Save New Snippet", 55 | "when": "queryEditorVisible" 56 | }, 57 | { 58 | "command": "dsk.runQuerySection", 59 | "title": "QE Boost: Run Query Section", 60 | "when": "queryEditorVisible && qeb.EagerRunQuery" 61 | } 62 | ], 63 | "keybindings": [ 64 | { 65 | "key": "ctrl+u", 66 | "command": "dsk.useDatabase", 67 | "when": "queryEditorVisible" 68 | }, 69 | { 70 | "key": "ctrl+n", 71 | "command": "dsk.newqueryoption" 72 | }, 73 | { 74 | "key": "ctrl+shift+e", 75 | "command": "dsk.runQuerySection", 76 | "when": "queryEditorVisible && qeb.EagerRunQuery" 77 | }, 78 | { 79 | "key": "cmd+u", 80 | "command": "dsk.useDatabase", 81 | "when": "queryEditorVisible && isMac" 82 | }, 83 | { 84 | "key": "cmd+n", 85 | "command": "dsk.newqueryoption", 86 | "when": "isMac" 87 | }, 88 | { 89 | "key": "cmd+shift+e", 90 | "command": "dsk.runQuerySection", 91 | "when": "queryEditorVisible && isMac && qeb.EagerRunQuery" 92 | } 93 | ], 94 | "menus": { 95 | "objectExplorer/item/context": [ 96 | { 97 | "command": "dsk.newqueryoption", 98 | "when": "nodeType && nodeType == Server", 99 | "group": "QEB" 100 | }, 101 | { 102 | "command": "dsk.newqueryoption", 103 | "when": "nodeType && nodeType == Database", 104 | "group": "QEB" 105 | } 106 | ] 107 | }, 108 | "configuration": [ 109 | { 110 | "title": "Query Editor Boost", 111 | "properties": { 112 | "newquerytemplate.DefaultQueryTemplate": { 113 | "type": "array", 114 | "default": [ 115 | "--set a default new query template with the command QE Boost: Set New Query Template", 116 | "", 117 | "" 118 | ], 119 | "description": "Query text to insert into new query windows" 120 | }, 121 | "newquerytemplate.DefaultQueryLine": { 122 | "type": "number", 123 | "default": -1 124 | }, 125 | "newquerytemplate.DefaultQueryCharacter": { 126 | "type": "number", 127 | "default": -1 128 | }, 129 | "queryeditorboost.EagerRunQuery": { 130 | "type": "boolean", 131 | "default": true, 132 | "description": "Enables ctrl+shift+E keyboard shortcut to execute current query segment through 'Run Query Section' command" 133 | }, 134 | "queryeditorboost.telemetry": { 135 | "type": "boolean", 136 | "default": true, 137 | "description": "Enable usage data to be sent to an online service" 138 | } 139 | } 140 | } 141 | ] 142 | }, 143 | "scripts": { 144 | "vscode:prepublish": "webpack --mode production", 145 | "webpack": "webpack --mode development", 146 | "webpack-dev": "webpack --mode development --watch", 147 | "compile": "tsc -p ./", 148 | "watch": "tsc -watch -p ./", 149 | "postinstall": "node ./node_modules/vscode/bin/install && node ./node_modules/azdata/bin/install", 150 | "test": "npm run compile && node ./node_modules/vscode/bin/test", 151 | "proposedapi": "node installTypings.js", 152 | "vscode:uninstall": "node ./dist/uninstallQEB" 153 | }, 154 | "devDependencies": { 155 | "@types/mocha": "^2.2.42", 156 | "@types/node": "^7.0.43", 157 | "azdata": "1.0.0", 158 | "file-loader": "^5.0.2", 159 | "ts-loader": "^6.2.1", 160 | "typescript": "^2.6.1", 161 | "vscode": "^1.1.6", 162 | "webpack": "^4.41.5", 163 | "webpack-cli": "^3.3.10" 164 | }, 165 | "dependencies": { 166 | "jsonc-parser": "^2.2.0", 167 | "vscode-extension-telemetry": "^0.1.2" 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/FileSaver.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as fs from 'fs'; 3 | import * as os from 'os'; 4 | 5 | export class FileSaver { 6 | 7 | public async saveThis(textDoc:vscode.TextDocument) { 8 | var settingsPath: string = ''; 9 | var directorySeparator = '/'; 10 | 11 | var vscodeSubdir :string = 'azuredatastudio'; 12 | 13 | switch (os.type()) { 14 | case 'Darwin': 15 | settingsPath = process.env.HOME + "/Library/Application Support/" + vscodeSubdir + "/User/"; 16 | break; 17 | case 'Linux': 18 | settingsPath = process.env.HOME + "/.config/" + vscodeSubdir + "/User/"; 19 | break; 20 | case 'Windows_NT': 21 | settingsPath = process.env.APPDATA + "\\" + vscodeSubdir + "\\User\\"; 22 | directorySeparator = "\\"; 23 | break; 24 | default: 25 | settingsPath = process.env.HOME + "/.config/" + vscodeSubdir + "/User/"; 26 | break; 27 | } 28 | 29 | var newFileAbsolutePath = settingsPath + 'tempquery.sql'; 30 | //+ util.format("snippets%s.json", directorySeparator + snippet.language); 31 | 32 | // var oldDocText = fs.readFileSync(oldFileAbsolutePath); 33 | let oldDocText:string = textDoc.getText(); 34 | // let newFileAbsolutePath:string = ''; 35 | fs.writeFileSync(newFileAbsolutePath, oldDocText); 36 | 37 | const finalUri = vscode.Uri.file(newFileAbsolutePath); 38 | vscode.workspace.openTextDocument(finalUri).then((doc) => { 39 | vscode.window.showTextDocument(doc, {preview: false}); 40 | }); 41 | } 42 | } -------------------------------------------------------------------------------- /src/changeDatabase.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as azdata from 'azdata'; 4 | import * as vscode from 'vscode'; 5 | 6 | 7 | export async function changeDatabase(databaseList, connection) { 8 | let connectionUri = await azdata.connection.getUriForConnection(connection.connectionId); 9 | let dProvider = await azdata.dataprotocol.getProvider(connection.providerId, azdata.DataProviderType.ConnectionProvider); 10 | 11 | if (dProvider.providerId == "MSSQL") { 12 | let selectedDatabase = await vscode.window.showQuickPick(databaseList, 13 | { placeHolder: 'Select Database', "ignoreFocusOut": true} 14 | ); 15 | let useThisDB = selectedDatabase; 16 | 17 | await dProvider.changeDatabase(connectionUri,useThisDB); 18 | await azdata.queryeditor.connect(vscode.window.activeTextEditor.document.uri.toString(), connection.connectionId); 19 | } else { 20 | vscode.window.showErrorMessage("Sorry, use database is only supported for MS SQL"); 21 | } 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /src/contextSettings.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import * as vscode from 'vscode'; 3 | 4 | export function setEagerRunContext() { 5 | const workbenchConfig = vscode.workspace.getConfiguration('queryeditorboost'); 6 | let eagerRun = workbenchConfig.get('EagerRunQuery'); 7 | if (eagerRun) { 8 | vscode.commands.executeCommand('setContext', 'qeb.EagerRunQuery', true); 9 | } else { 10 | vscode.commands.executeCommand('setContext', 'qeb.EagerRunQuery', false); 11 | } 12 | } -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import * as vscode from 'vscode'; 3 | import * as azdata from 'azdata'; 4 | 5 | import { changeDatabase } from './changeDatabase'; 6 | import { initQEB } from './settingsUpdates'; 7 | import { setEagerRunContext } from './contextSettings'; 8 | import { addSnippetPlaceholder, addSnippetVariable, saveNewSnippet } from './snippetHelper'; 9 | import { runQuerySection } from './runQuery'; 10 | 11 | import { placeScript } from './placescript'; 12 | import { telemetryHelper } from './telemetryHelper'; 13 | 14 | require('./media/newquery.svg'); 15 | require('./media/newquery-inverse.svg'); 16 | 17 | export function activate(context: vscode.ExtensionContext) { 18 | // query section execution keyboard shortcut setting 19 | setEagerRunContext(); 20 | context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(setEagerRunContext)); 21 | 22 | // telemetry setup 23 | var tH = new telemetryHelper(context); 24 | tH.sendTelemetry('activated', { }, { }); 25 | 26 | // setup the dashboard task buttons 27 | initQEB(); 28 | 29 | //dsk.createQueryTemplate 30 | var createQueryTemplate = async () => { 31 | tH.sendTelemetry('createQueryTemplate', { }, { }); 32 | 33 | const editor = vscode.window.activeTextEditor; 34 | let cursorPosition = editor.selection.start; 35 | let lineCount = editor.document.lineCount; 36 | let templateBuilder:string[] = []; 37 | 38 | for (let i = 0; i < lineCount; i++) { 39 | templateBuilder.push(editor.document.lineAt(i).text); 40 | } 41 | 42 | var theSettings = vscode.workspace.getConfiguration(); 43 | theSettings.update('newquerytemplate.DefaultQueryTemplate',templateBuilder,vscode.ConfigurationTarget.Global); 44 | theSettings.update('newquerytemplate.DefaultQueryLine', cursorPosition.line, vscode.ConfigurationTarget.Global); 45 | theSettings.update('newquerytemplate.DefaultQueryCharacter', cursorPosition.character, vscode.ConfigurationTarget.Global); 46 | } 47 | var disposable_createQueryTemplate = vscode.commands.registerCommand('dsk.createQueryTemplate', createQueryTemplate); 48 | context.subscriptions.push(disposable_createQueryTemplate); 49 | 50 | //dsk.newqueryoption 51 | var newQueryOption = async (context?: azdata.ObjectExplorerContext) => { 52 | tH.sendTelemetry('newQueryOption', { }, { }); 53 | 54 | let scriptText:string = ""; 55 | const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate'); 56 | let queryTemplateArray = new Array(); 57 | queryTemplateArray = workbenchConfig.get('DefaultQueryTemplate'); 58 | if (queryTemplateArray.length >= 1) { 59 | queryTemplateArray.forEach(function(scriptLine) { 60 | scriptText += scriptLine; 61 | scriptText += ` 62 | `; 63 | }); 64 | } 65 | let pS = new placeScript() 66 | await pS.placescript(scriptText, context); 67 | }; 68 | vscode.commands.registerCommand('dsk.newqueryoption', newQueryOption); 69 | azdata.tasks.registerTask('dsk.newqueryoption', ( 70 | (profile?: azdata.IConnectionProfile, context?: azdata.ObjectExplorerContext) => newQueryOption(context) 71 | ) ); 72 | 73 | var useDatabaseCmd = () => { 74 | tH.sendTelemetry('useDatabaseCmd', { }, { }); 75 | azdata.connection.getCurrentConnection().then( connection => { 76 | if (connection) { 77 | let databaseList = azdata.connection.listDatabases(connection.connectionId); 78 | changeDatabase(databaseList, connection); 79 | } else { 80 | vscode.window.showErrorMessage("No connection found. Connect before switching databases."); 81 | } 82 | }, error => { 83 | console.info(error); 84 | }); 85 | } 86 | var disposable_useDatabase = vscode.commands.registerCommand('dsk.useDatabase', useDatabaseCmd); 87 | context.subscriptions.push(disposable_useDatabase); 88 | 89 | var disposable_addSnippetPlaceholder = vscode.commands.registerCommand('dsk.addSnippetPlaceholder', addSnippetPlaceholder); 90 | context.subscriptions.push(disposable_addSnippetPlaceholder); 91 | 92 | var disposable_addSnippetVariable = vscode.commands.registerCommand('dsk.addSnippetVariable', addSnippetVariable); 93 | context.subscriptions.push(disposable_addSnippetVariable); 94 | 95 | var SaveNewSnippet = () => { 96 | tH.sendTelemetry('saveNewSnippet', { }, { }); 97 | saveNewSnippet(); 98 | } 99 | var disposable_saveNewSnippet = vscode.commands.registerCommand('dsk.saveNewSnippet', SaveNewSnippet); 100 | context.subscriptions.push(disposable_saveNewSnippet); 101 | 102 | var RunQuerySection = () => { 103 | tH.sendTelemetry('runQuerySection', { }, { }); 104 | runQuerySection(); 105 | } 106 | var disposable_runQuerySection = vscode.commands.registerCommand('dsk.runQuerySection', RunQuerySection); 107 | context.subscriptions.push(disposable_runQuerySection); 108 | 109 | } 110 | 111 | export function deactivate() { 112 | } -------------------------------------------------------------------------------- /src/media/newquery-inverse.svg: -------------------------------------------------------------------------------- 1 | newquery_inverse_16x16 -------------------------------------------------------------------------------- /src/media/newquery.svg: -------------------------------------------------------------------------------- 1 | newquery_16x16 -------------------------------------------------------------------------------- /src/placescript.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as sqlops from 'azdata'; 4 | import * as vscode from 'vscode'; 5 | 6 | export class placeScript { 7 | 8 | private connectionId: string = ''; 9 | private dbName: string = ''; 10 | 11 | // places scriptText into fileName editor with current connection 12 | public async placescript(scriptText:string, context?:sqlops.ObjectExplorerContext) { 13 | try { 14 | var connection; 15 | if (context) { 16 | let connection = context.connectionProfile; 17 | this.connectionId = connection.id; 18 | this.dbName = context.connectionProfile.databaseName; 19 | await vscode.commands.executeCommand('explorer.query', context.connectionProfile); 20 | } else { 21 | await vscode.commands.executeCommand('newQuery'); 22 | } 23 | 24 | let editor = vscode.window.activeTextEditor; 25 | let doc = editor.document; 26 | editor.edit(edit => { 27 | edit.insert(new vscode.Position(0, 0), scriptText); 28 | }); 29 | 30 | const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate'); 31 | let lineAt: number = workbenchConfig.get('DefaultQueryLine'); 32 | let charAt: number = workbenchConfig.get('DefaultQueryCharacter'); 33 | if (lineAt >= 0 && charAt >= 0) { 34 | let newPosition: vscode.Position = new vscode.Position(lineAt, charAt); 35 | let newSelection = new vscode.Selection(newPosition, newPosition); 36 | editor.selection = newSelection; 37 | } 38 | 39 | if (context && this.dbName) { 40 | let providerName = context.connectionProfile.providerName; 41 | let dProvider = await sqlops.dataprotocol.getProvider(providerName, sqlops.DataProviderType.ConnectionProvider); 42 | let connectionUri = await sqlops.connection.getUriForConnection(this.connectionId); 43 | await dProvider.changeDatabase(connectionUri,this.dbName); 44 | await sqlops.queryeditor.connect(doc.uri.toString(), this.connectionId); 45 | } 46 | } catch (err) { 47 | vscode.window.showErrorMessage(err); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/runQuery.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import * as vscode from 'vscode'; 3 | 4 | export async function runQuerySection() { 5 | let eagerRun: boolean = false; 6 | 7 | const workbenchConfig = vscode.workspace.getConfiguration('queryeditorboost'); 8 | eagerRun = workbenchConfig.get('EagerRunQuery'); 9 | 10 | if (eagerRun) { 11 | let endPosition: vscode.Position; 12 | let startPosition: vscode.Position; 13 | let cursorPosition: vscode.Position = vscode.window.activeTextEditor.selection.start; 14 | 15 | if (vscode.window.activeTextEditor.document.lineAt(cursorPosition.line).isEmptyOrWhitespace || 16 | vscode.window.activeTextEditor.document.lineCount - 1 == cursorPosition.line) { 17 | endPosition = vscode.window.activeTextEditor.document.lineAt(cursorPosition.line).range.end; 18 | //cursorPosition; 19 | } else { 20 | // iterate down in document to an empty line to find end of segment 21 | let j: number = cursorPosition.line+1; 22 | while ((j <= vscode.window.activeTextEditor.document.lineCount) 23 | && endPosition == undefined) { 24 | if (vscode.window.activeTextEditor.document.lineAt(j).isEmptyOrWhitespace || j == vscode.window.activeTextEditor.document.lineCount - 1) { 25 | endPosition = new vscode.Position(j,vscode.window.activeTextEditor.document.lineAt(j).range.end.character); 26 | 27 | } 28 | j++; 29 | } 30 | } 31 | 32 | // iterate up in document to find start of segment 33 | let i: number = cursorPosition.line - 1; 34 | while (i >= 0 && startPosition == undefined) { 35 | if (vscode.window.activeTextEditor.document.lineAt(i).isEmptyOrWhitespace) { 36 | startPosition = new vscode.Position(i,0); 37 | } 38 | i--; 39 | } 40 | if (startPosition == undefined) { 41 | startPosition = new vscode.Position(0,0); 42 | } 43 | 44 | // highlight selection 45 | vscode.window.activeTextEditor.selections = []; 46 | vscode.window.activeTextEditor.selection = new vscode.Selection(startPosition, endPosition); 47 | 48 | vscode.commands.executeCommand('runQueryKeyboardAction'); 49 | } 50 | } -------------------------------------------------------------------------------- /src/settingsUpdates.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as vscode from 'vscode'; 4 | 5 | export async function initQEB() { 6 | var theSettings = vscode.workspace.getConfiguration(); 7 | 8 | await initServerDashboard(theSettings); 9 | await initDatabaseDashboard(theSettings); 10 | 11 | } 12 | 13 | export async function uninstallQEB() { 14 | var theSettings = vscode.workspace.getConfiguration(); 15 | 16 | await uninstallServerDashboard(theSettings); 17 | await uninstallDatabaseDashboard(theSettings); 18 | vscode.window.showInformationMessage("QE Boost: Dashboard settings have been uninstalled."); 19 | } 20 | 21 | async function initDatabaseDashboard(theConfig: vscode.WorkspaceConfiguration) { 22 | let dashboardDatabaseWidgets = [ 23 | { 24 | "name": "Tasks", 25 | "gridItemConfig": { 26 | "sizex": 1, 27 | "sizey": 2 28 | }, 29 | "widget": { 30 | "tasks-widget": [ 31 | "dsk.newqueryoption", 32 | "mssqlCluster.task.newNotebook", 33 | { 34 | "name": "backup", 35 | "when": "!mssql:iscloud" 36 | }, 37 | { 38 | "name": "restore", 39 | "when": "!mssql:iscloud" 40 | }, 41 | "configureDashboard" 42 | ] 43 | } 44 | }, 45 | { 46 | "name": "Search", 47 | "gridItemConfig": { 48 | "sizex": 1, 49 | "sizey": 2 50 | }, 51 | "widget": { 52 | "explorer-widget": {} 53 | } 54 | } 55 | ]; 56 | 57 | if (theConfig.has('dashboard.database.widgets')) { 58 | let dashWidgetSettings: { widget: object, name: string, gridItemConfig?: object }[] = theConfig.get('dashboard.database.widgets'); 59 | for (var i = 0; i < dashWidgetSettings.length; i++) { 60 | if (dashWidgetSettings[i].name && dashWidgetSettings[i].name == "Tasks") { 61 | let tasksList: string[]; 62 | let qppTasks: string[] = ["dsk.newqueryoption"]; 63 | tasksList = dashWidgetSettings[i].widget["tasks-widget"]; 64 | if (tasksList.indexOf('dsk.newqueryoption') == -1) { 65 | for (var j = 0; j < tasksList.length; j++) { 66 | if (tasksList[j] != "newQuery") { 67 | qppTasks.push(tasksList[j]); 68 | } 69 | } 70 | dashWidgetSettings[i].widget["tasks-widget"] = qppTasks; 71 | } 72 | } 73 | } 74 | theConfig.update('dashboard.database.widgets', dashWidgetSettings, vscode.ConfigurationTarget.Global); 75 | } else { 76 | theConfig.update('dashboard.database.widgets', dashboardDatabaseWidgets, vscode.ConfigurationTarget.Global); 77 | } 78 | 79 | } 80 | async function initServerDashboard(theConfig: vscode.WorkspaceConfiguration) { 81 | let dashboardServerWidgets = [ 82 | { 83 | "name": "Tasks", 84 | "widget": { 85 | "tasks-widget": [ 86 | "dsk.newqueryoption", 87 | { 88 | "name": "restore", 89 | "when": "!mssql:iscloud" 90 | }, 91 | "configureDashboard", 92 | "newQuery", 93 | "mssqlCluster.task.newNotebook" 94 | ] 95 | }, 96 | "gridItemConfig": { 97 | "sizex": 1, 98 | "sizey": 2 99 | } 100 | }, 101 | { 102 | "name": "Search", 103 | "gridItemConfig": { 104 | "sizex": 1, 105 | "sizey": 2 106 | }, 107 | "widget": { 108 | "explorer-widget": {} 109 | } 110 | }, 111 | { 112 | "widget": { 113 | "backup-history-server-insight": null 114 | } 115 | }, 116 | { 117 | "widget": { 118 | "all-database-size-server-insight": null 119 | } 120 | }]; 121 | 122 | if (theConfig.has('dashboard.server.widgets')) { 123 | let dashWidgetSettings: { widget: object, name: string, gridItemConfig?: object }[] = theConfig.get('dashboard.server.widgets'); 124 | for (var i = 0; i < dashWidgetSettings.length; i++) { 125 | if (dashWidgetSettings[i].name && dashWidgetSettings[i].name == "Tasks") { 126 | let tasksList: string[]; 127 | let qppTasks: string[] = ["dsk.newqueryoption"]; 128 | tasksList = dashWidgetSettings[i].widget["tasks-widget"]; 129 | if (tasksList.indexOf('dsk.newqueryoption') == -1) { 130 | for (var j = 0; j < tasksList.length; j++) { 131 | if (tasksList[j] != "newQuery") { 132 | qppTasks.push(tasksList[j]); 133 | } 134 | } 135 | dashWidgetSettings[i].widget["tasks-widget"] = qppTasks; 136 | } 137 | } 138 | } 139 | theConfig.update('dashboard.server.widgets', dashWidgetSettings, vscode.ConfigurationTarget.Global); 140 | } else { 141 | theConfig.update('dashboard.server.widgets', dashboardServerWidgets, vscode.ConfigurationTarget.Global); 142 | } 143 | } 144 | 145 | 146 | async function uninstallDatabaseDashboard(theConfig: vscode.WorkspaceConfiguration) { 147 | if (theConfig.has('dashboard.database.widgets')) { 148 | let dashWidgetSettings: { widget: object, name: string, gridItemConfig?: object }[] = theConfig.get('dashboard.database.widgets'); 149 | for (var i = 0; i < dashWidgetSettings.length; i++) { 150 | if (dashWidgetSettings[i].name && dashWidgetSettings[i].name == "Tasks") { 151 | let tasksList: string[]; 152 | let qppTasks: string[] = ["newQuery"]; //["dsk.newqueryoption"]; 153 | tasksList = dashWidgetSettings[i].widget["tasks-widget"]; 154 | if (tasksList.indexOf('newQuery') == -1) { 155 | for (var j = 0; j < tasksList.length; j++) { 156 | if (tasksList[j] != "dsk.newqueryoption") { 157 | qppTasks.push(tasksList[j]); 158 | } 159 | } 160 | dashWidgetSettings[i].widget["tasks-widget"] = qppTasks; 161 | } 162 | } 163 | } 164 | theConfig.update('dashboard.database.widgets', dashWidgetSettings, vscode.ConfigurationTarget.Global); 165 | } 166 | } 167 | 168 | async function uninstallServerDashboard(theConfig: vscode.WorkspaceConfiguration) { 169 | if (theConfig.has('dashboard.server.widgets')) { 170 | let dashWidgetSettings: { widget: object, name: string, gridItemConfig?: object }[] = theConfig.get('dashboard.server.widgets'); 171 | for (var i = 0; i < dashWidgetSettings.length; i++) { 172 | if (dashWidgetSettings[i].name && dashWidgetSettings[i].name == "Tasks") { 173 | let tasksList: string[]; 174 | let qppTasks: string[] = ["newQuery"]; //["dsk.newqueryoption"]; 175 | tasksList = dashWidgetSettings[i].widget["tasks-widget"]; 176 | if (tasksList.indexOf('newQuery') == -1) { 177 | for (var j = 0; j < tasksList.length; j++) { 178 | if (tasksList[j] != "dsk.newqueryoption") { 179 | qppTasks.push(tasksList[j]); 180 | } 181 | } 182 | dashWidgetSettings[i].widget["tasks-widget"] = qppTasks; 183 | } 184 | } 185 | } 186 | theConfig.update('dashboard.server.widgets', dashWidgetSettings, vscode.ConfigurationTarget.Global); 187 | } 188 | } 189 | 190 | -------------------------------------------------------------------------------- /src/snippetHelper.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import * as vscode from 'vscode'; 3 | import Snippet from "./vscode-snippet-creator/Snippet"; 4 | import SnippetsManager from "./vscode-snippet-creator/SnippetsManager"; 5 | 6 | export async function addSnippetPlaceholder() { 7 | let newPlaceholder = await vscode.window.showInputBox({placeHolder: 'Placeholder Name'}); 8 | let editor = vscode.window.activeTextEditor; 9 | let placeholderIndex = 0; 10 | let testIndex = 1; 11 | 12 | let currentQuery:string = editor.document.getText(); 13 | while (placeholderIndex == 0) { 14 | if ( currentQuery.includes(':'+newPlaceholder+'}') ) { 15 | let probableindex:string = currentQuery.substr(currentQuery.indexOf(':'+newPlaceholder+'}')-2,2); 16 | if (probableindex[0] == '{') { 17 | placeholderIndex = parseInt(probableindex[1]); 18 | } else { 19 | placeholderIndex = parseInt(probableindex); 20 | } 21 | } else { 22 | if (!(currentQuery.includes('${'+testIndex.toString()) ) ) { 23 | placeholderIndex = testIndex; 24 | } 25 | } 26 | testIndex++; 27 | } 28 | 29 | let placeholderSyntax = '${'+placeholderIndex.toString()+':'+ newPlaceholder + '}'; 30 | let cursorLoc:vscode.Position = editor.selection.start; 31 | 32 | editor.edit(edit => { 33 | edit.insert(cursorLoc, placeholderSyntax); 34 | }); 35 | 36 | } 37 | 38 | export async function addSnippetVariable() { 39 | let variableList:vscode.QuickPickItem[] = [ 40 | {label:"CURRENT_YEAR", description: "The current year"}, 41 | {label:"CURRENT_YEAR_SHORT", description: "The current year's last two digits"}, 42 | {label:"CURRENT_MONTH", description: "The month as two digits (example '02')"}, 43 | {label:"CURRENT_MONTH_NAME", description: "The full name of the month (example 'July')"}, 44 | {label:"CURRENT_MONTH_NAME_SHORT", description: "The short name of the month (example 'Jul')"}, 45 | {label:"CURRENT_DATE", description: "The day of the month"}, 46 | {label:"CURRENT_DAY_NAME", description: "The name of day (example 'Monday')"}, 47 | {label:"CURRENT_DAY_NAME_SHORT", description: "The short name of the day (example 'Mon')"}, 48 | {label:"CURRENT_HOUR", description: "The current hour in 24-hour clock format"}, 49 | {label:"CURRENT_MINUTE", description: "The current minute"}, 50 | {label:"CURRENT_SECOND", description: "The current second"}, 51 | {label:"TM_SELECTED_TEXT", description: "The currently selected text or the empty string"}, 52 | {label:"TM_CURRENT_LINE", description: "The contents of the current line"}, 53 | {label:"TM_CURRENT_WORD", description: "The contents of the word under cursor or the empty string"}, 54 | {label:"TM_LINE_INDEX", description: "The zero-index based line number"}, 55 | {label:"TM_LINE_NUMBER", description: "The one-index based line number"}, 56 | {label:"TM_FILENAME", description: "The filename of the current document"}, 57 | {label:"TM_FILENAME_BASE", description: "The filename of the current document without its extensions"}, 58 | {label:"TM_DIRECTORY", description: "The directory of the current document"}, 59 | {label:"TM_FILEPATH", description: "The full file path of the current document"}, 60 | {label:"CLIPBOARD", description: "The contents of your clipboard"}, 61 | {label:"WORKSPACE_NAME", description: "The name of the opened workspace or folder"}, 62 | ]; 63 | let newVariable = await vscode.window.showQuickPick(variableList, 64 | { placeHolder: 'Snippet Variables', ignoreFocusOut: true} 65 | ); 66 | let editor = vscode.window.activeTextEditor; 67 | let placeholderSyntax = '$'+ newVariable.label; 68 | let cursorLoc:vscode.Position = editor.selection.start; 69 | editor.edit(edit => { 70 | edit.insert(cursorLoc, placeholderSyntax); 71 | }); 72 | 73 | } 74 | 75 | export async function saveNewSnippet() { 76 | 77 | try { 78 | const editor = vscode.window.activeTextEditor; 79 | if (editor === undefined) { return; } 80 | 81 | let snippetText = editor.document.getText(); 82 | 83 | var snippet = new Snippet(); 84 | var snippetsManager = new SnippetsManager(); 85 | 86 | if (!(snippetText.length > 0)) { 87 | vscode.window.showWarningMessage('Cannot create snippet from empty string. Select some text first.'); 88 | return; 89 | } 90 | snippet.language = editor.document.languageId; 91 | 92 | const name = await vscode.window.showInputBox({ prompt: 'Enter snippet name' }); 93 | if (name === undefined) { return; } 94 | snippet.name = name; 95 | 96 | const prefix = await vscode.window.showInputBox({ prompt: 'Enter snippet prefix' }); 97 | if (prefix === undefined) { return; } 98 | snippet.prefix = prefix; 99 | 100 | const description = await vscode.window.showInputBox({ prompt: 'Enter snippet description' }); 101 | if (description === undefined) { return; } 102 | snippet.description = description; 103 | 104 | snippet.buildBody(snippetText); 105 | snippetsManager.addSnippet(snippet); 106 | } 107 | catch{ 108 | vscode.window.showErrorMessage("An unknown error appear"); 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /src/telemetryConnect.ts: -------------------------------------------------------------------------------- 1 | export interface telemetryConnect 2 | { 3 | token: string; 4 | } -------------------------------------------------------------------------------- /src/telemetryHelper.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as telemetryConnect from './telemetryConnect'; 3 | 4 | // extension telemetry 5 | import TelemetryReporter from 'vscode-extension-telemetry'; 6 | const extensionId = 'drewsk.query-editor-boost'; 7 | const extension = vscode.extensions.getExtension(extensionId); 8 | let telemetryconnect: telemetryConnect.telemetryConnect = require('../telemetryConnect.json'); 9 | const extensionVersion = extension.packageJSON.version; 10 | const key = telemetryconnect.token; 11 | 12 | export class telemetryHelper { 13 | public reporter: TelemetryReporter; 14 | 15 | constructor(context:vscode.ExtensionContext) { 16 | this.reporter = new TelemetryReporter(extensionId, extensionVersion, key); 17 | context.subscriptions.push(this.reporter); 18 | } 19 | 20 | public sendTelemetry(eventName:string, stringObj:any, numericObj:any) { 21 | var theSettings = vscode.workspace.getConfiguration(); 22 | if ( theSettings.get('queryeditorboost.telemetry') && theSettings.get('telemetry.enableTelemetry') ) { 23 | this.reporter.sendTelemetryEvent(eventName, stringObj, numericObj); 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/test/extension.test.ts: -------------------------------------------------------------------------------- 1 | // 2 | // Note: This example test is leveraging the Mocha test framework. 3 | // Please refer to their documentation on https://mochajs.org/ for help. 4 | // 5 | 6 | // The module 'assert' provides assertion methods from node 7 | import * as assert from 'assert'; 8 | 9 | // You can import and use all API from the 'vscode' module 10 | // as well as import your extension to test it 11 | // import * as vscode from 'vscode'; 12 | // import * as myExtension from '../extension'; 13 | 14 | // Defines a Mocha test suite to group tests of similar kind together 15 | suite("Extension Tests", function () { 16 | 17 | // Defines a Mocha unit test 18 | test("Something 1", function() { 19 | assert.equal(-1, [1, 2, 3].indexOf(5)); 20 | assert.equal(-1, [1, 2, 3].indexOf(0)); 21 | }); 22 | }); -------------------------------------------------------------------------------- /src/test/index.ts: -------------------------------------------------------------------------------- 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 | import * as testRunner from '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.ts (suite, test, etc.) 19 | useColors: true // colored output from test results 20 | }); 21 | 22 | module.exports = testRunner; -------------------------------------------------------------------------------- /src/uninstallQEB.ts: -------------------------------------------------------------------------------- 1 | import { uninstallQEB } from './settingsUpdates'; 2 | 3 | uninstallQEB(); 4 | -------------------------------------------------------------------------------- /src/vscode-snippet-creator/Snippet.ts: -------------------------------------------------------------------------------- 1 | export default class Snippet { 2 | 3 | private _body: string[]; 4 | private _name: string; 5 | private _prefix: string; 6 | private _language: string; 7 | private _description: string; 8 | 9 | constructor () { 10 | this._body = []; 11 | this._name = ''; 12 | this._prefix = ''; 13 | this._language = ''; 14 | this._description = ''; 15 | } 16 | 17 | get body (): string[] { 18 | return this._body; 19 | } 20 | 21 | get name (): string { 22 | return this._name; 23 | } 24 | 25 | set name (name: string) { 26 | this._name = name; 27 | } 28 | 29 | get prefix (): string { 30 | return this._prefix; 31 | } 32 | 33 | set prefix (prefix: string) { 34 | this._prefix = prefix; 35 | } 36 | 37 | get language (): string { 38 | return this._language; 39 | } 40 | 41 | set language (language: string) { 42 | this._language = language; 43 | } 44 | 45 | get description (): string { 46 | return this._description; 47 | } 48 | 49 | set description (description: string) { 50 | this._description = description; 51 | } 52 | 53 | buildBody (code: string) { 54 | this._body = code.replace(/\r/g, '').split("\n"); 55 | } 56 | } -------------------------------------------------------------------------------- /src/vscode-snippet-creator/SnippetsManager.ts: -------------------------------------------------------------------------------- 1 | import Snippet from './Snippet'; 2 | 3 | import * as os from 'os'; 4 | import * as fs from 'fs'; 5 | import * as util from 'util'; 6 | import * as vscode from 'vscode'; 7 | import * as jsonc from 'jsonc-parser'; 8 | 9 | export default class SnippetsManager { 10 | 11 | addSnippet (snippet: Snippet) { 12 | var settingsPath: string = ''; 13 | var directorySeparator = '/'; 14 | 15 | var vscodeSubdir :string = 'azuredatastudio'; 16 | 17 | switch (os.type()) { 18 | case 'Darwin': 19 | settingsPath = process.env.HOME + "/Library/Application Support/" + vscodeSubdir + "/User/"; 20 | break; 21 | case 'Linux': 22 | settingsPath = process.env.HOME + "/.config/" + vscodeSubdir + "/User/"; 23 | break; 24 | case 'Windows_NT': 25 | settingsPath = process.env.APPDATA + "\\" + vscodeSubdir + "\\User\\"; 26 | directorySeparator = "\\"; 27 | break; 28 | default: 29 | settingsPath = process.env.HOME + "/.config/" + vscodeSubdir + "/User/"; 30 | break; 31 | } 32 | 33 | var snippetFile = settingsPath + util.format("snippets%s.json", directorySeparator + snippet.language); 34 | 35 | 36 | if (!fs.existsSync(snippetFile)) { 37 | fs.openSync(snippetFile, "w+"); 38 | fs.writeFileSync(snippetFile, '{}'); 39 | } 40 | 41 | fs.readFile(snippetFile, async (err, text) => { 42 | if (err) { 43 | return; 44 | } 45 | 46 | var jsonText = text.toString(); 47 | var parsingErrors: jsonc.ParseError[] = []; 48 | var snippets = jsonc.parse(jsonText, parsingErrors); 49 | 50 | if (parsingErrors.length > 0) { 51 | var errors: string[] = []; 52 | parsingErrors.forEach((e) => { 53 | var errorText = jsonc.printParseErrorCode(e.error) + " error at the offset " + e.offset; 54 | errors.push(errorText); 55 | }); 56 | 57 | vscode.window.showErrorMessage("Error" + ((parsingErrors.length > 1) ? "s" : "") + " on parsing current " + snippet.language + " snippet file: " + errors.join(', ')); 58 | return; 59 | } 60 | 61 | if (snippets[snippet.name] !== undefined) { 62 | vscode.window.showErrorMessage("A snippet " + snippet.name + " already exists - so adding a unique id"); 63 | let ynOptions = ["No", "Yes"]; 64 | let overwriteYN = await vscode.window.showQuickPick(ynOptions, 65 | { placeHolder: 'Do you want to overwrite a current snippet?', "ignoreFocusOut": true} 66 | ); 67 | snippet.name = snippet.name + "_" + this.uuidv4(); 68 | } 69 | 70 | this.normalizeSnippet(snippet); 71 | 72 | var edit = jsonc.modify(jsonText, [snippet.name], 73 | { 74 | prefix: snippet.prefix, 75 | body: snippet.body, 76 | description: snippet.description 77 | }, 78 | { 79 | formattingOptions: { // based on default vscode snippet format 80 | tabSize: 2, 81 | insertSpaces: false, 82 | eol: '' 83 | } 84 | }); 85 | 86 | var fileContent = jsonc.applyEdits(jsonText, edit); 87 | fs.writeFile(snippetFile, fileContent, () => { }); 88 | vscode.window.showInformationMessage("Snippet " + snippet.name + " added to " + snippet.language + " snippets"); 89 | }); 90 | } 91 | 92 | protected uuidv4 () { 93 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 94 | var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); 95 | return v.toString(16); 96 | }); 97 | } 98 | 99 | protected normalizeSnippet (snippet: Snippet) { 100 | if (snippet.prefix === "") { 101 | snippet.prefix = snippet.name; 102 | } 103 | if (snippet.description === "") { 104 | snippet.description = snippet.name + ' description'; 105 | } 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | /* Strict Type-Checking Option */ 12 | "strict": false, /* enable all strict type-checking options */ 13 | /* Additional Checks */ 14 | "noUnusedLocals": false /* Report errors on unused locals. */ 15 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 16 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 17 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 18 | }, 19 | "exclude": [ 20 | "node_modules", 21 | ".vscode-test" 22 | ] 23 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | //@ts-check 2 | 3 | 'use strict'; 4 | 5 | const path = require('path'); 6 | 7 | /**@type {import('webpack').Configuration}*/ 8 | const config = { 9 | target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ 10 | 11 | entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ 12 | output: { 13 | // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ 14 | path: path.resolve(__dirname, 'dist'), 15 | filename: 'extension.js', 16 | libraryTarget: 'commonjs2', 17 | devtoolModuleFilenameTemplate: '../[resource-path]' 18 | }, 19 | devtool: 'source-map', 20 | externals: { 21 | vscode: '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/ 22 | azdata: 'azdata' 23 | }, 24 | resolve: { 25 | // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader 26 | extensions: ['.ts', '.js', '.svg'] 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.ts$/, 32 | exclude: /node_modules/, 33 | use: [ 34 | { 35 | loader: 'ts-loader' 36 | } 37 | ] 38 | }, 39 | { 40 | test: /\.svg$/, 41 | loader: 'file-loader', 42 | options: { 43 | name: '[path][name].[ext]', 44 | } 45 | } 46 | ] 47 | } 48 | }; 49 | module.exports = config; --------------------------------------------------------------------------------