├── src ├── test │ ├── index.ts │ └── extension.test.ts ├── extension.ts └── parser.ts ├── .gitignore ├── assets ├── icon.png └── remove-comments.gif ├── .vscodeignore ├── .vscode ├── extensions.json ├── settings.json ├── tasks.json └── launch.json ├── tslint.json ├── CHANGELOG.md ├── tsconfig.json ├── LICENSE ├── package.json └── README.md /src/test/index.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/extension.test.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plibither8/vscode-remove-comments/HEAD/assets/icon.png -------------------------------------------------------------------------------- /assets/remove-comments.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plibither8/vscode-remove-comments/HEAD/assets/remove-comments.gif -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | out/**/*.map 5 | src/** 6 | .gitignore 7 | tsconfig.json 8 | vsc-extension-quickstart.md 9 | tslint.json -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "eg2.tslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } -------------------------------------------------------------------------------- /.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 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## Unreleased 8 | - Support for HTML 9 | 10 | ## 1.1.1 - 2018-05-05 11 | 12 | ### Changed 13 | - New icon 14 | 15 | ## 1.1.0 - 2018-05-05 16 | 17 | ### Added 18 | - Seperate commands for remove inline and multiline comments individually. 19 | 20 | ## 1.0.0 - 2018-05-04 21 | ### Added 22 | - Icon 23 | - README -------------------------------------------------------------------------------- /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": true, /* enable all strict type-checking options */ 13 | /* Additional Checks */ 14 | "noUnusedLocals": true /* 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 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Mihir Chaturvedi 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /.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 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "npm: watch" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "npm: watch" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { Parser } from './parser'; 3 | 4 | export function activate(context: vscode.ExtensionContext) { 5 | 6 | let activeEditor: vscode.TextEditor; 7 | let parser: Parser = new Parser(); 8 | 9 | let removeComments = function (n: number) { 10 | 11 | if (!activeEditor || !parser.supportedLanguage) { 12 | return; 13 | } 14 | 15 | if (n === 0) { 16 | parser.FindSingleLineComments(activeEditor); 17 | } 18 | else if (n === 1) { 19 | parser.FindMultilineComments(activeEditor); 20 | } else { 21 | parser.FindSingleLineComments(activeEditor); 22 | parser.FindMultilineComments(activeEditor); 23 | } 24 | 25 | vscode.workspace.applyEdit(parser.edit); 26 | }; 27 | 28 | // Register commands here 29 | 30 | let removeAllCommentsCommand = vscode.commands.registerCommand('extension.removeAllComments', () => { 31 | 32 | if (vscode.window.activeTextEditor) { 33 | activeEditor = vscode.window.activeTextEditor; 34 | parser.SetRegex(activeEditor, activeEditor.document.languageId); 35 | removeComments(2); 36 | } 37 | 38 | }); 39 | 40 | let removeSingleLineCommentsCommand = vscode.commands.registerCommand('extension.removeSingleLineComments', () => { 41 | 42 | if (vscode.window.activeTextEditor) { 43 | activeEditor = vscode.window.activeTextEditor; 44 | parser.SetRegex(activeEditor, activeEditor.document.languageId); 45 | removeComments(0); 46 | } 47 | 48 | }); 49 | 50 | let removeMultilineCommentsCommand = vscode.commands.registerCommand('extension.removeMultilineComments', () => { 51 | 52 | if (vscode.window.activeTextEditor) { 53 | activeEditor = vscode.window.activeTextEditor; 54 | parser.SetRegex(activeEditor, activeEditor.document.languageId); 55 | removeComments(1); 56 | } 57 | 58 | }); 59 | 60 | context.subscriptions.push(removeAllCommentsCommand); 61 | context.subscriptions.push(removeSingleLineCommentsCommand); 62 | context.subscriptions.push(removeMultilineCommentsCommand); 63 | 64 | } 65 | 66 | export function deactivate() { } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remove-comments", 3 | "displayName": "Remove Comments", 4 | "description": "Remove all comments from your code at once! Unclutter and undocument your code in one go!", 5 | "version": "1.2.2", 6 | "publisher": "plibither8", 7 | "license": "MIT", 8 | "icon": "assets/icon.png", 9 | "author": { 10 | "name": "Mihir Chaturvedi" 11 | }, 12 | "homepage": "https://github.com/plibither8/vscode-remove-comments/blob/master/README.md", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/plibither8/vscode-remove-comments" 16 | }, 17 | "bugs": "https://github.com/plibither8/vscode-remove-comments/issues", 18 | "engines": { 19 | "vscode": "^1.22.0" 20 | }, 21 | "categories": [ 22 | "Formatters" 23 | ], 24 | "keywords": [ 25 | "comment", 26 | "comments", 27 | "delete", 28 | "remove" 29 | ], 30 | "activationEvents": [ 31 | "onCommand:extension.removeAllComments", 32 | "onCommand:extension.removeSingleLineComments", 33 | "onCommand:extension.removeMultilineComments" 34 | ], 35 | "gallaryBanner": {}, 36 | "main": "./out/extension", 37 | "contributes": { 38 | "configuration": { 39 | "title": "Remove Comments configuration", 40 | "properties": { 41 | "remove-comments.multilineComments": { 42 | "type": "boolean", 43 | "default": true 44 | } 45 | } 46 | }, 47 | "commands": [ 48 | { 49 | "command": "extension.removeAllComments", 50 | "title": "Remove All Comments" 51 | }, 52 | { 53 | "command": "extension.removeSingleLineComments", 54 | "title": "Remove All Single Line Comments" 55 | }, 56 | { 57 | "command": "extension.removeMultilineComments", 58 | "title": "Remove All Multiline Comments" 59 | } 60 | ] 61 | }, 62 | "scripts": { 63 | "vscode:prepublish": "npm run compile", 64 | "compile": "tsc -p ./", 65 | "watch": "tsc -watch -p ./", 66 | "postinstall": "node ./node_modules/vscode/bin/install", 67 | "test": "npm run compile && node ./node_modules/vscode/bin/test" 68 | }, 69 | "devDependencies": { 70 | "@types/mocha": "^2.2.42", 71 | "@types/node": "^7.0.43", 72 | "tslint": "^5.8.0", 73 | "typescript": "^2.6.1", 74 | "vscode": "^1.1.26" 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚫 Remove Comments 2 | 3 |
4 | 5 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) 6 | [![Version](https://vsmarketplacebadge.apphb.com/version/plibither8.remove-comments.svg)](https://marketplace.visualstudio.com/items?itemName=plibither8.remove-comments) 7 | [![Installs](https://vsmarketplacebadge.apphb.com/installs/plibither8.remove-comments.svg)](https://marketplace.visualstudio.com/items?itemName=plibither8.remove-comments) 8 | 9 | [![Made_with_love_in India](https://img.shields.io/badge/Made_with_love_in-India-DC3545.svg)](https://madewithlove.org.in/) 10 | 11 | ![Demo of usage](assets/remove-comments.gif) 12 | 13 |
14 | 15 | ## 📜 About 16 | 17 | Just copy-pasted some code from somewhere and it's obscenely documented with unnecessary comments everywhere? *Remove Comments* will help you undocument the code and remove all the comments present in the code by doing the job for you. 18 | 19 | *Remove Comments* is a **Visual Studio Code** extension. 20 | 21 | ### ✨ Features 22 | 23 | * Supports both inline and multiline comments 24 | * Support for 60+ languages 🌐 25 | 26 | > Note: This extension does not 'uncomment' the comments present in the code, but removes them completely altogether. 27 | 28 | ### 📝 Usage 29 | 30 | * Install the extension by searching for *Remove Comments* in the editor's 'Extensions' tab, or by launching VS Code Quick Open (Ctrl+P) and entering: 31 | 32 | ```txt 33 | ext install plibither8.remove-comments 34 | ``` 35 | 36 | * Once installed, remove comments in your code by opening the command palette (Ctrl+Shift+P), entering "Remove all comments" and pressing enter. 37 | * Voilà, all the comments are gone 🎉! 38 | 39 | ### 🌐 Supported Languages 40 | 41 |
42 | 43 | List of Supported Languages 44 | 45 | * ACUCOBOL 46 | * Ada 47 | * AL 48 | * C 49 | * COBOL 50 | * Clojure 51 | * CoffeeScript 52 | * CSS 53 | * C++ 54 | * C# 55 | * Dart 56 | * Dockerfile 57 | * Elixir 58 | * Erlang 59 | * F# 60 | * Go 61 | * GraphQL 62 | * Groovy 63 | * Haskell 64 | * Haxe 65 | * Kotlin 66 | * Java 67 | * JavaScript 68 | * JavaScript React 69 | * JSON with comments 70 | * Julia 71 | * LaTex 72 | * Less 73 | * Lisp 74 | * Lua 75 | * Makefile 76 | * Objective-C 77 | * Objective-C++ 78 | * OpenCOBOL 79 | * Pascal 80 | * Perl 81 | * Perl 6 82 | * PHP 83 | * PL/SQL 84 | * PowerShell 85 | * Python 86 | * R 87 | * Racket 88 | * Rust 89 | * Ruby 90 | * Sass 91 | * Scala 92 | * SCSS 93 | * ShaderLab 94 | * ShellScript 95 | * SQL 96 | * Swift 97 | * Terraform 98 | * TypeScript 99 | * TypeScript React 100 | * Visual Basic 101 | * YAML 102 | 103 |
104 | 105 | --- 106 | 107 | ## ⚖️ License 108 | 109 | Copyright (c) Mihir Chaturvedi. All rights reserved. 110 | 111 | Licensed under the [MIT](LICENSE) License. 112 | -------------------------------------------------------------------------------- /src/parser.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | 3 | 4 | export class Parser { 5 | 6 | private delimiters: string[] = []; 7 | private removeRanges: boolean[] = []; 8 | private multilineComments: boolean = false; 9 | private config: any = vscode.workspace.getConfiguration('remove-comments').multilineComments; 10 | 11 | public edit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit(); 12 | public uri: any; 13 | public supportedLanguage = true; 14 | 15 | public SetRegex(activeEditor: vscode.TextEditor, languageCode: string) { 16 | 17 | if (this.setDelimiter(languageCode)) { 18 | this.edit = new vscode.WorkspaceEdit(); 19 | this.uri = activeEditor.document.uri; 20 | } else { 21 | vscode.window.showInformationMessage("Cannot remove comments : unknown language (" + languageCode + ")"); 22 | } 23 | } 24 | 25 | public FindSingleLineComments(activeEditor: vscode.TextEditor): any { 26 | for (var l = 0; l < activeEditor.document.lineCount; l++) { 27 | let line = activeEditor.document.lineAt(l); 28 | let matched = false; 29 | for (var i = 0; i < this.delimiters.length; i++) { 30 | if (!matched) { 31 | let expression = this.delimiters[i].replace(/\//ig, "\\/"); 32 | let removeRange = this.removeRanges[i]; 33 | let regEx = new RegExp(expression, "ig"); 34 | let match = regEx.exec(line.text); 35 | if (match) { 36 | if (removeRange) { 37 | let startPos = new vscode.Position(l, match.index); 38 | let endPos = new vscode.Position(l, line.text.length); 39 | let range = new vscode.Range(startPos, endPos); 40 | this.edit.delete(this.uri, range); 41 | let n = activeEditor.document.getText(range); 42 | console.log("Removing : " + n); 43 | } else { 44 | let startPos = new vscode.Position(l, match.index); 45 | let endPos = new vscode.Position(l + 1, 0); 46 | let range = new vscode.Range(startPos, endPos); 47 | this.edit.delete(this.uri, range); 48 | } 49 | 50 | matched = true; 51 | } 52 | } 53 | } 54 | } 55 | } 56 | 57 | public FindMultilineComments(activeEditor: vscode.TextEditor): void { 58 | 59 | if (!this.multilineComments) { 60 | return; 61 | } 62 | 63 | let text = activeEditor.document.getText(); 64 | let uri = activeEditor.document.uri; 65 | let regEx: RegExp = /(^|[ \t])(\/\*[^*])+([\s\S]*?)(\*\/)/gm; 66 | let match: any; 67 | 68 | while (match = regEx.exec(text)) { 69 | 70 | let startPos = activeEditor.document.positionAt(match.index); 71 | let endPos = activeEditor.document.positionAt(match.index + match[0].length); 72 | let range = new vscode.Range(startPos, endPos); 73 | this.edit.delete(uri, range); 74 | 75 | } 76 | 77 | } 78 | 79 | private setDelimiter(languageCode: string): boolean { 80 | 81 | this.supportedLanguage = true; 82 | this.delimiters = []; 83 | this.removeRanges = []; 84 | 85 | switch (languageCode) { 86 | case "al": 87 | case "c": 88 | case "cpp": 89 | case "csharp": 90 | case "css": 91 | case "dart": 92 | case "fsharp": 93 | case "go": 94 | case "haxe": 95 | case "java": 96 | case "javascript": 97 | case "javascriptreact": 98 | case "jsonc": 99 | case "kotlin": 100 | case "less": 101 | case "pascal": 102 | case "objectpascal": 103 | case "php": 104 | case "rust": 105 | case "scala": 106 | case "swift": 107 | case "typescript": 108 | case "typescriptreact": 109 | this.delimiters.push("//"); 110 | this.removeRanges.push(true); 111 | this.multilineComments = this.config; 112 | break; 113 | 114 | case "coffeescript": 115 | case "dockerfile": 116 | case "elixir": 117 | case "graphql": 118 | case "julia": 119 | case "makefile": 120 | case "perl": 121 | case "perl6": 122 | case "powershell": 123 | case "python": 124 | case "r": 125 | case "ruby": 126 | case "shellscript": 127 | case "yaml": 128 | this.delimiters.push("#"); 129 | this.removeRanges.push(true); 130 | break; 131 | 132 | case "ada": 133 | case "haskell": 134 | case "plsql": 135 | case "sql": 136 | case "lua": 137 | this.delimiters.push("--"); 138 | this.removeRanges.push(true); 139 | break; 140 | 141 | case "vb": 142 | this.delimiters.push("'"); 143 | this.removeRanges.push(true); 144 | break; 145 | 146 | case "erlang": 147 | case "latex": 148 | this.delimiters.push("%"); 149 | this.removeRanges.push(true); 150 | break; 151 | 152 | case "clojure": 153 | case "racket": 154 | case "lisp": 155 | this.delimiters.push(";"); 156 | this.removeRanges.push(true); 157 | break; 158 | 159 | case "terraform": 160 | this.delimiters.push("#"); 161 | this.removeRanges.push(true); 162 | this.multilineComments = this.config; 163 | break; 164 | 165 | case "ACUCOBOL": 166 | case "OpenCOBOL": 167 | case "COBOL": 168 | this.delimiters.push("\\*>"); 169 | this.removeRanges.push(true); 170 | this.delimiters.push("^......\\*"); 171 | this.removeRanges.push(false); 172 | this.multilineComments = false; 173 | break; 174 | default: 175 | this.supportedLanguage = false; 176 | break; 177 | } 178 | 179 | return this.supportedLanguage; 180 | } 181 | 182 | } 183 | --------------------------------------------------------------------------------