Skip to content

Commit d8d0779

Browse files
committed
First draft of the language service plugin
1 parent fe2c1d3 commit d8d0779

File tree

11 files changed

+166
-49
lines changed

11 files changed

+166
-49
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"out": true // set this to false to include "out" folder in search results
88
},
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off"
10+
"typescript.tsc.autoDetect": "off",
11+
"typescript.tsserver.log": "normal"
1112
}

packages/language-service-plugin/CHANGELOG.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"typescript.tsserver.log": "normal",
3+
"typescript.tsdk": "node_modules/typescript/lib"
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let a;
2+
3+
export function A(b: number): number {
4+
if (true) {
5+
return 1;
6+
} {
7+
3;
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@total-typescript/language-service-plugin-example",
3+
"version": "0.1.0",
4+
"dependencies": {
5+
"ts-error-translator-tssplugin": "file:..",
6+
"typescript": "^4.8.3"
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"plugins": [{
4+
"name": "ts-error-translator-tssplugin"
5+
}]
6+
}
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "ts-error-translator-tssplugin",
3+
"version": "0.1.0",
4+
"license": "MIT",
5+
"main": "./out/index.js",
6+
"private": true,
7+
"files": ["./out/**"],
8+
"scripts": {
9+
"dev": "tsc --watch",
10+
"build": "tsc"
11+
},
12+
"devDependencies": {
13+
"tsconfig": "workspace:*",
14+
"typescript": "^4.5.3"
15+
}
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
2+
const ts = modules.typescript;
3+
4+
function create(info: ts.server.PluginCreateInfo) {
5+
// Set up decorator object
6+
const proxy: ts.LanguageService = Object.create(null);
7+
8+
for (let k of Object.keys(info.languageService) as Array<keyof ts.LanguageService>) {
9+
const x = info.languageService[k]!;
10+
// @ts-expect-error - JS runtime trickery which is tricky to type tersely
11+
proxy[k] = (...args: Array<{}>) => x.apply(info.languageService, args);
12+
}
13+
14+
// Remove specified entries from completion list
15+
proxy.getCompletionsAtPosition = (fileName, position, options) => {
16+
const prior = info.languageService.getCompletionsAtPosition(fileName, position, options);
17+
if (!prior) {
18+
return prior;
19+
}
20+
prior.entries = prior.entries.filter(e => e.name !== "caller");
21+
const myItem: ts.CompletionEntry = {
22+
name: 'MyTestKeyword',
23+
kind: ts.ScriptElementKind.keyword,
24+
sortText: 'My Test Keyword'
25+
}
26+
prior.entries.push(myItem);
27+
return prior;
28+
};
29+
30+
return proxy;
31+
}
32+
33+
return { create };
34+
35+
}
36+
37+
export = init;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "tsconfig/base.json",
3+
"compilerOptions": {
4+
"outDir": "./out"
5+
},
6+
"include": [
7+
"src"
8+
],
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

pnpm-lock.yaml

Lines changed: 70 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)