-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/language service plugin #154
Draft
ivan-demchenko
wants to merge
4
commits into
mattpocock:main
Choose a base branch
from
ivan-demchenko:feature/language-service-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node | ||
{ | ||
"name": "Node.js & TypeScript", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18", | ||
"features": { | ||
"ghcr.io/devcontainers-contrib/features/pnpm:2": {} | ||
}, | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
"forwardPorts": [3000], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "npm i -g turbo && pnpm install && git config --global core.editor 'code --wait'", | ||
|
||
// Configure tool-specific properties. | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} | ||
} | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
node_modules | ||
.pnp | ||
.pnp.js | ||
.pnpm-store/ | ||
|
||
# testing | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
"extends": "tsconfig/base.json", | ||
"compilerOptions": { | ||
"outDir": "out" | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
"node_modules", | ||
"src/__tests__" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Language Service Plugin | ||
|
||
[Reference](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin) | ||
|
||
To test this plugin out, compile the code and open the `example` folder in a VSCode instance: | ||
|
||
``` | ||
code ./example | ||
``` | ||
|
||
Also, please, make sure the workspace version of TypeScript is used. Use the `TypeScript: Select TypeScript version` command for this. |
4 changes: 4 additions & 0 deletions
4
packages/language-service-plugin/example/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"typescript.tsserver.log": "normal", | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export function A(b: number): number { | ||
return b; | ||
} | ||
A("test") | ||
|
||
|
||
let a: { m: number[] }; | ||
let b = { m: [""] }; | ||
a = b; | ||
|
||
// Extra Properties | ||
|
||
type A = { m: number }; | ||
const w: A = { m: 10, n: "" }; | ||
|
||
// Union Assignments | ||
|
||
type Thing = "none" | { name: string }; | ||
const e: Thing = { name: 0 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@total-typescript/language-service-plugin-example", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"ts-error-translator-tssplugin": "file:..", | ||
"typescript": "^4.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"plugins": [{ | ||
"name": "ts-error-translator-tssplugin" | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ts-error-translator-tssplugin", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "./out/index.js", | ||
"private": true, | ||
"files": [ | ||
"./out/**" | ||
], | ||
"scripts": { | ||
"dev": "tsc --watch", | ||
"build": "rollup -c rollup.config.mjs" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^24.0.1", | ||
"@rollup/plugin-json": "^6.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@rollup/plugin-typescript": "^11.0.0", | ||
"rollup": "^3.14.0", | ||
"tsconfig": "workspace:*", | ||
"typescript": "^4.5.3" | ||
}, | ||
"dependencies": { | ||
"@total-typescript/error-translation-engine": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { nodeResolve } from '@rollup/plugin-node-resolve'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import json from '@rollup/plugin-json'; | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
output: { | ||
file: 'out/index.js', | ||
sourcemap: true, | ||
format: 'cjs' | ||
}, | ||
plugins: [ | ||
nodeResolve({ | ||
extensions: ['.mjs', '.js', '.json', '.node', '.ts'] | ||
}), | ||
commonjs({ extensions: ['.js', '.ts'] }), | ||
typescript(), | ||
json() | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { parseErrors } from '@total-typescript/error-translation-engine'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattpocock I'm not sure if this is the right function to import here |
||
|
||
export default function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) { | ||
const ts = modules.typescript; | ||
|
||
function withParsedError(messageText: string): string { | ||
const parsed = parseErrors(messageText); | ||
const allMessages = parsed.map(err => err.error).join('\n\n'); | ||
return `${messageText}\n\nIn other words,\n${allMessages}\n`; | ||
} | ||
|
||
function enrichDiagnostic(diagnostic: ts.Diagnostic): ts.Diagnostic { | ||
if (typeof diagnostic.messageText === 'string') { | ||
diagnostic.messageText = withParsedError(diagnostic.messageText); | ||
return diagnostic; | ||
} | ||
if (diagnostic.messageText.category === ts.DiagnosticCategory.Error) { | ||
const msg = withParsedError(diagnostic.messageText.messageText); | ||
diagnostic.messageText.messageText = msg; | ||
|
||
const nextMesgs = diagnostic.messageText.next; | ||
if (nextMesgs) { | ||
for (let i = 0; i < nextMesgs.length; i++) { | ||
let nextMsg = nextMesgs[i]; | ||
nextMesgs[i].messageText = withParsedError(nextMsg.messageText); | ||
} | ||
} | ||
} | ||
return diagnostic; | ||
} | ||
|
||
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<keyof ts.LanguageService>) { | ||
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); | ||
} | ||
|
||
proxy.getSemanticDiagnostics = (filename) => { | ||
return info.languageService.getSemanticDiagnostics(filename).map(enrichDiagnostic); | ||
} | ||
|
||
return proxy; | ||
} | ||
|
||
return { create }; | ||
|
||
} | ||
|
||
// export = init; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "tsconfig/base.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"target": "ESNext", | ||
"outDir": "./out", | ||
"rootDir": "src", | ||
"strict": true, | ||
"declaration": true, | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", "out" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattpocock I needed this change to make plugin bundling work.