Skip to content

Commit 7361f0c

Browse files
committed
first commit
0 parents  commit 7361f0c

13 files changed

+3300
-0
lines changed

.gitignore

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Mac OS
2+
.DS_Store
3+
4+
# Typescript
5+
tsconfig.tsbuildinfo
6+
7+
examples
8+
9+
# Logs
10+
*.log
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
lerna-debug.log*
15+
.pnpm-debug.log*
16+
17+
# database files
18+
*.rdb
19+
20+
# Diagnostic reports (https://nodejs.org/api/report.html)
21+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
22+
23+
# Runtime data
24+
pids
25+
*.pid
26+
*.seed
27+
*.pid.lock
28+
29+
# Directory for instrumented libs generated by jscoverage/JSCover
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
coverage
34+
*.lcov
35+
36+
# nyc test coverage
37+
.nyc_output
38+
39+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
40+
.grunt
41+
42+
# Bower dependency directory (https://bower.io/)
43+
bower_components
44+
45+
# node-waf configuration
46+
.lock-wscript
47+
48+
# Compiled binary addons (https://nodejs.org/api/addons.html)
49+
build/Release
50+
51+
# Dependency directories
52+
node_modules/
53+
jspm_packages/
54+
55+
# Snowpack dependency directory (https://snowpack.dev/)
56+
web_modules/
57+
58+
# TypeScript cache
59+
*.tsbuildinfo
60+
61+
# Optional npm cache directory
62+
.npm
63+
64+
# Optional eslint cache
65+
.eslintcache
66+
67+
# Optional stylelint cache
68+
.stylelintcache
69+
70+
# Microbundle cache
71+
.rpt2_cache/
72+
.rts2_cache_cjs/
73+
.rts2_cache_es/
74+
.rts2_cache_umd/
75+
76+
# Optional REPL history
77+
.node_repl_history
78+
79+
# Output of 'npm pack'
80+
*.tgz
81+
82+
# Yarn Integrity file
83+
.yarn-integrity
84+
85+
# dotenv environment variable files
86+
.env
87+
.env.development.local
88+
.env.test.local
89+
.env.production.local
90+
.env.local
91+
92+
# parcel-bundler cache (https://parceljs.org/)
93+
.cache
94+
.parcel-cache
95+
96+
# Next.js build output
97+
.next
98+
out
99+
100+
# Nuxt.js build / generate output
101+
.nuxt
102+
dist
103+
104+
# Gatsby files
105+
.cache/
106+
# Comment in the public line in if your project uses Gatsby and not Next.js
107+
# https://nextjs.org/blog/next-9-1#public-directory-support
108+
# public
109+
110+
# vuepress build output
111+
.vuepress/dist
112+
113+
# vuepress v2.x temp and cache directory
114+
.temp
115+
116+
# Docusaurus cache and generated files
117+
.docusaurus
118+
119+
# Serverless directories
120+
.serverless/
121+
122+
# FuseBox cache
123+
.fusebox/
124+
125+
# DynamoDB Local files
126+
.dynamodb/
127+
128+
# TernJS port file
129+
.tern-port
130+
131+
# Stores VSCode versions used for testing VSCode extensions
132+
.vscode-test
133+
134+
# Webstorm
135+
.idea
136+
137+
# yarn v2
138+
.yarn/cache
139+
.yarn/unplugged
140+
.yarn/build-state.yml
141+
.yarn/install-state.gz
142+
.pnp.*
143+
144+
test
145+
examples

README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# TypeScript Type Tree Generator
2+
3+
This project is a TypeScript Language Server Plugin that generates a tree-like structure representing the type information of TypeScript entities. It recursively traverses the types and builds a comprehensive tree, providing a structured view of the types and their relationships.
4+
5+
The plugin handles various TypeScript types including basic types, union types, and complex object types. It also takes care of circular references to prevent infinite recursion. The depth of recursion is configurable, and certain types can be skipped if needed.
6+
7+
This tool is particularly useful for understanding complex type structures in TypeScript projects, aiding in debugging, documentation, and code comprehension.
8+
9+
## Custom Requests through getCompletionsAtPosition
10+
11+
This plugin overrides the `getCompletionsAtPosition` method of the TypeScript Language Server to enable sending custom requests. By hijacking this method, we can intercept the completion request and inject our own logic to generate and return the type tree.
12+
13+
When a completion request is made with the Prettify Metadata flag, instead of providing the usual code completions, the plugin generates a type tree for the entity at the cursor position. This type tree is then included in the completion details that are sent back to the client.
14+
15+
This approach allows us to leverage the existing communication channel between the client and the server, and to provide additional information without requiring changes to the client or the protocol.
16+
17+
## Response TypeInfo
18+
19+
The response from the plugin includes a `TypeInfo` object, which contains detailed type information about a TypeScript node. Here's a breakdown of its structure:
20+
21+
```typescript
22+
type TypeTree = {
23+
typeName: string;
24+
kind: "union";
25+
excessMembers: number;
26+
types: TypeTree[];
27+
} | {
28+
typeName: string;
29+
kind: "intersection";
30+
types: TypeTree[];
31+
} | {
32+
typeName: string;
33+
kind: "object";
34+
excessProperties: number;
35+
properties: {
36+
name: string;
37+
readonly: boolean;
38+
type: TypeTree;
39+
}[];
40+
} | {
41+
typeName: string;
42+
kind: "array";
43+
readonly: boolean;
44+
elementType: TypeTree;
45+
} | {
46+
typeName: string;
47+
kind: "function";
48+
signatures: {
49+
returnType: TypeTree;
50+
parameters: {
51+
name: string;
52+
isRestParameter: boolean;
53+
type: TypeTree;
54+
}[];
55+
}[];
56+
} | {
57+
typeName: string;
58+
kind: "promise";
59+
type: TypeTree;
60+
} | {
61+
typeName: string;
62+
kind: "enum";
63+
member: string;
64+
} | {
65+
typeName: string;
66+
kind: "basic";
67+
}
68+
69+
/**
70+
* TypeInfo contains the type information of a TypeScript node.
71+
*/
72+
type TypeInfo = {
73+
typeTree: TypeTree
74+
syntaxKind: ts.SyntaxKind
75+
name: string
76+
}
77+
```

biome.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"ignore": ["test", "dist", "node_modules"]
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "space"
15+
},
16+
"organizeImports": {
17+
"enabled": true
18+
},
19+
"linter": {
20+
"enabled": true,
21+
"rules": {
22+
"recommended": true,
23+
"correctness": {
24+
"noUnusedVariables": "warn",
25+
"noUnusedFunctionParameters": "warn",
26+
"noUnusedImports": "warn"
27+
},
28+
"suspicious": {
29+
"noExplicitAny": "off"
30+
},
31+
"style": {
32+
"noNonNullAssertion": "off",
33+
"noParameterAssign": "off",
34+
"noInferrableTypes": "off"
35+
}
36+
}
37+
},
38+
"javascript": {
39+
"formatter": {
40+
"quoteStyle": "single",
41+
"semicolons": "asNeeded"
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)