-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of the language service plugin
- Loading branch information
Showing
12 changed files
with
179 additions
and
49 deletions.
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
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,9 @@ | ||
let a; | ||
|
||
export function A(b: number): number { | ||
if (true) { | ||
return 1; | ||
} { | ||
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,8 @@ | ||
{ | ||
"name": "@total-typescript/language-service-plugin-example", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"ts-error-translator-tssplugin": "file:..", | ||
"typescript": "^4.8.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,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" | ||
} | ||
} |
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,32 @@ | ||
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) { | ||
const ts = modules.typescript; | ||
|
||
function enrichDiagnostic(diagnostic: ts.Diagnostic): ts.Diagnostic { | ||
// diagnostic.code: number | ||
// diagnostic.category === ts.DiagnosticCategory (Error, Message, Suggestion, Warning) | ||
diagnostic.messageText = `${diagnostic.messageText}\n\nHello from plugin!\n` | ||
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,19 @@ | ||
{ | ||
"extends": "tsconfig/base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "ES2019", | ||
"outDir": "./out", | ||
"rootDir": "src", | ||
"strict": true, | ||
"declaration": true, | ||
"sourceMap": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 +1,4 @@ | ||
packages: | ||
- 'packages/*' | ||
- 'packages/language-service-plugin/*' | ||
- 'apps/*' |