From 713a9cde6a4569f6caf112155394195853b49e00 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sun, 19 Nov 2023 23:37:24 +0100 Subject: [PATCH] works tm --- TODO.md | 6 ++++ src/comments.json | 91 +++++++++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 24 +++++-------- tsconfig.json | 1 + 4 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 TODO.md create mode 100644 src/comments.json diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..8025726 --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +[x] - in extensions.json add suffix for languages that require it such as css where comments are: /* stuff */ +[] - test cancel token +[] - add fill in middle +[] - add config option to disable the extension +[] - add command to test and query connection to server +[] - add feedback when waiting response \ No newline at end of file diff --git a/src/comments.json b/src/comments.json new file mode 100644 index 0000000..2344a09 --- /dev/null +++ b/src/comments.json @@ -0,0 +1,91 @@ +{ + "ada": ["--", ""], + "agda": ["--", ""], + "alloy": ["//", ""], + "antlr": ["#", ""], + "applescript": ["--", ""], + "assembly": [";", ""], + "augeas": ["##", ""], + "awk": ["#", ""], + "batchfile": ["::", ""], + "bluespec": ["//", ""], + "c-sharp": ["///", ""], + "c": ["//", ""], + "clojure": [";;", ""], + "cmake": ["#", ""], + "coffeescript": ["#", ""], + "common-lisp": [";;;", ""], + "cpp": ["//", ""], + "css": ["/*", "*/"], + "cuda": ["//", ""], + "dart": ["//", ""], + "dockerfile": ["#", ""], + "elixir": ["#", ""], + "elm": ["--", ""], + "emacs-lisp": [";;;", ""], + "erlang": ["%", ""], + "f-sharp": ["//", ""], + "fortran": ["!", ""], + "glsl": ["//", ""], + "go": ["//", ""], + "groovy": ["//", ""], + "haskell": ["--", ""], + "html": [""], + "idris": ["|||", ""], + "isabelle": ["--", ""], + "java-server-pages": ["<%--", "--%>"], + "java": ["//", ""], + "javascript": ["//", ""], + "json": ["\"comment\":\"", "\","], + "julia": ["#", ""], + "jupyter-notebook": ["#", ""], + "kotlin": ["//", ""], + "lean": ["/--", "-/"], + "literate-agda": ["--", ""], + "literate-coffeescript": ["#", ""], + "literate-haskell": ["--", ""], + "lua": ["--", ""], + "makefile": ["#", ""], + "maple": ["#", ""], + "markdown": [""], + "mathematica": ["(*", "*)"], + "matlab": ["%", ""], + "ocaml": ["(*", "*)"], + "pascal": ["(*", "*)"], + "perl": ["#", ""], + "php": ["//", ""], + "powershell": ["#", ""], + "prolog": ["/*", "*/"], + "protocol-buffer": ["//", ""], + "python": ["#", ""], + "r": ["#", ""], + "racket": [";", ""], + "restructuredtext": [".. ", ""], + "rmarkdown": [""], + "ruby": ["#", ""], + "rust": ["//", ""], + "sas": ["/*", "*/"], + "scala": ["//", ""], + "scheme": [";", ""], + "shell": ["#", ""], + "smalltalk": ["\"", "\""], + "solidity": ["//", ""], + "sparql": ["#", ""], + "sql": ["--", ""], + "stan": ["//", ""], + "standard-ml": ["(*", "*)"], + "stata": ["//", ""], + "systemverilog": ["//", ""], + "tcl": ["#", ""], + "tcsh": [": ", ""], + "tex": ["%", ""], + "thrift": ["//", ""], + "typescript": ["//", ""], + "verilog": ["//", ""], + "vhdl": ["--", ""], + "visual-basic": ["'", ""], + "xslt": ["", ""], + "yacc": ["//", ""], + "yaml": ["#", ""], + "zig": ["//", ""] +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 6e0a58f..65f9739 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,6 @@ import { ok } from 'assert'; import * as vscode from 'vscode'; +import commentPrefix from './comments.json'; // llama.cpp server response format @@ -92,22 +93,13 @@ export function activate(cotext: vscode.ExtensionContext) { //doc_after = doc_before.replace(/\s+/gm, " "); // prefix commented filename, is this the best way? - var comment_prefix: string = ''; - switch (document.languageId) { - case 'c': - case 'js': - case 'ts': - comment_prefix = '//'; - break; - case 'sh': - case 'bash': - case 'zsh': - case 'py': - case 'python': - comment_prefix = '#'; - break; - } - doc_before = comment_prefix + ' ' + document.fileName + '\n' + doc_before; + var pfx: string = ''; + var sfx: string = ''; + const lang = document.languageId; + const prefixes = commentPrefix; + pfx = (prefixes as any)[lang][0] as string; + sfx = (prefixes as any)[lang][1] as string; + doc_before = pfx + ' ' + document.fileName + sfx + '\n' + doc_before; // server request object const request = { diff --git a/tsconfig.json b/tsconfig.json index 6954702..22c5f85 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "module": "Node16", "target": "ES2022", "outDir": "out", + "resolveJsonModule": true, "lib": [ "ES2022" ],