diff --git a/.vscode/settings.json b/.vscode/settings.json index 30bf8c2..d6b96bc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "out": true // set this to false to include "out" folder in search results }, // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" + "typescript.tsc.autoDetect": "off", + "typescript.tsserver.log": "normal" } \ No newline at end of file diff --git a/packages/language-service-plugin/CHANGELOG.md b/packages/language-service-plugin/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/language-service-plugin/example/.vscode/settings.json b/packages/language-service-plugin/example/.vscode/settings.json new file mode 100644 index 0000000..faee71a --- /dev/null +++ b/packages/language-service-plugin/example/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "typescript.tsserver.log": "normal", + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/packages/language-service-plugin/example/index.ts b/packages/language-service-plugin/example/index.ts new file mode 100644 index 0000000..98cefcb --- /dev/null +++ b/packages/language-service-plugin/example/index.ts @@ -0,0 +1,9 @@ +let a; + +export function A(b: number): number { + if (true) { + return 1; + } { + 3; + } +} \ No newline at end of file diff --git a/packages/language-service-plugin/example/package.json b/packages/language-service-plugin/example/package.json new file mode 100644 index 0000000..a26badb --- /dev/null +++ b/packages/language-service-plugin/example/package.json @@ -0,0 +1,8 @@ +{ + "name": "@total-typescript/language-service-plugin-example", + "version": "0.1.0", + "dependencies": { + "ts-error-translator-tssplugin": "file:..", + "typescript": "^4.8.3" + } +} diff --git a/packages/language-service-plugin/example/tsconfig.json b/packages/language-service-plugin/example/tsconfig.json new file mode 100644 index 0000000..1fd32df --- /dev/null +++ b/packages/language-service-plugin/example/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "plugins": [{ + "name": "ts-error-translator-tssplugin" + }] + } +} \ No newline at end of file diff --git a/packages/language-service-plugin/package.json b/packages/language-service-plugin/package.json new file mode 100644 index 0000000..4db30d3 --- /dev/null +++ b/packages/language-service-plugin/package.json @@ -0,0 +1,16 @@ +{ + "name": "ts-error-translator-tssplugin", + "version": "0.1.0", + "license": "MIT", + "main": "./out/index.js", + "private": true, + "files": ["./out/**"], + "scripts": { + "dev": "tsc --watch", + "build": "tsc" + }, + "devDependencies": { + "tsconfig": "workspace:*", + "typescript": "^4.5.3" + } +} diff --git a/packages/language-service-plugin/src/index.ts b/packages/language-service-plugin/src/index.ts new file mode 100644 index 0000000..c2e2eb4 --- /dev/null +++ b/packages/language-service-plugin/src/index.ts @@ -0,0 +1,37 @@ +function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) { + const ts = modules.typescript; + + function create(info: ts.server.PluginCreateInfo) { + // Set up decorator object + const proxy: ts.LanguageService = Object.create(null); + + for (let k of Object.keys(info.languageService) as Array) { + const x = info.languageService[k]!; + // @ts-expect-error - JS runtime trickery which is tricky to type tersely + proxy[k] = (...args: Array<{}>) => x.apply(info.languageService, args); + } + + // Remove specified entries from completion list + proxy.getCompletionsAtPosition = (fileName, position, options) => { + const prior = info.languageService.getCompletionsAtPosition(fileName, position, options); + if (!prior) { + return prior; + } + prior.entries = prior.entries.filter(e => e.name !== "caller"); + const myItem: ts.CompletionEntry = { + name: 'MyTestKeyword', + kind: ts.ScriptElementKind.keyword, + sortText: 'My Test Keyword' + } + prior.entries.push(myItem); + return prior; + }; + + return proxy; + } + + return { create }; + +} + +export = init; \ No newline at end of file diff --git a/packages/language-service-plugin/tsconfig.json b/packages/language-service-plugin/tsconfig.json new file mode 100644 index 0000000..eefd5b6 --- /dev/null +++ b/packages/language-service-plugin/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "tsconfig/base.json", + "compilerOptions": { + "outDir": "./out" + }, + "include": [ + "src" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32c5e92..46cd6b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,7 +92,7 @@ importers: dependencies: '@types/lz-string': 1.3.34 lz-string: 1.4.4 - next: 13.0.7_sfoxds7t5ydpegc3knd667wn6m + next: 13.1.6_sfoxds7t5ydpegc3knd667wn6m react: 17.0.2 react-dom: 17.0.2_react@17.0.2 react-markdown: 8.0.3_pxzommwrsowkd4kgag6q3sluym @@ -143,6 +143,22 @@ importers: typescript: 4.8.3 vitest: 0.10.5 + packages/language-service-plugin: + specifiers: + tsconfig: workspace:* + typescript: ^4.5.3 + devDependencies: + tsconfig: link:../tsconfig + typescript: 4.8.3 + + packages/language-service-plugin/example: + specifiers: + ts-error-translator-tssplugin: file:.. + typescript: ^4.8.3 + dependencies: + ts-error-translator-tssplugin: file:packages/language-service-plugin + typescript: 4.8.3 + packages/parser: specifiers: '@babel/core': ^7.19.1 @@ -767,8 +783,8 @@ packages: read-yaml-file: 1.1.0 dev: false - /@next/env/13.0.7: - resolution: {integrity: sha512-ZBclBRB7DbkSswXgbJ+muF5RxfgmAuQKAWL8tcm86aZmoiL1ZainxQK0hMcMYdh+IYG8UObAKV2wKB5O+6P4ng==} + /@next/env/13.1.6: + resolution: {integrity: sha512-s+W9Fdqh5MFk6ECrbnVmmAOwxKQuhGMT7xXHrkYIBMBcTiOqNWhv5KbJIboKR5STXxNXl32hllnvKaffzFaWQg==} dev: false /@next/eslint-plugin-next/12.3.0: @@ -777,8 +793,8 @@ packages: glob: 7.1.7 dev: false - /@next/swc-android-arm-eabi/13.0.7: - resolution: {integrity: sha512-QTEamOK/LCwBf05GZ261rULMbZEpE3TYdjHlXfznV+nXwTztzkBNFXwP67gv2wW44BROzgi/vrR9H8oP+J5jxg==} + /@next/swc-android-arm-eabi/13.1.6: + resolution: {integrity: sha512-F3/6Z8LH/pGlPzR1AcjPFxx35mPqjE5xZcf+IL+KgbW9tMkp7CYi1y7qKrEWU7W4AumxX/8OINnDQWLiwLasLQ==} engines: {node: '>= 10'} cpu: [arm] os: [android] @@ -786,8 +802,8 @@ packages: dev: false optional: true - /@next/swc-android-arm64/13.0.7: - resolution: {integrity: sha512-wcy2H0Tl9ME8vKy2GnJZ7Mybwys+43F/Eh2Pvph7mSDpMbYBJ6iA0zeY62iYYXxlZhnAID3+h79FUqUEakkClw==} + /@next/swc-android-arm64/13.1.6: + resolution: {integrity: sha512-cMwQjnB8vrYkWyK/H0Rf2c2pKIH4RGjpKUDvbjVAit6SbwPDpmaijLio0LWFV3/tOnY6kvzbL62lndVA0mkYpw==} engines: {node: '>= 10'} cpu: [arm64] os: [android] @@ -795,8 +811,8 @@ packages: dev: false optional: true - /@next/swc-darwin-arm64/13.0.7: - resolution: {integrity: sha512-F/mU7csN1/J2cqXJPMgTQ6MwAbc1pJ6sp6W+X0z5JEY4IFDzxKd3wRc3pCiNF7j8xW381JlNpWxhjCctnNmfaw==} + /@next/swc-darwin-arm64/13.1.6: + resolution: {integrity: sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -804,8 +820,8 @@ packages: dev: false optional: true - /@next/swc-darwin-x64/13.0.7: - resolution: {integrity: sha512-636AuRQynCPnIPRVzcCk5B7OMq9XjaYam2T0HeWUCE6y7EqEO3kxiuZ4QmN81T7A6Ydb+JnivYrLelHXmgdj6A==} + /@next/swc-darwin-x64/13.1.6: + resolution: {integrity: sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -813,8 +829,8 @@ packages: dev: false optional: true - /@next/swc-freebsd-x64/13.0.7: - resolution: {integrity: sha512-92XAMzNgQazowZ9t7uZmHRA5VdBl/SwEdrf5UybdfRovsxB4r3+yJWEvFaqYpSEp0gwndbwLokJdpz7OwFdL3Q==} + /@next/swc-freebsd-x64/13.1.6: + resolution: {integrity: sha512-qaEALZeV7to6weSXk3Br80wtFQ7cFTpos/q+m9XVRFggu+8Ib895XhMWdJBzew6aaOcMvYR6KQ6JmHA2/eMzWw==} engines: {node: '>= 10'} cpu: [x64] os: [freebsd] @@ -822,8 +838,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm-gnueabihf/13.0.7: - resolution: {integrity: sha512-3r1CWl5P6I5n5Yxip8EXv/Rfu2Cp6wVmIOpvmczyUR82j+bcMkwPAcUjNkG/vMCagS4xV7NElrcdGb39iFmfLg==} + /@next/swc-linux-arm-gnueabihf/13.1.6: + resolution: {integrity: sha512-OybkbC58A1wJ+JrJSOjGDvZzrVEQA4sprJejGqMwiZyLqhr9Eo8FXF0y6HL+m1CPCpPhXEHz/2xKoYsl16kNqw==} engines: {node: '>= 10'} cpu: [arm] os: [linux] @@ -831,8 +847,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-gnu/13.0.7: - resolution: {integrity: sha512-RXo8tt6ppiwyS6hpDw3JdAjKcdVewsefxnxk9xOH4mRhMyq9V2lQx0e24X/dRiZqkx3jnWReR2WRrUlgN1UkSQ==} + /@next/swc-linux-arm64-gnu/13.1.6: + resolution: {integrity: sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -840,8 +856,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-musl/13.0.7: - resolution: {integrity: sha512-RWpnW+bmfXyxyY7iARbueYDGuIF+BEp3etLeYh/RUNHb9PhOHLDgJOG8haGSykud3a6CcyBI8hEjqOhoObaDpw==} + /@next/swc-linux-arm64-musl/13.1.6: + resolution: {integrity: sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -849,8 +865,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-gnu/13.0.7: - resolution: {integrity: sha512-/ygUIiMMTYnbKlFs5Ba9J5k/tNxFWy8eI1bBF8UuMTvV8QJHl/aLDiA5dwsei2kk99/cu3eay62JnJXkSk3RSQ==} + /@next/swc-linux-x64-gnu/13.1.6: + resolution: {integrity: sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -858,8 +874,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-musl/13.0.7: - resolution: {integrity: sha512-dLzr6AL77USJN0ejgx5AS8O8SbFlbYTzs0XwAWag4oQpUG2p3ARvxwQgYQ0Z+6EP0zIRZ/XfLkN/mhsyi3m4PA==} + /@next/swc-linux-x64-musl/13.1.6: + resolution: {integrity: sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -867,8 +883,8 @@ packages: dev: false optional: true - /@next/swc-win32-arm64-msvc/13.0.7: - resolution: {integrity: sha512-+vFIVa82AwqFkpFClKT+n73fGxrhAZ2u1u3mDYEBdxO6c9U4Pj3S5tZFsGFK9kLT/bFvf/eeVOICSLCC7MSgJQ==} + /@next/swc-win32-arm64-msvc/13.1.6: + resolution: {integrity: sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -876,8 +892,8 @@ packages: dev: false optional: true - /@next/swc-win32-ia32-msvc/13.0.7: - resolution: {integrity: sha512-RNLXIhp+assD39dQY9oHhDxw+/qSJRARKhOFsHfOtf8yEfCHqcKkn3X/L+ih60ntaEqK294y1WkMk6ylotsxwA==} + /@next/swc-win32-ia32-msvc/13.1.6: + resolution: {integrity: sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] @@ -885,8 +901,8 @@ packages: dev: false optional: true - /@next/swc-win32-x64-msvc/13.0.7: - resolution: {integrity: sha512-kvdnlLcrnEq72ZP0lqe2Z5NqvB9N5uSCvtXJ0PhKvNncWWd0fEG9Ec9erXgwCmVlM2ytw41k9/uuQ+SVw4Pihw==} + /@next/swc-win32-x64-msvc/13.1.6: + resolution: {integrity: sha512-Ls2OL9hi3YlJKGNdKv8k3X/lLgc3VmLG3a/DeTkAd+lAituJp8ZHmRmm9f9SL84fT3CotlzcgbdaCDfFwFA6bA==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -4337,8 +4353,8 @@ packages: escalade: 3.1.1 dev: true - /next/13.0.7_sfoxds7t5ydpegc3knd667wn6m: - resolution: {integrity: sha512-YfTifqX9vfHm+rSU/H/3xvzOHDkYuMuh4wsvTjiqj9h7qHEF7KHB66X4qrH96Po+ohdid4JY8YVGPziDwdXL0A==} + /next/13.1.6_sfoxds7t5ydpegc3knd667wn6m: + resolution: {integrity: sha512-hHlbhKPj9pW+Cymvfzc15lvhaOZ54l+8sXDXJWm3OBNBzgrVj6hwGPmqqsXg40xO1Leq+kXpllzRPuncpC0Phw==} engines: {node: '>=14.6.0'} hasBin: true peerDependencies: @@ -4355,27 +4371,27 @@ packages: sass: optional: true dependencies: - '@next/env': 13.0.7 + '@next/env': 13.1.6 '@swc/helpers': 0.4.14 caniuse-lite: 1.0.30001435 postcss: 8.4.14 react: 17.0.2 react-dom: 17.0.2_react@17.0.2 - styled-jsx: 5.1.0_react@17.0.2 + styled-jsx: 5.1.1_react@17.0.2 optionalDependencies: - '@next/swc-android-arm-eabi': 13.0.7 - '@next/swc-android-arm64': 13.0.7 - '@next/swc-darwin-arm64': 13.0.7 - '@next/swc-darwin-x64': 13.0.7 - '@next/swc-freebsd-x64': 13.0.7 - '@next/swc-linux-arm-gnueabihf': 13.0.7 - '@next/swc-linux-arm64-gnu': 13.0.7 - '@next/swc-linux-arm64-musl': 13.0.7 - '@next/swc-linux-x64-gnu': 13.0.7 - '@next/swc-linux-x64-musl': 13.0.7 - '@next/swc-win32-arm64-msvc': 13.0.7 - '@next/swc-win32-ia32-msvc': 13.0.7 - '@next/swc-win32-x64-msvc': 13.0.7 + '@next/swc-android-arm-eabi': 13.1.6 + '@next/swc-android-arm64': 13.1.6 + '@next/swc-darwin-arm64': 13.1.6 + '@next/swc-darwin-x64': 13.1.6 + '@next/swc-freebsd-x64': 13.1.6 + '@next/swc-linux-arm-gnueabihf': 13.1.6 + '@next/swc-linux-arm64-gnu': 13.1.6 + '@next/swc-linux-arm64-musl': 13.1.6 + '@next/swc-linux-x64-gnu': 13.1.6 + '@next/swc-linux-x64-musl': 13.1.6 + '@next/swc-win32-arm64-msvc': 13.1.6 + '@next/swc-win32-ia32-msvc': 13.1.6 + '@next/swc-win32-x64-msvc': 13.1.6 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros @@ -5405,8 +5421,8 @@ packages: inline-style-parser: 0.1.1 dev: false - /styled-jsx/5.1.0_react@17.0.2: - resolution: {integrity: sha512-/iHaRJt9U7T+5tp6TRelLnqBqiaIT0HsO0+vgyj8hK2KUk7aejFqRrumqPUlAqDwAj8IbS/1hk3IhBAAK/FCUQ==} + /styled-jsx/5.1.1_react@17.0.2: + resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==} engines: {node: '>= 12.0.0'} peerDependencies: '@babel/core': '*' @@ -6217,3 +6233,9 @@ packages: /zod/3.19.1: resolution: {integrity: sha512-LYjZsEDhCdYET9ikFu6dVPGp2YH9DegXjdJToSzD9rO6fy4qiRYFoyEYwps88OseJlPyl2NOe2iJuhEhL7IpEA==} dev: false + + file:packages/language-service-plugin: + resolution: {directory: packages/language-service-plugin, type: directory} + name: ts-error-translator-tssplugin + version: 0.1.0 + dev: false diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4e708bd..0162815 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,4 @@ packages: - 'packages/*' + - 'packages/language-service-plugin/*' - 'apps/*'