diff --git a/README.md b/README.md index 946e35c..fddb725 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ This sets up all built-in features: completion, hover, diagnostics, go-to-defini | `workspaceFolders` | `WorkspaceFolder[]` | LSP workspace folders | | `documentUri` | `string` | URI of the document being edited | | `languageId` | `string` | Language identifier ([spec](https://microsoft.github.io/language-server-protocol/specification#textDocumentItem)) | +| `prefix`, `suffix` | `string` | Text surrounding the editor content in the document sent to the server | | `initializationOptions` | `object` | Server-specific initialization options | | `locale` | `string` | Locale for the LSP session (e.g. `'en'`) | | `allowHTMLContent` | `boolean` | Trust raw HTML in hover/completion content (default: `false`) | diff --git a/package-lock.json b/package-lock.json index caa4f63..a0abc25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@rollup/plugin-commonjs": "^29.0.3", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-typescript": "^12.3.0", + "del-cli": "^8.0.0", "prettier": "^3.9.6", "rollup": "^4.63.1", "tslib": "^2.8.1", @@ -195,9 +196,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -207,6 +205,44 @@ "node": "^22.20 || ^24.12 || >=25" } }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/@rollup/plugin-commonjs": { "version": "29.0.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-29.0.3.tgz", @@ -401,9 +437,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -418,9 +451,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -435,9 +465,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -452,9 +479,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -469,9 +493,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -486,9 +507,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -503,9 +521,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -520,9 +535,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -537,9 +549,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -554,9 +563,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -571,9 +577,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -588,9 +591,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -605,9 +605,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -698,6 +695,19 @@ "win32" ] }, + "node_modules/@sindresorhus/merge-streams": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz", + "integrity": "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -712,6 +722,19 @@ "dev": true, "license": "MIT" }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -735,6 +758,50 @@ "node": ">=0.10.0" } }, + "node_modules/del": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/del/-/del-9.0.1.tgz", + "integrity": "sha512-1B11d2d8AJcTcbvXtF5a9NWVoE7G12eJPcadRGdLik38WxgsAyDQO5ZdjHoeIlAIhAhbgnD/AZVBWf9xQze+0w==", + "dev": true, + "license": "MIT", + "dependencies": { + "globby": "^16.2.4", + "is-glob": "^4.0.3", + "is-path-cwd": "^4.0.1", + "is-path-inside": "^4.0.0", + "p-map": "^7.0.8", + "presentable-error": "^0.0.1", + "slash": "^5.1.0" + }, + "engines": { + "node": ">=22" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/del-cli": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/del-cli/-/del-cli-8.0.1.tgz", + "integrity": "sha512-Z4+xLjVJs9dMN4gDMRfY/7b7WItNOB5EOKu9BenbJD63olx9YM5SU/DEuDFWvN0B1BdGIzejCJFgPt2vIGwj1A==", + "dev": true, + "license": "MIT", + "dependencies": { + "del": "^9.0.1", + "meow": "^14.1.0", + "presentable-error": "^0.0.1" + }, + "bin": { + "del": "del.js", + "del-cli": "cli.js" + }, + "engines": { + "node": ">=22" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/es-errors": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", @@ -752,6 +819,33 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-glob": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fastq": { + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz", + "integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==", + "dev": true, + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -770,6 +864,19 @@ } } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -795,6 +902,41 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/globby": { + "version": "16.2.4", + "resolved": "https://registry.npmjs.org/globby/-/globby-16.2.4.tgz", + "integrity": "sha512-c8B/VNLmxRcmqqenRA9t+9IyOjf9+V6lTxPaUJLqOCONdQkWZ0ETYgX0qbtJqPsgCNusT9MZ5Jeidw8Eb9tn2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sindresorhus/merge-streams": "^4.0.0", + "fast-glob": "^3.3.3", + "ignore": "^7.0.5", + "is-path-inside": "^4.0.0", + "micromatch": "^4.0.8", + "slash": "^5.1.0", + "unicorn-magic": "^0.4.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/hasown": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", @@ -808,6 +950,16 @@ "node": ">= 0.4" } }, + "node_modules/ignore": { + "version": "7.0.16", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.16.tgz", + "integrity": "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, "node_modules/is-core-module": { "version": "2.16.2", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", @@ -824,6 +976,29 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", @@ -831,6 +1006,42 @@ "dev": true, "license": "MIT" }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-path-cwd": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-4.0.1.tgz", + "integrity": "sha512-w3upMc5m1LfTkA4VvUcMo764hWF1uuo2NPHtLkLrlhw/tiCLxD5gIhvl72oZIY8oFVpZ/xG2JnqbibZAfSQ3Ww==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-path-inside": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-4.0.0.tgz", + "integrity": "sha512-lJJV/5dYS+RcL8uQdBDW9c9uWFLLBNRyFhnAKXw5tVqLlKZ4RMGZKv+YQ/IA3OhD+RpbJa1LLFM1FQPGyIXvOA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-reference": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", @@ -863,6 +1074,69 @@ "node": ">= 20" } }, + "node_modules/meow": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/meow/-/meow-14.1.0.tgz", + "integrity": "sha512-EDYo6VlmtnumlcBCbh1gLJ//9jvM/ndXHfVXIFrZVr6fGcwTUyCTFNTLCKuY3ffbK8L/+3Mzqnd58RojiZqHVw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/p-map": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-7.1.1.tgz", + "integrity": "sha512-6Lh3jQPLthYujSrlw6ccWXBGZTkoTCz27Hd92g79LH/kjAbgoEu0t442cCCNbegPSJsA0lwDX8z0bcKtkpA32g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -883,6 +1157,19 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/presentable-error": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/presentable-error/-/presentable-error-0.0.1.tgz", + "integrity": "sha512-E6rsNU1QNJgB3sjj7OANinGncFKuK+164sLXw1/CqBjj/EkXSoSdHCtWQGBNlREIGLnL7IEUEGa08YFVUbrhVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/prettier": { "version": "3.9.10", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz", @@ -899,6 +1186,27 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/resolve": { "version": "1.22.12", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz", @@ -921,6 +1229,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "dev": true, + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, "node_modules/rollup": { "version": "4.66.0", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.66.0.tgz", @@ -967,6 +1286,43 @@ "fsevents": "~2.3.2" } }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/slash": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/style-mod": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz", @@ -986,6 +1342,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -1007,6 +1376,19 @@ "node": ">=14.17" } }, + "node_modules/unicorn-magic": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.4.1.tgz", + "integrity": "sha512-lzlXPoVB0Uy/FvTaUgX39RbixYiSKoc3JSoSf01+0c2B6FR3qdYIPN7Qjo/AV7n6sqLCk0509cT3LRj1oSZ1+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/vscode-jsonrpc": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-10.0.0.tgz", diff --git a/package.json b/package.json index 32b7ae0..dba4316 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "main": "dist/index.js", "type": "module", "scripts": { - "prepare": "rollup -c rollup.config.js", + "all": "npm run typecheck && npm run build", + "clean": "del-cli dist", + "build": "rollup -c rollup.config.js", + "prepare": "npm run build", "typecheck": "tsc --noEmit -p tsconfig.check.json", "format:check": "prettier --check src", "build:gh-pages": "rollup -c rollup.config.gh-pages.js" @@ -32,6 +35,7 @@ "@rollup/plugin-commonjs": "^29.0.3", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-typescript": "^12.3.0", + "del-cli": "^8.0.0", "prettier": "^3.9.6", "rollup": "^4.63.1", "tslib": "^2.8.1", diff --git a/src/changes.ts b/src/changes.ts index abe2d79..62a9808 100644 --- a/src/changes.ts +++ b/src/changes.ts @@ -1,9 +1,9 @@ -import type { Text, ChangeSet } from '@codemirror/state'; +import type { EditorState, ChangeSet } from '@codemirror/state'; import type * as LSP from 'vscode-languageserver-protocol'; import { offsetToPos, posToOffset } from './pos.js'; export function changeSetToEvents( - doc: Text, + state: EditorState, changes: ChangeSet, ): LSP.TextDocumentContentChangeEvent[] { const events: LSP.TextDocumentContentChangeEvent[] = []; @@ -11,8 +11,8 @@ export function changeSetToEvents( changes.iterChanges((fromA, toA, fromB, toB, inserted) => { events.push({ range: { - start: offsetToPos(doc, fromA), - end: offsetToPos(doc, toA), + start: offsetToPos(state, fromA), + end: offsetToPos(state, toA), }, text: inserted.toString(), }); @@ -22,7 +22,8 @@ export function changeSetToEvents( if (!('range' in a)) return 1; if (!('range' in b)) return -1; return ( - posToOffset(doc, b.range.start) - posToOffset(doc, a.range.start) + posToOffset(state, b.range.start) - + posToOffset(state, a.range.start) ); }); diff --git a/src/completion.ts b/src/completion.ts index f37edbd..891a235 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -35,7 +35,7 @@ export const autocompletion = (): Extension => } return await plugin.requestCompletion( context, - offsetToPos(state.doc, pos), + offsetToPos(state, pos), { triggerCharacter: trigChar, triggerKind: trigKind, diff --git a/src/definition.ts b/src/definition.ts index 667b4b0..ebe9b1b 100644 --- a/src/definition.ts +++ b/src/definition.ts @@ -5,21 +5,21 @@ import { offsetToPos } from './pos.js'; function requestDefinition(view: EditorView, pos: number): boolean { const plugin = view.plugin(languageServerPlugin); if (!plugin) return false; - plugin.requestDefinition(view, offsetToPos(view.state.doc, pos)); + plugin.requestDefinition(view, offsetToPos(view.state, pos)); return true; } function requestDeclaration(view: EditorView, pos: number): boolean { const plugin = view.plugin(languageServerPlugin); if (!plugin) return false; - plugin.requestDeclaration(view, offsetToPos(view.state.doc, pos)); + plugin.requestDeclaration(view, offsetToPos(view.state, pos)); return true; } function requestTypeDefinition(view: EditorView, pos: number): boolean { const plugin = view.plugin(languageServerPlugin); if (!plugin) return false; - plugin.requestTypeDefinition(view, offsetToPos(view.state.doc, pos)); + plugin.requestTypeDefinition(view, offsetToPos(view.state, pos)); return true; } diff --git a/src/formatting.ts b/src/formatting.ts index d8a9e8f..77002bf 100644 --- a/src/formatting.ts +++ b/src/formatting.ts @@ -3,7 +3,7 @@ import type { EditorView } from '@codemirror/view'; import type * as LSP from 'vscode-languageserver-protocol'; import { languageServerPlugin } from './plugin.js'; -import { offsetToPos, posToOffset } from './pos.js'; +import { isEditableRange, offsetToPos, posToOffset } from './pos.js'; /** * Facet for configuring LSP formatting options (tab size, spaces vs tabs, etc.). @@ -29,9 +29,13 @@ function getFormattingOptions(view: EditorView): LSP.FormattingOptions { } function applyTextEdits(view: EditorView, edits: LSP.TextEdit[]) { + if (edits.some((edit) => !isEditableRange(view.state, edit.range))) { + console.error('Cannot apply formatting outside the editable document'); + return; + } const changes = edits.map((edit) => ({ - from: posToOffset(view.state.doc, edit.range.start), - to: posToOffset(view.state.doc, edit.range.end), + from: posToOffset(view.state, edit.range.start), + to: posToOffset(view.state, edit.range.end), insert: edit.newText, })); view.dispatch(view.state.update({ changes })); @@ -81,8 +85,8 @@ export function formatSelection(view: EditorView): boolean { .textDocumentRangeFormatting({ textDocument: { uri: plugin.documentUri }, range: { - start: offsetToPos(view.state.doc, from), - end: offsetToPos(view.state.doc, to), + start: offsetToPos(view.state, from), + end: offsetToPos(view.state, to), }, options: getFormattingOptions(view), }) diff --git a/src/highlight.ts b/src/highlight.ts index 6ac130e..056becb 100644 --- a/src/highlight.ts +++ b/src/highlight.ts @@ -93,7 +93,7 @@ const highlightPlugin = ViewPlugin.fromClass( const result = await plugin.client.textDocumentDocumentHighlight({ textDocument: { uri: plugin.documentUri }, - position: offsetToPos(state.doc, pos), + position: offsetToPos(state, pos), }); if (view.state.selection.main.head !== pos) { @@ -109,12 +109,9 @@ const highlightPlugin = ViewPlugin.fromClass( const decorations = result .map((highlight) => { - const from = posToOffset( - view.state.doc, - highlight.range.start, - ); - const to = posToOffset(view.state.doc, highlight.range.end); - if (from == null || to == null) return null; + const from = posToOffset(view.state, highlight.range.start); + const to = posToOffset(view.state, highlight.range.end); + if (from == null || to == null || from >= to) return null; return decorationForKind(highlight.kind).range(from, to); }) .filter((d) => d != null) diff --git a/src/hover.ts b/src/hover.ts index 850ae1d..d8c719b 100644 --- a/src/hover.ts +++ b/src/hover.ts @@ -8,9 +8,7 @@ export const hoverTooltip = (): Extension => cmHoverTooltip((view, pos): Promise => { const plugin = view.plugin(languageServerPlugin); return ( - plugin?.requestHoverTooltip( - view, - offsetToPos(view.state.doc, pos), - ) ?? null + plugin?.requestHoverTooltip(view, offsetToPos(view.state, pos)) ?? + null ); }); diff --git a/src/index.ts b/src/index.ts index 7fcf97e..a785a41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,7 @@ import { autocompletion } from './completion.js'; import { documentHighlight } from './highlight.js'; import { mouseHandler } from './mouse.js'; import { renameExtension } from './rename.js'; +import { documentPrefix, documentSuffix } from './pos.js'; interface LanguageServerOptions< InitializationOptions = unknown, @@ -85,6 +86,8 @@ export function languageServerWithTransport( options: LanguageServerOptions, ) { return [ + documentPrefix.of(options.prefix ?? ''), + documentSuffix.of(options.suffix ?? ''), languageServerPlugin.of({ client: options.client || diff --git a/src/plugin.ts b/src/plugin.ts index 84c4713..32a00b5 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -21,7 +21,12 @@ import { marked } from 'marked'; import type { PublishDiagnosticsParams } from 'vscode-languageserver-protocol'; import type * as LSP from 'vscode-languageserver-protocol'; -import { posToOffset, offsetToPos } from './pos.js'; +import { + posToOffset, + offsetToPos, + fullDocument, + isEditableRange, +} from './pos.js'; import { changeSetToEvents } from './changes.js'; const timeout = 10000; @@ -85,6 +90,7 @@ interface LSPNotifyMap { initialized: LSP.InitializedParams; 'textDocument/didChange': LSP.DidChangeTextDocumentParams; 'textDocument/didOpen': LSP.DidOpenTextDocumentParams; + 'textDocument/didClose': LSP.DidCloseTextDocumentParams; } // Server to client @@ -278,6 +284,10 @@ export class LanguageServerClient { return this.notify('textDocument/didChange', params); } + public textDocumentDidClose(params: LSP.DidCloseTextDocumentParams) { + return this.notify('textDocument/didClose', params); + } + public async textDocumentHover(params: LSP.HoverParams) { return await this.request('textDocument/hover', params, timeout); } @@ -397,6 +407,8 @@ export class LanguageServerPlugin implements PluginValue { private documentVersion: number; private allowHTMLContent: boolean; private synchronizationMethod: SynchronizationMethod; + private destroyed = false; + private opened = false; constructor( private view: EditorView, @@ -424,9 +436,7 @@ export class LanguageServerPlugin implements PluginValue { this.client.attachPlugin(this); - this.initialize({ - documentText: this.view.state.doc.toString(), - }); + this.initialize().catch(console.error); } public update({ state, changes, startState, docChanged }: ViewUpdate) { @@ -438,30 +448,44 @@ export class LanguageServerPlugin implements PluginValue { case SynchronizationMethod.Full: this.sendChanges([ { - text: this.view.state.doc.toString(), + text: fullDocument(this.view.state).toString(), }, ]); break; case SynchronizationMethod.Incremental: - this.sendChanges(changeSetToEvents(startState.doc, changes)); + this.sendChanges(changeSetToEvents(startState, changes)); break; } } public destroy() { - this.client.detachPlugin(this); + this.destroyed = true; + if (this.opened) { + this.client + .textDocumentDidClose({ + textDocument: { uri: this.documentUri }, + }) + .catch(console.error) + .finally(() => this.client.detachPlugin(this)); + } else { + this.client.detachPlugin(this); + } } - public async initialize({ documentText }: { documentText: string }) { + public async initialize() { if (this.client.initializePromise) { await this.client.initializePromise; } - this.client.textDocumentDidOpen({ + if (this.destroyed || !this.client.ready) { + return; + } + this.opened = true; + await this.client.textDocumentDidOpen({ textDocument: { uri: this.documentUri, languageId: this.languageId, - text: documentText, + text: fullDocument(this.view.state).toString(), version: this.documentVersion, }, }); @@ -487,7 +511,7 @@ export class LanguageServerPlugin implements PluginValue { } public requestDiagnostics(view: EditorView) { - this.sendChanges([{ text: view.state.doc.toString() }]); + this.sendChanges([{ text: fullDocument(view.state).toString() }]); } public async requestHoverTooltip( @@ -506,11 +530,11 @@ export class LanguageServerPlugin implements PluginValue { return null; } const { contents, range } = result; - let pos = posToOffset(view.state.doc, { line, character })!; + let pos = posToOffset(view.state, { line, character })!; let end: number; if (range) { - pos = posToOffset(view.state.doc, range.start)!; - end = posToOffset(view.state.doc, range.end); + pos = posToOffset(view.state, range.start)!; + end = posToOffset(view.state, range.end); } if (pos === null) { return null; @@ -564,33 +588,16 @@ export class LanguageServerPlugin implements PluginValue { let items = 'items' in result ? result.items : result; - const [span, match] = prefixMatch(items); - const token = context.matchBefore(match); - let { pos } = context; - - if (token) { - pos = token.from; - const word = token.text.toLowerCase(); - if (/^\w+$/.test(word)) { - items = items - .filter(({ label, filterText }) => { - const text = filterText ?? label; - return text.toLowerCase().startsWith(word); - }) - .sort((a, b) => { - const aText = a.sortText ?? a.label; - const bText = b.sortText ?? b.label; - switch (true) { - case aText.startsWith(token.text) && - !bText.startsWith(token.text): - return -1; - case !aText.startsWith(token.text) && - bText.startsWith(token.text): - return 1; - } - return 0; - }); - } + const matchedItems = items.filter(({ textEdit }) => { + if (!isLSPTextEdit(textEdit)) return false; + const start = textEdit.range.start; + return ( + start.line < line || + (start.line === line && start.character < character) + ); + }); + if (matchedItems.length) { + items = matchedItems; } const options = items.map((item) => { const { @@ -612,14 +619,24 @@ export class LanguageServerPlugin implements PluginValue { ) { const changes = []; + if ( + (isLSPTextEdit(textEdit) && + !isEditableRange(view.state, textEdit.range)) || + additionalTextEdits?.some( + (edit) => !isEditableRange(view.state, edit.range), + ) + ) { + console.error( + 'Cannot apply completion outside the editable document', + ); + return; + } + if (isLSPTextEdit(textEdit)) { changes.push({ - from: posToOffset( - view.state.doc, - textEdit.range.start, - ), + from: posToOffset(view.state, textEdit.range.start), to: Math.max( - posToOffset(view.state.doc, textEdit.range.end), + posToOffset(view.state, textEdit.range.end), to, ), insert: textEdit.newText, @@ -635,11 +652,8 @@ export class LanguageServerPlugin implements PluginValue { if (additionalTextEdits) { for (const edit of additionalTextEdits) { changes.push({ - from: posToOffset( - view.state.doc, - edit.range.start, - ), - to: posToOffset(view.state.doc, edit.range.end), + from: posToOffset(view.state, edit.range.start), + to: posToOffset(view.state, edit.range.end), insert: edit.newText, }); } @@ -675,7 +689,7 @@ export class LanguageServerPlugin implements PluginValue { }); return { - from: pos, + from: context.pos, options, filter: false, }; @@ -710,8 +724,8 @@ export class LanguageServerPlugin implements PluginValue { view.dispatch( view.state.update({ selection: { - anchor: posToOffset(view.state.doc, range.start), - head: posToOffset(view.state.doc, range.end), + anchor: posToOffset(view.state, range.start), + head: posToOffset(view.state, range.end), }, scrollIntoView: true, }), @@ -778,8 +792,8 @@ export class LanguageServerPlugin implements PluginValue { const diagnostics = params.diagnostics .map(({ range, message, severity }) => ({ - from: posToOffset(this.view.state.doc, range.start)!, - to: posToOffset(this.view.state.doc, range.end)!, + from: posToOffset(this.view.state, range.start)!, + to: posToOffset(this.view.state, range.end)!, severity: ( { [DiagnosticSeverity.Error]: 'error', @@ -823,6 +837,10 @@ export interface LanguageServerBaseOptions { documentUri: string; /** Language identifier as defined by the LSP specification. */ languageId: string; + /** Text placed before the editable content in the server document. */ + prefix?: string; + /** Text placed after the editable content in the server document. */ + suffix?: string; } /** Options for creating a {@link LanguageServerClient}. */ @@ -875,34 +893,6 @@ function escapeHTML(text: string): string { .replace(/>/g, '>'); } -function toSet(chars: Set) { - let preamble = ''; - let flat = Array.from(chars).join(''); - const words = /\w/.test(flat); - if (words) { - preamble += '\\w'; - flat = flat.replace(/\w/g, ''); - } - return `[${preamble}${flat.replace(/[^\w\s]/g, '\\$&')}]`; -} - -function prefixMatch(items: LSP.CompletionItem[]) { - const first = new Set(); - const rest = new Set(); - - for (const item of items) { - const text = item.textEdit?.newText || item.label; - const initial = text[0]; - first.add(initial); - for (let i = 1; i < text.length; i++) { - rest.add(text[i]); - } - } - - const source = toSet(first) + toSet(rest) + '*$'; - return [new RegExp('^' + source), new RegExp(source)]; -} - function isLSPTextEdit( textEdit?: LSP.TextEdit | LSP.InsertReplaceEdit, ): textEdit is LSP.TextEdit { diff --git a/src/pos.ts b/src/pos.ts index f886f54..34807df 100644 --- a/src/pos.ts +++ b/src/pos.ts @@ -1,9 +1,51 @@ -import type { Text } from '@codemirror/state'; +import { EditorState, Facet, Text } from '@codemirror/state'; + +export const documentPrefix = Facet.define({ + combine: (values) => values[0] ?? '', +}); +export const documentSuffix = Facet.define({ + combine: (values) => values[0] ?? '', +}); + +export function fullDocument(state: EditorState): Text { + return Text.of(state.facet(documentPrefix).split('\n')) + .append(state.doc) + .append(Text.of(state.facet(documentSuffix).split('\n'))); +} + +export function isEditableRange( + state: EditorState, + range: { + start: { line: number; character: number }; + end: { line: number; character: number }; + }, +): boolean { + const doc = fullDocument(state); + const toAbsoluteOffset = (pos: { line: number; character: number }) => { + if (pos.line < 0 || pos.line >= doc.lines || pos.character < 0) return; + const line = doc.line(pos.line + 1); + if (pos.character > line.length) return; + return line.from + pos.character; + }; + const start = toAbsoluteOffset(range.start); + const end = toAbsoluteOffset(range.end); + const prefixLength = state.facet(documentPrefix).length; + return ( + start !== undefined && + end !== undefined && + start >= prefixLength && + start <= end && + end <= prefixLength + state.doc.length + ); +} export function posToOffset( - doc: Text, + document: Text | EditorState, pos: { line: number; character: number }, ) { + const state = document instanceof EditorState ? document : null; + const prefix = state?.facet(documentPrefix) ?? ''; + const doc = state ? fullDocument(state) : (document as Text); if (pos.line >= doc.lines) { return; } @@ -11,13 +53,18 @@ export function posToOffset( if (offset > doc.length) { return; } - return offset; + return state + ? Math.max(0, Math.min(state.doc.length, offset - prefix.length)) + : offset; } -export function offsetToPos(doc: Text, offset: number) { - const line = doc.lineAt(offset); +export function offsetToPos(document: Text | EditorState, offset: number) { + const state = document instanceof EditorState ? document : null; + const doc = state ? fullDocument(state) : (document as Text); + const fullOffset = offset + (state?.facet(documentPrefix).length ?? 0); + const line = doc.lineAt(fullOffset); return { - character: offset - line.from, + character: fullOffset - line.from, line: line.number - 1, }; } diff --git a/src/rename.ts b/src/rename.ts index 68226c3..f0c1d74 100644 --- a/src/rename.ts +++ b/src/rename.ts @@ -3,7 +3,7 @@ import { EditorView, showPanel, Panel } from '@codemirror/view'; import type * as LSP from 'vscode-languageserver-protocol'; import { languageServerPlugin } from './plugin.js'; -import { offsetToPos, posToOffset } from './pos.js'; +import { isEditableRange, offsetToPos, posToOffset } from './pos.js'; const openRenamePanel = StateEffect.define(); const closeRenamePanel = StateEffect.define(); @@ -35,9 +35,15 @@ function applyWorkspaceEdit(view: EditorView, edit: LSP.WorkspaceEdit) { const edits = edit.changes[plugin.documentUri]; if (edits) { for (const e of edits) { + if (!isEditableRange(view.state, e.range)) { + console.error( + 'Cannot rename outside the editable document', + ); + return; + } changes.push({ - from: posToOffset(view.state.doc, e.range.start), - to: posToOffset(view.state.doc, e.range.end), + from: posToOffset(view.state, e.range.start), + to: posToOffset(view.state, e.range.end), insert: e.newText, }); } @@ -50,9 +56,15 @@ function applyWorkspaceEdit(view: EditorView, edit: LSP.WorkspaceEdit) { if (change.textDocument.uri !== plugin.documentUri) continue; for (const e of change.edits) { if ('newText' in e) { + if (!isEditableRange(view.state, e.range)) { + console.error( + 'Cannot rename outside the editable document', + ); + return; + } changes.push({ - from: posToOffset(view.state.doc, e.range.start), - to: posToOffset(view.state.doc, e.range.end), + from: posToOffset(view.state, e.range.start), + to: posToOffset(view.state, e.range.end), insert: e.newText, }); } @@ -118,7 +130,7 @@ async function performRename(view: EditorView, newName: string) { const result = await plugin.client.textDocumentRename({ textDocument: { uri: plugin.documentUri }, - position: offsetToPos(view.state.doc, pos), + position: offsetToPos(view.state, pos), newName, }); @@ -151,7 +163,7 @@ export function renameSymbol(view: EditorView): boolean { plugin.client .textDocumentPrepareRename({ textDocument: { uri: plugin.documentUri }, - position: offsetToPos(view.state.doc, pos), + position: offsetToPos(view.state, pos), }) .then((result) => { if (!result) return; @@ -159,8 +171,8 @@ export function renameSymbol(view: EditorView): boolean { 'placeholder' in result ? result.placeholder : view.state.doc.sliceString( - posToOffset(view.state.doc, result.start), - posToOffset(view.state.doc, result.end), + posToOffset(view.state, result.start), + posToOffset(view.state, result.end), ); view.dispatch({ effects: openRenamePanel.of(placeholder),