diff --git a/README.md b/README.md index a5894b6..c8f4290 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Better Comments The Better Comments extension will help you create more human-friendly comments in your code. -With this extension, you will be able to categorise your annotations into: +With this extension, you will be able to categorize your annotations into: * Alerts * Queries * TODOs @@ -80,7 +80,9 @@ The default 5 can be modified to change the colors, and more can be added. ## Supported Languages * Ada +* Auto Hot Key * AL +* Alloy * Apex * AsciiDoc * BrightScript @@ -91,7 +93,9 @@ The default 5 can be modified to change the colors, and more can be added. * Clojure * COBOL * CoffeeScript +* CSON * CSS +* Dafny * Dart * Dockerfile * Elixir @@ -99,8 +103,11 @@ The default 5 can be modified to change the colors, and more can be added. * Erlang * F# * Fortran +* GAS x86/x86_64/AMD64 assembly _(at&t/GNU syntax)_ * gdscript * GenStat +* git config +* gitignore * Go * GraphQL * Groovy @@ -114,14 +121,15 @@ The default 5 can be modified to change the colors, and more can be added. * JSON with comments * Julia * Kotlin -* LaTex (inlc. Bibtex/Biblatex) +* LaTeX (inlc. BibTeX/BibLaTeX & plain TeX) * Less * Lisp * Lua * Makefile * Markdown -* Nim * MATLAB +* NASM/YASM x86/x86_64/AMD64 assembly _(intel syntax) [asm]_ +* Nim * Objective-C * Objective-C++ * Pascal @@ -132,10 +140,12 @@ The default 5 can be modified to change the colors, and more can be added. * PlantUML * PL/SQL * PowerShell +* Promela * Puppet * Python * R * Racket +* Rainmeter _(win10 desktop widget config file [modified ini])_ * Ruby * Rust * SAS @@ -150,6 +160,7 @@ The default 5 can be modified to change the colors, and more can be added. * Swift * Tcl * Terraform +* TOML * Twig * TypeScript * TypeScript React diff --git a/package.json b/package.json index 5b753ed..df6c7c5 100644 --- a/package.json +++ b/package.json @@ -25,91 +25,102 @@ "ui" ], "activationEvents": [ - "onLanguage:ada", - "onLanguage:al", - "onLanguage:apex", - "onLanguage:asciidoc", - "onLanguage:bibtex", - "onLanguage:brightscript", - "onLanguage:c", - "onLanguage:clojure", - "onLanguage:cfml", - "onLanguage:COBOL", - "onLanguage:coffeescript", - "onLanguage:cpp", - "onLanguage:csharp", - "onLanguage:css", - "onLanguage:d", - "onLanguage:dart", - "onLanguage:diagram", - "onLanguage:dockerfile", - "onLanguage:elixir", - "onLanguage:elm", - "onLanguage:erlang", - "onLanguage:flax", - "onLanguage:fsharp", - "onLanguage:fortran-modern", - "onLanguage:gdscript", - "onLanguage:genstat", - "onLanguage:go", - "onLanguage:graphql", - "onLanguage:groovy", - "onLanguage:haskell", - "onLanguage:html", - "onLanguage:haxe", - "onLanguage:hive-sql", - "onLanguage:kotlin", - "onLanguage:java", - "onLanguage:javascript", - "onLanguage:javascriptreact", - "onLanguage:jsonc", - "onLanguage:julia", - "onLanguage:latex", - "onLanguage:less", - "onLanguage:lisp", - "onLanguage:lua", - "onLanguage:makefile", - "onLanguage:markdown", - "onLanguage:matlab", - "onLanguage:nim", - "onLanguage:objective-c", - "onLanguage:objective-cpp", - "onLanguage:objectpascal", - "onLanguage:pascal", - "onLanguage:perl", - "onLanguage:perl6", - "onLanguage:pig", - "onLanguage:plaintext", - "onLanguage:plsql", - "onLanguage:php", - "onLanguage:powershell", - "onLanguage:puppet", - "onLanguage:python", - "onLanguage:r", - "onLanguage:racket", - "onLanguage:ruby", - "onLanguage:rust", - "onLanguage:scala", - "onLanguage:sas", - "onLanguage:sass", - "onLanguage:scss", - "onLanguage:shaderlab", - "onLanguage:shellscript", - "onLanguage:sql", - "onLanguage:stata", - "onLanguage:stylus", - "onLanguage:swift", - "onLanguage:tcl", - "onLanguage:terraform", - "onLanguage:twig", - "onLanguage:typescript", - "onLanguage:typescriptreact", - "onLanguage:vb", - "onLanguage:verilog", - "onLanguage:vue", - "onLanguage:xml", - "onLanguage:yaml" - ], + "onLanguage:ada", + "onLanguage:ahk", + "onLanguage:al", + "onlanguage:alloy", + "onLanguage:apex", + "onLanguage:asciidoc", + "onLanguage:bibtex", + "onLanguage:brightscript", + "onLanguage:c", + "onLanguage:clojure", + "onLanguage:cfml", + "onLanguage:COBOL", + "onLanguage:coffeescript", + "onLanguage:cpp", + "onLanguage:csharp", + "onLanguage:cson", + "onLanguage:css", + "onLanguage:d", + "onlanguage:dafny", + "onLanguage:dart", + "onLanguage:diagram", + "onLanguage:dockerfile", + "onLanguage:elixir", + "onLanguage:elm", + "onLanguage:erlang", + "onLanguage:flax", + "onLanguage:fsharp", + "onLanguage:fortran-modern", + "onLanguage:gas", + "onLanguage:gdscript", + "onLanguage:genstat", + "onlanguage:gitconfig", + "onLanguage:gitignore", + "onLanguage:go", + "onLanguage:graphql", + "onLanguage:groovy", + "onLanguage:haskell", + "onLanguage:html", + "onLanguage:haxe", + "onLanguage:hive-sql", + "onLanguage:kotlin", + "onLanguage:java", + "onLanguage:javascript", + "onLanguage:javascriptreact", + "onLanguage:jsonc", + "onLanguage:julia", + "onLanguage:latex", + "onLanguage:less", + "onLanguage:lisp", + "onLanguage:lua", + "onLanguage:makefile", + "onLanguage:markdown", + "onLanguage:matlab", + "onLanguage:nim", + "onLanguage:objective-c", + "onLanguage:objective-cpp", + "onLanguage:objectpascal", + "onLanguage:pascal", + "onLanguage:perl", + "onLanguage:perl6", + "onLanguage:pig", + "onLanguage:plaintext", + "onLanguage:plsql", + "onLanguage:php", + "onLanguage:powershell", + "onLanguage:promela", + "onLanguage:puppet", + "onLanguage:python", + "onLanguage:r", + "onLanguage:racket", + "onLanguage:rainmeter", + "onLanguage:ruby", + "onLanguage:rust", + "onLanguage:scala", + "onLanguage:sas", + "onLanguage:sass", + "onLanguage:scss", + "onLanguage:shaderlab", + "onLanguage:shellscript", + "onLanguage:sql", + "onLanguage:stata", + "onLanguage:stylus", + "onLanguage:swift", + "onLanguage:tcl", + "onLanguage:terraform", + "onLanguage:tex", + "onLanguage:toml", + "onLanguage:twig", + "onLanguage:typescript", + "onLanguage:typescriptreact", + "onLanguage:vb", + "onLanguage:verilog", + "onLanguage:vue", + "onLanguage:xml", + "onLanguage:yaml" + ], "galleryBanner": { "color": "#e3f4ff", "theme": "light" @@ -128,6 +139,7 @@ "better-comments.multilineComments": { "type": "boolean", "description": "Whether the multiline comment highlighter should be active", + "scope": "language-overridable", "default": true }, "better-comments.highlightPlainText": { @@ -137,6 +149,7 @@ }, "better-comments.tags": { "type": "array", + "scope": "language-overridable", "description": "Tags which are used to color the comments. Changes require a restart of VS Code to take effect", "default": [ { diff --git a/src/extension.ts b/src/extension.ts index 4fc4df1..35ac748 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,7 +12,7 @@ export function activate(context: vscode.ExtensionContext) { // * if no active window is open, return if (!activeEditor) return; - // * if lanugage isn't supported, return + // * if language isn't supported, return if (!parser.supportedLanguage) return; // Finds the single line comments using the language comment delimiter @@ -28,7 +28,7 @@ export function activate(context: vscode.ExtensionContext) { parser.ApplyDecorations(activeEditor); }; - // Get the active editor for the first time and initialise the regex + // Get the active editor for the first time and initialize the regex if (vscode.window.activeTextEditor) { activeEditor = vscode.window.activeTextEditor; diff --git a/src/parser.ts b/src/parser.ts index 95e14bc..3e5035e 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -93,7 +93,7 @@ export class Parser { let text = activeEditor.document.getText(); - // if it's plain text, we have to do mutliline regex to catch the start of the line with ^ + // if it's plain text, we have to do multiline regex to catch the start of the line with ^ let regexFlags = (this.isPlainText) ? "igm" : "ig"; let regEx = new RegExp(this.expression, regexFlags); @@ -247,168 +247,212 @@ export class Parser { switch (languageCode) { case "asciidoc": - this.setCommentFormat("//", "////", "////"); + this.setCommentFormat("//", "////", "////"); + break; + + case "apex": + case "javascript": + case "javascriptreact": + case "typescript": + case "typescriptreact": + this.setCommentFormat("//", "/*", "*/"); + this.highlightJSDoc = true; + break; + + case "al": + case "c": + case "cpp": + case "csharp": + case "dafny": + case "dart": + case "flax": + case "fsharp": + case "go": + case "groovy": + case "haxe": + case "java": + case "jsonc": + case "kotlin": + case "less": + case "pascal": + case "objectpascal": + case "php": + case "promela": + case "rust": + case "scala": + case "sass": + case "scss": + case "shaderlab": + case "stylus": + case "swift": + case "verilog": + case "vue": + this.setCommentFormat("//", "/*", "*/"); + break; + + case "css": + this.setCommentFormat("/*", "/*", "*/"); //? should css even have a single line comment? + break; + + case "coffeescript": + case "cson": + case "dockerfile": + case "gdscript": + case "graphql": + case "julia": + case "makefile": + case "perl": + case "perl6": + case "puppet": + case "r": + case "ruby": + case "shellscript": + case "tcl": + case "toml": + case "yaml": + this.delimiter = "#"; + break; + + case "tcl": + this.delimiter = "#"; + this.ignoreFirstLine = true; + break; + + case "gitconfig": + this.delimiter = "[#;]"; // single line comments can start with either '#', or ';'. (bypasses regex scrubber) break; - case "apex": - case "javascript": - case "javascriptreact": - case "typescript": - case "typescriptreact": - this.setCommentFormat("//", "/*", "*/"); - this.highlightJSDoc = true; + case "gitignore": + this.delimiter = "^#"; // single line comments must be the first character of the line. (bypasses regex scrubber) + this.isPlainText = true; // to enable multiline in regex parsing and allow the /^/ to detect the start fo a line. break; - case "al": - case "c": - case "cpp": - case "csharp": - case "dart": - case "flax": - case "fsharp": - case "go": - case "groovy": - case "haxe": - case "java": - case "jsonc": - case "kotlin": - case "less": - case "pascal": - case "objectpascal": - case "php": - case "rust": - case "scala": - case "sass": - case "scss": - case "shaderlab": - case "stylus": - case "swift": - case "verilog": - case "vue": - this.setCommentFormat("//", "/*", "*/"); - break; - - case "css": - this.setCommentFormat("/*", "/*", "*/"); - break; - - case "coffeescript": - case "dockerfile": - case "gdscript": - case "graphql": - case "julia": - case "makefile": - case "perl": - case "perl6": - case "puppet": - case "r": - case "ruby": - case "shellscript": - case "tcl": - case "yaml": - this.delimiter = "#"; - break; - - case "tcl": - this.delimiter = "#"; - this.ignoreFirstLine = true; - break; - - case "elixir": - case "python": - this.setCommentFormat("#", '"""', '"""'); - this.ignoreFirstLine = true; - break; - - case "nim": - this.setCommentFormat("#", "#[", "]#"); - break; - - case "powershell": - this.setCommentFormat("#", "<#", "#>"); - break; - - case "ada": - case "hive-sql": - case "pig": - case "plsql": - case "sql": - this.delimiter = "--"; - break; - - case "lua": - this.setCommentFormat("--", "--[[", "]]"); - break; - - case "elm": - case "haskell": - this.setCommentFormat("--", "{-", "-}"); - break; - - case "brightscript": - case "diagram": // ? PlantUML is recognized as Diagram (diagram) - case "vb": - this.delimiter = "'"; - break; - - case "bibtex": - case "erlang": - case "latex": - case "matlab": - this.delimiter = "%"; - break; + case "elixir": + case "python": + this.setCommentFormat("#", '"""', '"""'); + this.ignoreFirstLine = true; + break; + + case "nim": + this.setCommentFormat("#", "#[", "]#"); + break; + + case "powershell": + this.setCommentFormat("#", "<#", "#>"); + break; + + case "ada": + case "hive-sql": + case "pig": + case "plsql": + case "sql": + this.delimiter = "--"; + break; + + case "lua": + this.setCommentFormat("--", "--[[", "]]"); + break; + + case "elm": + case "haskell": + this.setCommentFormat("--", "{-", "-}"); + break; + + case "brightscript": + case "diagram": // ? PlantUML is recognized as Diagram (diagram) + case "vb": + this.delimiter = "'"; + break; + + case "bibtex": + case "tex": + case "erlang": + case "matlab": + this.delimiter = "%"; + break; + + case "latex": + // latex has a make shift multiline comment using the `comment` environment. + this.setCommentFormat("%", "\\begin{comment}", "\\end{comment}"); + break; + + case "ahk": + this.setCommentFormat(";", "/*", "*/"); + break; + + case "clojure": + case "racket": + case "lisp": + case "rainmeter": + this.delimiter = ";"; + break; + + case "gas": + case "terraform": + this.setCommentFormat("#", "/*", "*/"); + break; + + case "COBOL": + this.delimiter = this.escapeRegExp("*>"); + break; + + case "fortran-modern": + this.delimiter = "c"; + break; + + case "SAS": + case "stata": + this.setCommentFormat("*", "/*", "*/"); + break; + + case "html": + case "markdown": + case "xml": + this.setCommentFormat(""); + break; + + case "twig": + this.setCommentFormat("{#", "{#", "#}"); + break; + + case "genstat": + this.setCommentFormat("\\", '"', '"'); + break; + + case "cfml": + this.setCommentFormat(""); + break; + + + case "alloy": // Alloy Model checker language + this.delimiter = "(?:\/\/|--)" // single line comments can be either standard C `//` or haskell like `--` (bypasses regex scrubber) + this.blockCommentStart = this.escapeRegExp("/*"); // multiline comments can only be C style '/* ... */` + this.blockCommentEnd = this.escapeRegExp("*/"); + this.highlightMultilineComments = this.contributions.multilineComments; + + //? Commented out until language id overlap is resolved between several different extensions offering support very different assembly syntaxes for different architectures. + //? relevant issues have been submitted on the offending extensions repos (2021-02-18). + // case "asm": // nasm/yasm x86/x86_64/amd64 assembly (Intel Syntax) + // this.delimiter = ";"; + // // Has no official multiline comments but has two common practices for this using assembler directives. + // //? Highlighting this is supported by 1 of the two extensions for the language. + // // Which involve using a standard `%if` with some constant for 0 as the expr or `%ifdef` with a Defined `COMMENT` "variable" of some flavor. + // // for sections that are used for documentation (and not just "commenting-out-code"). + // this.blockCommentStart = "%if(?: (?:0x)?0+|def _*\d*_*[Cc][Oo][Mm][Mm][Ee][Nn][Tt]_*\d*_*)"; // (bypasses regex scrubber) + // this.blockCommentEnd = this.escapeRegExp("%endif"); + // this.highlightMultilineComments = this.contributions.multilineComments; + // break; + + case "plaintext": + this.isPlainText = true; + // If highlight plaintext is enabled, this is a supported language + this.supportedLanguage = this.contributions.highlightPlainText; + break; + + default: + this.supportedLanguage = false; + break; - case "clojure": - case "racket": - case "lisp": - this.delimiter = ";"; - break; - - case "terraform": - this.setCommentFormat("#", "/*", "*/"); - break; - - case "COBOL": - this.delimiter = this.escapeRegExp("*>"); - break; - - case "fortran-modern": - this.delimiter = "c"; - break; - - case "SAS": - case "stata": - this.setCommentFormat("*", "/*", "*/"); - break; - - case "html": - case "markdown": - case "xml": - this.setCommentFormat(""); - break; - - case "twig": - this.setCommentFormat("{#", "{#", "#}"); - break; - - case "genstat": - this.setCommentFormat("\\", '"', '"'); - break; - - case "cfml": - this.setCommentFormat(""); - break; - - case "plaintext": - this.isPlainText = true; - - // If highlight plaintext is enabeld, this is a supported language - this.supportedLanguage = this.contributions.highlightPlainText; - break; - - default: - this.supportedLanguage = false; - break; } } @@ -420,7 +464,7 @@ export class Parser { for (let item of items) { let options: vscode.DecorationRenderOptions = { color: item.color, backgroundColor: item.backgroundColor }; - // ? the textDecoration is initialised to empty so we can concat a preceeding space on it + // ? the textDecoration is initialized to empty so we can concat a proceeding space on it options.textDecoration = ""; if (item.strikethrough) {