Skip to content
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

feat!: language service plugin #25

Merged
merged 55 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
657571e
initial setup
May 12, 2024
71cfa18
continued setup
May 12, 2024
844e5c0
package lock update
May 12, 2024
f5969a4
working proof of concept
May 13, 2024
3645056
reworked prettify
May 13, 2024
f4b2050
minor changes for symbol declarations
May 13, 2024
b2314ee
updated functionality
May 14, 2024
2a7e533
refactor files
May 14, 2024
faeb2ca
newlines
May 15, 2024
aa9ced0
enum support
May 15, 2024
5def09c
prevent recursion
May 15, 2024
4fce974
updated function names
May 15, 2024
46215c2
added depth counter
May 15, 2024
8cf7181
only increment depth on object properties
May 15, 2024
1bb8af5
use apparent type in some cases
May 20, 2024
09b3852
added literals
May 20, 2024
4068611
add readonly support
May 21, 2024
80af25a
adding settings
May 21, 2024
a5965cc
working prototype
May 21, 2024
e779d7e
use yarn, fixed packaging
May 21, 2024
5ddf276
file cleanup
May 21, 2024
991f22a
fixed tsc
May 21, 2024
93d1850
fix properties slice
May 21, 2024
3034ba9
fixed depth
May 21, 2024
4a00727
fixed enum support
May 21, 2024
7f3fdd3
enum support fixed
May 21, 2024
cff202f
removed redudant primitive type flags
May 22, 2024
41d045a
updated readme
May 22, 2024
b28d982
small updates
May 22, 2024
a98ceca
rename package json to correct identifier
May 22, 2024
b650517
minor fixes
May 22, 2024
b4608cb
removed get type info func
May 22, 2024
0056b30
fixed primitive type check
May 23, 2024
1da0ff0
updated typeof import string
May 23, 2024
423483f
manually join intersections
May 23, 2024
1a46007
version bump
May 23, 2024
627ab18
fix union undefined types
May 23, 2024
e6fc287
transform undefined properties
May 26, 2024
202a8d0
updated readme
Jun 19, 2024
f6cb99b
updated optional properties code
Jun 19, 2024
0008afd
readd optional conversion
Jun 19, 2024
ded52b6
version bump and readme update
Jun 19, 2024
6ee3df1
added sortUnionTypes function
Jun 25, 2024
5ed2a5b
unwrap functions code change
Jun 26, 2024
28d5794
fix for functions and naming conflicts
Jun 27, 2024
b6491ad
fixed multiple function signatures
Jun 27, 2024
d17dc2e
added max union members
Jun 27, 2024
3432dda
added hiding private properties
Jun 27, 2024
5b6735a
version bump
Jun 27, 2024
8fc31bd
added function rest parameters support
Jun 28, 2024
635823d
version bump
Jun 28, 2024
08e8cb6
readme updated
Jun 28, 2024
235dba0
excess props newline
Jun 29, 2024
6145c61
version bump
Jun 29, 2024
d705120
added optional function params
Jun 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "standard-with-typescript",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
"env": {
"browser": true,
"es2021": true
},
"extends": "standard-with-typescript",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"curly": "off"
}
}
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Ignore node_modules directory
node_modules/

# Ignore build output
dist/
packages/*/node_modules/

# Ignore IDE and editor files
.idea/
Expand All @@ -13,10 +11,12 @@ dist/

# Ignore OS generated files
.DS_Store
**/.DS_Store
Thumbs.db

# Build
out
packages/*/out

# Package Files
*.vsix
*.vsix
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
8 changes: 0 additions & 8 deletions .vscode/extensions.json

This file was deleted.

31 changes: 24 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
Expand All @@ -10,12 +6,33 @@
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/packages/*/out/**/*.js"
],
"preLaunchTask": "npm: build"
"preLaunchTask": "build root",
"env": {
"TSS_DEBUG": "9229"
}
},
{
"name": "Attach to TSServer",
"type": "node",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"port": 9229
}
],
"compounds": [
{
"name": "Run Extension and Attach to TSServer",
"configurations": [
"Run Extension",
"Attach to TSServer"
]
}
]
}
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
Expand All @@ -7,5 +6,7 @@
"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",
"editor.tabSize": 2,
"typescript.tsserver.log": "verbose"
}
13 changes: 5 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
"label": "build root",
"type": "shell",
"command": "yarn run build",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
Expand Down
15 changes: 0 additions & 15 deletions .vscodeignore

This file was deleted.

1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-engines true
67 changes: 32 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,56 @@

Prettify TS is a Visual Studio Code extension that enhances your TypeScript development experience. It provides hover information for TypeScript types, classes, interfaces, and more, formatted in a more readable and configurable way.

## Example
![Example Photo](./assets/example.png)
## Developer Notes

## Features
This README is for Development of Prettify TS. The VSCode Extension README can be found [here](./packages/vscode-extension/README.md).

- **Hover Information**: Just hover over a type, class, interface, etc., and you'll see a prettified version of its declaration in the hover panel.
## Scripts

- **Sidebar**: Open the Prettify TS sidebar to view menu options and types.
This project provides several Yarn scripts that you can use to manage the development process:

## Extension Settings
- `yarn install`: Installs all the dependencies for the project. This command should be run after cloning the repository or whenever a new package is added to the `package.json` file.

Prettify TS can be configured to customize your TypeScript development experience. Some settings are available in the extension's menu panel on the sidebar, allow you to easily adjust certain options.
- `yarn build`: Compiles the TypeScript code in the project. This command should be run before testing the extension or preparing it for distribution.

For more advanced settings, like ignoring specific types from Prettification, you can access the Visual Studio Code extension settings. Visual Studio Code extension settings can be found by navigating to the Settings editor and searching for the specific extension by name.
- `yarn package`: Packages the Visual Studio Code extension for distribution. This command should be run when you're ready to create a `.vsix` file that can be installed in Visual Studio Code.

## Commands
You can run these commands from the terminal in the root directory of the project.

Use the `Prettify TS: Toggle Hover` command to enable or disable the hover information feature provided by the Prettify-ts extension.
## Development and Debugging

Use the `Prettify TS: Toggle View Nested Types` command to show or hide nested type information.
In the `.vscode/launch.json` file, we have:

## How it works
- **Run Extension**: Starts a new VS Code instance with the extension loaded. It runs the "build root" task before launching and allows attaching a debugger to the VSCode extension code.

The core function of this extension is accomplished by virtually integrating a [`Prettify`](https://www.totaltypescript.com/concepts/the-prettify-helper) generic into your project. This generic acts as a powerful tool that takes TypeScript types and transforms them into a more readable format.
- **Attach to TSServer**: Attaches the debugger to the TypeScript server running in the extension's context. Use this to debug the TypeScript server's Language Service Plugin.

To achieve this, Prettify TS utilizes the ts-morph library to pass your type to the generic in a virtual replica of your code. It's important to note that the Prettify generic is only added to this virtual copy, and not to your actual codebase.
You can execute these tasks in Visual Studio Code by navigating to the Run view (View > Run), selecting the desired task from the dropdown menu, and pressing the green play button.

```typescript
type Prettify<T> = T extends String | Number | Boolean
? T
: T extends (...args: infer A) => infer R
? (...args: { [K in keyof A]: Prettify<A[K]> } & unknown) => Prettify<R>
: T extends Promise<infer U>
? Promise<Prettify<U>>
: T extends Array<infer U>
? Prettify<U>[]
: T extends object
? { [P in keyof T]: Prettify<T[P]> } & unknown
: T
## Monorepo Structure

type Input = Promise<{ a: number, b: string }>;
type Output = Prettify<Input>;
// Original Output Hint: Promise<Input>
// Prettified Output Hint: Promise<{ a: number; b: string; }>
```
This project is organized as a monorepo, meaning it hosts multiple packages within a single repository. Yarn is required for it's advanced monorepo customizability, specifically it's `nohoist` functionality.

## Contributing
### Packages

Contributions are welcome! Please open an issue if you encounter any problems or have a feature request.
The monorepo includes the following packages:

## Acknowledgements
- `vscode-extension`: This package is the Visual Studio Code extension that integrates the TypeScript Plugin into the editor. It provides the user interface for interacting with Prettify TS.

Thank you for trying out this extension! A special mention to [@mattpocock](https://github.com/mattpocock) for the Prettify Type, [@willbattel](https://github.com/willbattel) for beta testing, and [@mattiamanzati](https://github.com/mattiamanzati) for their TypeScript expertise.
- `typescript-plugin`: This package is a TypeScript language service plugin. It enhances the TypeScript language service with the capabilities of Prettify TS.

### Nohoist and Packaging

In this monorepo, we use Yarn's `nohoist` option for the packages. This is necessary because the Visual Studio Code extension packaging tool (`vsce`) expects all of the extension's dependencies to be located directly in the extension's `node_modules` directory.

Nohoist allows specific dependencies to avoid being hoisted to the root `node_modules` directory, which is the default behavior in a Yarn workspace. Instead, these dependencies are installed directly into the `node_modules` directory of the package that depends on them.

## Roadmap / To-Do

1. Show/Hide Private Properties setting
2. Show/Hide default TS previews (explore moving completely over to overriding)
3. Svelte Support
4. JetBrains Extension

## License

Expand Down
Loading