├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── default-mappings.json ├── package-lock.json ├── package.json ├── src └── extension.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | -------------------------------------------------------------------------------- /.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": "Run 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 | } 23 | -------------------------------------------------------------------------------- /.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 | } 10 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "watch", 7 | "problemMatcher": [ 8 | "$tsc-watch" 9 | ], 10 | "group": "build", 11 | "label": "npm: watch", 12 | "detail": "tsc -watch -p ./", 13 | "isBackground": true 14 | }, 15 | { 16 | "type": "npm", 17 | "script": "compile", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": "build", 22 | "label": "npm: compile", 23 | "detail": "tsc -p ./", 24 | "isBackground": true 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | out/test/** 3 | out/**/*.map 4 | src/** 5 | .gitignore 6 | tsconfig.json 7 | tslint.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 0.5.0 4 | - Add banana brackets (⦇, ⦈) 5 | - Add adjunction symbol (⊣) 6 | 7 | ## 0.3.0 - 0.4.0 8 | - Fumbled vsce and accidentally published two new versions. 9 | 10 | ## 0.2.0 11 | - Add "glb" (⊓) and "lub" (⊔). 12 | - Add square subset operators (⊏, ⊐, ⊑, ⊒). 13 | - Add mathcal symbols for C, L, and P. 14 | - Add complement operator (∁). 15 | 16 | ## 0.1.0 17 | - Add "ell" (ℓ) 18 | - Update repository URL to vscode-latex-input 19 | 20 | ## 0.0.1 21 | - Initial release 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Anthony Vandikas 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # latex-input 2 | 3 | This extension allows you to enter Unicode symbols using LaTeX-like commands. Available commands are added to the list of auto-completions when you type `\`. 4 | 5 | ## Configuration 6 | 7 | * `latex-input.enabled`: Enables or disables the extension. This can be set on a per-language basis. For example: 8 | 9 | ```js 10 | "[latex]": { 11 | "latex-input.enabled": false 12 | } 13 | ``` 14 | 15 | * `latex-input.triggers`: The set of characters to watch for to activate the extension. By default this is `'\\'`. 16 | 17 | * `latex-input.mappings`: Defines the available input mappings, i.e., which strings get translated into which unicode characters. This can be one of three things: 18 | 19 | 1. A JSON object with specific mappings: 20 | 21 | ```js 22 | "latex-input.mappings": { 23 | "pm": "±", 24 | "mp": "∓", 25 | "times": "×", 26 | "x": "×", 27 | "cdot": "⋅", 28 | ... 29 | } 30 | ``` 31 | 32 | 2. A filename pointing to a JSON file with the desired configuration: 33 | 34 | ```js 35 | "latex-input.mappings": "${workspaceFolder}my-mappings.json" 36 | ``` 37 | 38 | ```js 39 | // ${workspaceFolder}my-mappings.json 40 | { 41 | "pm": "±", 42 | "mp": "∓", 43 | "times": "×", 44 | "x": "×", 45 | "cdot": "⋅", 46 | ... 47 | } 48 | ``` 49 | 50 | Relative filenames are always resolved with respect to the extension's own directory, which contains a `"default-mappings.json"`. 51 | 52 | 3. An array of filenames and JSON objects: 53 | 54 | ```js 55 | "latex-input.mappings": [ 56 | {...}, 57 | "${workspaceFolder}my-mappings.json" 58 | ] 59 | ``` 60 | -------------------------------------------------------------------------------- /default-mappings.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": "₀", 3 | "1": "₁", 4 | "2": "₂", 5 | "3": "₃", 6 | "4": "₄", 7 | "5": "₅", 8 | "6": "₆", 9 | "7": "₇", 10 | "8": "₈", 11 | "9": "₉", 12 | "_0": "₀", 13 | "_1": "₁", 14 | "_2": "₂", 15 | "_3": "₃", 16 | "_4": "₄", 17 | "_5": "₅", 18 | "_6": "₆", 19 | "_7": "₇", 20 | "_8": "₈", 21 | "_9": "₉", 22 | "^0": "⁰", 23 | "^1": "¹", 24 | "^2": "²", 25 | "^3": "³", 26 | "^4": "⁴", 27 | "^5": "⁵", 28 | "^6": "⁶", 29 | "^7": "⁷", 30 | "^8": "⁸", 31 | "^9": "⁹", 32 | 33 | "_a": "ₐ", 34 | "_e": "ₑ", 35 | "_h": "ₕ", 36 | "_i": "ᵢ", 37 | "_j": "ⱼ", 38 | "_k": "ₖ", 39 | "_l": "ₗ", 40 | "_m": "ₘ", 41 | "_n": "ₙ", 42 | "_o": "ₒ", 43 | "_p": "ₚ", 44 | "_r": "ᵣ", 45 | "_s": "ₛ", 46 | "_t": "ₜ", 47 | "_u": "ᵤ", 48 | "_v": "ᵥ", 49 | "_x": "ₓ", 50 | 51 | "^a": "ᵃ", 52 | "^b": "ᵇ", 53 | "^c": "ᶜ", 54 | "^d": "ᵈ", 55 | "^e": "ᵉ", 56 | "^f": "ᶠ", 57 | "^g": "ᵍ", 58 | "^h": "ʰ", 59 | "^i": "ⁱ", 60 | "^j": "ʲ", 61 | "^k": "ᵏ", 62 | "^l": "ˡ", 63 | "^m": "ᵐ", 64 | "^n": "ⁿ", 65 | "^o": "ᵒ", 66 | "^p": "ᵖ", 67 | "^r": "ʳ", 68 | "^s": "ˢ", 69 | "^t": "ᵗ", 70 | "^u": "ᵘ", 71 | "^v": "ᵛ", 72 | "^w": "ʷ", 73 | "^x": "ˣ", 74 | "^y": "ʸ", 75 | "^z": "ᶻ", 76 | 77 | "^A": "ᴬ", 78 | "^B": "ᴮ", 79 | "^D": "ᴰ", 80 | "^E": "ᴱ", 81 | "^G": "ᴳ", 82 | "^H": "ᴴ", 83 | "^I": "ᴵ", 84 | "^J": "ᴶ", 85 | "^K": "ᴷ", 86 | "^L": "ᴸ", 87 | "^M": "ᴹ", 88 | "^N": "ᴺ", 89 | "^O": "ᴼ", 90 | "^P": "ᴾ", 91 | "^R": "ᴿ", 92 | "^T": "ᵀ", 93 | "^U": "ᵁ", 94 | "^V": "ⱽ", 95 | "^W": "ᵂ", 96 | 97 | "^alpha": "ᵅ", 98 | "^beta": "ᵝ", 99 | "^gamma": "ˠ", 100 | "^delta": "ᵟ", 101 | "^theta": "ᶿ", 102 | "^iota": "ᶥ", 103 | "^phi": "ᶲ", 104 | "^chi": "ᵡ", 105 | 106 | "_beta": "ᵦ", 107 | "_gamma": "ᵧ", 108 | "_rho": "ᵨ", 109 | "_phi": "ᵩ", 110 | "_chi": "ᵪ", 111 | 112 | "copyright": "©", 113 | "(C)": "©", 114 | "registered": "®", 115 | "(R)": "®", 116 | "trademark": "™", 117 | "^TM": "™", 118 | 119 | "ell": "ℓ", 120 | 121 | "_+": "₊", 122 | "_-": "₋", 123 | "^+": "⁺", 124 | "^-": "⁻", 125 | "^(": "⁽", 126 | "^)": "⁾", 127 | "_(": "₍", 128 | "_)": "₎", 129 | 130 | "<<": "⟪", 131 | ">>": "⟫", 132 | "[[": "⟦", 133 | "]]": "⟧", 134 | "{{": "⦃", 135 | "}}": "⦄", 136 | "(|": "⦇", 137 | "|)": "⦈", 138 | 139 | "pm": "±", 140 | "mp": "∓", 141 | "times": "×", 142 | "x": "×", 143 | "cdot": "⋅", 144 | "div": "÷", 145 | "sqrt": "√", 146 | "sum": "∑", 147 | "int": "∫", 148 | "oint": "∮", 149 | "ldots": "…", 150 | "cdots": "⋯", 151 | "vdots": "⋮", 152 | "ddots": "⋱", 153 | "adots": "⋰", 154 | "therefore": "∴", 155 | "neg": "¬", 156 | "^~": "˜", 157 | "propto": "∝", 158 | "infty": "∞", 159 | "blacksquare": "▪", 160 | "Box": "□", 161 | "blacktriangle": "▴", 162 | "blacktriangleup": "▴", 163 | "blacktriangleright": "▸", 164 | "blacktriangleleft": "◂", 165 | "blacktriangledown": "▾", 166 | "triangle": "▵", 167 | "triangleup": "▵", 168 | "triangleright": "▹", 169 | "triangleleft": "◃", 170 | "triangledown": "▿", 171 | "bigtriangle": "△", 172 | "bigtriangleup": "△", 173 | "bigtriangledown": "▽", 174 | 175 | "ne": "≠", 176 | "approx": "≈", 177 | "~~": "≈", 178 | "~": "∼", 179 | "=:": "≕", 180 | ":=": "≔", 181 | "equiv": "≡", 182 | "==": "≡", 183 | "triangleq": "≜", 184 | "triangle=": "≜", 185 | "def=": "≝", 186 | "doteq": "≐", 187 | "dot=": "≐", 188 | "cong": "≅", 189 | "Leftrightarrow": "⇔", 190 | "<=>": "⇔", 191 | "leftrightarrow": "↔", 192 | "<->": "↔", 193 | 194 | "ll": "≪", 195 | "gg": "≫", 196 | "le": "≤", 197 | "<=": "≤", 198 | "ge": "≥", 199 | ">=": "≥", 200 | "leqq": "≦", 201 | "geqq": "≧", 202 | "prec": "≺", 203 | "succ": "≻", 204 | "Rightarrow": "⇒", 205 | "=>": "⇒", 206 | "rightarrow": "→", 207 | "->": "→", 208 | "subset": "⊂", 209 | "subseteq": "⊆", 210 | "supset": "⊃", 211 | "supseteq": "⊇", 212 | "Subset": "⋐", 213 | "sqsubset": "⊏", 214 | "sqsupset": "⊐", 215 | "sqsubseteq": "⊑", 216 | "sqsupseteq": "⊒", 217 | "to": "→", 218 | "mapsto": "↦", 219 | "|->": "↦", 220 | "leftarrow": "←", 221 | "<-": "←", 222 | "vDash": "⊨", 223 | "|=": "⊨", 224 | "vdash": "⊢", 225 | "|-": "⊢", 226 | "dashv": "⊣", 227 | "-|": "⊣", 228 | "langle": "⟨", 229 | "<": "⟨", 230 | "rangle": "⟩", 231 | ">": "⟩", 232 | 233 | "||": "∥", 234 | "lfloor": "⌊", 235 | "rfloor": "⌋", 236 | "lceil": "⌈", 237 | "rceil": "⌉", 238 | 239 | "setminus": "∖", 240 | "mid": "|", 241 | "sharp": "♯", 242 | "#": "♯", 243 | "flat": "♭", 244 | ":": "∶", 245 | "::": "∷", 246 | "::-": "∺", 247 | "wr": "≀", 248 | "lightning": "↯", 249 | "smashtimes": "⨳", 250 | "Leftarrow": "⇐", 251 | "bot": "⊥", 252 | "nleftrightarrow": "↮", 253 | "n<->": "↮", 254 | "oplus": "⊕", 255 | "o+": "⊕", 256 | "veebar": "⊻", 257 | 258 | "dot": "∙", 259 | ".": "∙", 260 | 261 | "forall": "∀", 262 | "mathbb{B}": "𝔹", 263 | "B": "𝔹", 264 | "mathbb{C}": "ℂ", 265 | "mathcal{C}": "𝓒", 266 | "C": "ℂ", 267 | "partial": "∂", 268 | "mathbb{E}": "𝔼", 269 | "E": "𝔼", 270 | "exists": "∃", 271 | "nexists": "∄", 272 | "in": "∈", 273 | "notin": "∉", 274 | "ni": "∋", 275 | "notni": "∌", 276 | "mathbb{H}": "ℍ", 277 | "H": "ℍ", 278 | "mathcal{L}": "𝓛", 279 | "mathbb{N}": "ℕ", 280 | "N": "ℕ", 281 | "circ": "∘", 282 | "o": "∘", 283 | "empty": "∅", 284 | "mathbb{P}": "ℙ", 285 | "mathcal{P}": "𝓟", 286 | "P": "ℙ", 287 | "mathbb{Q}": "ℚ", 288 | "Q": "ℚ", 289 | "mathbb{R}": "ℝ", 290 | "R": "ℝ", 291 | "dagger": "†", 292 | "top": "⊤", 293 | "mathbb{U}": "𝕌", 294 | "U": "𝕌", 295 | "cup": "∪", 296 | "union": "∪", 297 | "cap": "∩", 298 | "intersection": "∩", 299 | "sqcup": "⊔", 300 | "lub": "⊔", 301 | "sqcap": "⊓", 302 | "glb": "⊓", 303 | "compl": "∁", 304 | "vee": "∨", 305 | "or": "∨", 306 | "wedge": "∧", 307 | "and": "∧", 308 | "otimes": "⊗", 309 | "ox": "⊗", 310 | "ltimes": "⋉", 311 | "rtimes": "⋊", 312 | "bowtie": "⋈", 313 | "mathbb{Z}": "ℤ", 314 | "Z": "ℤ", 315 | 316 | "aleph": "ℵ", 317 | "beth": "ℶ", 318 | "ominus": "⊖", 319 | "o-": "⊝", 320 | "del": "∇", 321 | "nabla": "∇", 322 | "prod": "∏", 323 | "coprod": "∐", 324 | 325 | "alpha": "α", 326 | "Alpha": "Α", 327 | "beta": "β", 328 | "Beta": "Β", 329 | "gamma": "γ", 330 | "Gamma": "Γ", 331 | "delta": "δ", 332 | "Delta": "Δ", 333 | "epsilon": "ε", 334 | "Epsilon": "Ε", 335 | "zeta": "ζ", 336 | "Zeta": "Ζ", 337 | "eta": "η", 338 | "Eta": "Η", 339 | "theta": "θ", 340 | "Theta": "Θ", 341 | "iota": "ι", 342 | "Iota": "Ι", 343 | "kappa": "κ", 344 | "Kappa": "Κ", 345 | "lambda": "λ", 346 | "Lambda": "Λ", 347 | "mu": "μ", 348 | "Mu": "Μ", 349 | "nu": "ν", 350 | "Nu": "Ν", 351 | "xi": "ξ", 352 | "Xi": "Ξ", 353 | "omicron": "ο", 354 | "Omicron": "Ο", 355 | "pi": "π", 356 | "Pi": "Π", 357 | "rho": "ρ", 358 | "Rho": "Ρ", 359 | "sigma": "σ", 360 | "Sigma": "Σ", 361 | "tau": "τ", 362 | "Tau": "Τ", 363 | "upsilon": "υ", 364 | "Upsilon": "Υ", 365 | "phi": "φ", 366 | "Phi": "Φ", 367 | "chi": "χ", 368 | "Chi": "Χ", 369 | "psi": "ψ", 370 | "Psi": "Ψ", 371 | "omega": "ω", 372 | "Omega": "Ω", 373 | 374 | "downarrow": "↓", 375 | "uparrow": "↑", 376 | "updownarrow": "↕" 377 | } 378 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "latex-input", 3 | "version": "2.3.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "14.14.21", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", 10 | "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==", 11 | "dev": true 12 | }, 13 | "@types/vscode": { 14 | "version": "1.52.0", 15 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.52.0.tgz", 16 | "integrity": "sha512-Kt3bvWzAvvF/WH9YEcrCICDp0Z7aHhJGhLJ1BxeyNP6yRjonWqWnAIh35/pXAjswAnWOABrYlF7SwXR9+1nnLA==", 17 | "dev": true 18 | }, 19 | "typescript": { 20 | "version": "4.1.3", 21 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", 22 | "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", 23 | "dev": true 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "latex-input", 3 | "displayName": "latex-input", 4 | "description": "LaTeX-style unicode input", 5 | "version": "2.3.0", 6 | "publisher": "yellpika", 7 | "license": "MIT", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/YellPika/vscode-latex-input" 11 | }, 12 | "engines": { 13 | "vscode": "^1.52.0" 14 | }, 15 | "categories": [ 16 | "Other" 17 | ], 18 | "activationEvents": [ 19 | "onLanguage" 20 | ], 21 | "main": "./out/extension", 22 | "contributes": { 23 | "commands": [ 24 | { 25 | "command": "latex-input.reload-mappings", 26 | "title": "Latex Input: Reload Mappings" 27 | } 28 | ], 29 | "configuration": { 30 | "title": "LaTeX input", 31 | "properties": { 32 | "latex-input.enabled": { 33 | "description": "Enables or disables the extension.", 34 | "type": "boolean", 35 | "default": true, 36 | "scope": "language-overridable" 37 | }, 38 | "latex-input.triggers": { 39 | "description": "A string containing the characters the extension should activate on.", 40 | "type": "string", 41 | "default": "\\" 42 | }, 43 | "latex-input.mappings": { 44 | "description": "A filename pointing to a JSON file containing mappings, an object defining mappings, or a list of either.", 45 | "default": [ 46 | "default-mappings.json" 47 | ], 48 | "anyOf": [ 49 | { 50 | "type": "string" 51 | }, 52 | { 53 | "type": "object", 54 | "additionalProperties": { 55 | "type": "string" 56 | } 57 | }, 58 | { 59 | "type": "array", 60 | "items": { 61 | "anyOf": [ 62 | { 63 | "type": "string" 64 | }, 65 | { 66 | "type": "object", 67 | "additionalProperties": { 68 | "type": "string" 69 | } 70 | } 71 | ] 72 | } 73 | } 74 | ], 75 | "scope": "language-overridable" 76 | } 77 | } 78 | } 79 | }, 80 | "scripts": { 81 | "vscode:prepublish": "npm run compile", 82 | "compile": "tsc -p ./", 83 | "watch": "tsc -watch -p ./", 84 | "postinstall": "node ./node_modules/vscode/bin/install" 85 | }, 86 | "devDependencies": { 87 | "@types/node": "^14.14.21", 88 | "@types/vscode": "^1.52.0", 89 | "typescript": "^4.1.3" 90 | }, 91 | "__metadata": { 92 | "id": "6af075bf-dfe9-43c0-956a-608e5591e7ee", 93 | "publisherDisplayName": "YellPika", 94 | "publisherId": "3f5fcd0e-50a7-4812-bb34-ff9d0bb88b57" 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { isAbsolute } from 'path'; 4 | import { 5 | ExtensionContext, 6 | languages, 7 | workspace, 8 | Range, 9 | CompletionItemProvider, 10 | CompletionItem, 11 | CompletionItemKind, 12 | Uri 13 | } from 'vscode'; 14 | 15 | export function activate(context: ExtensionContext) { 16 | let completionProvider: CompletionItemProvider = { 17 | async provideCompletionItems(document, position, token, { triggerCharacter }) { 18 | let config = workspace.getConfiguration('latex-input', document); 19 | if (!config.enabled || config.triggers.indexOf(triggerCharacter) === -1) { 20 | return []; 21 | } 22 | 23 | let range = new Range(position.translate(0, -1), position); 24 | let completions: Array = []; 25 | 26 | type Mappings = { [key: string]: string }; 27 | async function load(obj: string | Mappings | (string | Mappings)[]) { 28 | if (typeof obj === "string") { 29 | if (isAbsolute(obj)) { 30 | try { 31 | let buffer = await workspace.fs.readFile(Uri.file(obj)); 32 | await load(JSON.parse(buffer.toString())); 33 | } catch { } 34 | return; 35 | } 36 | 37 | if (workspace.workspaceFolders && obj.includes('${workspaceFolder}')) { 38 | for (let i = 0; i < workspace.workspaceFolders.length; i++) { 39 | try { 40 | let uri = Uri.file(obj.replace( 41 | '${workspaceFolder}', 42 | workspace.workspaceFolders[i].uri.fsPath + '/')); 43 | let buffer = await workspace.fs.readFile(uri); 44 | await load(JSON.parse(buffer.toString())); 45 | } catch { } 46 | } 47 | return; 48 | } 49 | 50 | try { 51 | let uri = Uri.file(context.asAbsolutePath(obj)); 52 | let buffer = await workspace.fs.readFile(uri); 53 | await load(JSON.parse(buffer.toString())); 54 | } catch { } 55 | } else if (obj instanceof Array) { 56 | for (const entry of obj) 57 | await load(entry); 58 | } else { 59 | for (const from in obj) { 60 | let to = obj[from]; 61 | let item = new CompletionItem(triggerCharacter + from); 62 | item.detail = to; 63 | item.kind = CompletionItemKind.Text; 64 | item.insertText = to; 65 | item.range = range; 66 | completions.push(item); 67 | } 68 | } 69 | } 70 | 71 | await load(config.mappings); 72 | 73 | return completions; 74 | } 75 | }; 76 | 77 | function registerCompletionProvider() { 78 | let config = workspace.getConfiguration('latex-input'); 79 | return languages.registerCompletionItemProvider( 80 | { pattern: "**" }, 81 | completionProvider, 82 | ...config.triggers); 83 | } 84 | 85 | let registration = registerCompletionProvider(); 86 | 87 | context.subscriptions.push( 88 | workspace.onDidChangeConfiguration((e) => { 89 | if (e.affectsConfiguration("latex-input.selector") || 90 | e.affectsConfiguration("latex-input.triggers")) { 91 | registration.dispose(); 92 | registration = registerCompletionProvider(); 93 | } 94 | })); 95 | } 96 | -------------------------------------------------------------------------------- /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 | ] 22 | } 23 | --------------------------------------------------------------------------------