Skip to content

Commit

Permalink
fix: preview indentations (#8)
Browse files Browse the repository at this point in the history
* fix: preview indentations

* fixed ignored types default

---------

Co-authored-by: Myles Murphy <mylesmurphy@Myless-MacBook-Pro.local>
  • Loading branch information
mylesmmurphy and Myles Murphy authored Jan 5, 2024
1 parent c34f5cd commit 72cf592
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Use the `Prettify TS: Toggle View Nested Types` command to show or hide nested t

Prettify TS works by creating and loading the entire Abstract Syntax Tree (AST) of the file into memory. This is true even for simple types. The time taken can increase with the complexity and size of the types in the file due to the computation involved in parsing and traversing the AST.

The extension attempts to cache the project after the first preview, which should greatly improve the speed of previews.

## Disclaimer

Prettify TS is currently, at best, a working proof of concept. The project is still in its early stages of development and may have limitations or bugs.
Expand All @@ -45,7 +47,7 @@ Contributions are welcome! Please open an issue if you encounter any problems or

Thanks for trying my extension! This is my first VSCode extension, and also my first time working with the TypeScript AST (Abstract Syntax Tree). Any code optimizations would be greatly appreciated.

Special thanks to [@mattpocock](https://github.com/mattpocock) for the Prettify Type, and to [@willbattel](https://github.com/willbattel) for Beta testing, providing feedback, and overall improving this tool!
Special thanks to [@mattpocock](https://github.com/mattpocock) for the Prettify Type, [@willbattel](https://github.com/willbattel) for beta testing, and @mattiamanzati for help with TypeScript AST questions. (https://github.com/mattiamanzati)

## License

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "View \"prettified\" and nested types in hover tooltips and sidebar.",
"publisher": "MylesMurphy",
"license": "MIT",
"version": "0.0.15",
"version": "0.0.16",
"icon": "assets/logo.png",
"engines": {
"vscode": "^1.44.0"
Expand Down
10 changes: 9 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export function formatDeclarationString (declarationString: string, indentation:
if (indentation < 1) return declarationString

// Add newline after { and ;
const splitDeclarationString = declarationString.replace(/{\s/g, '{\n').replace(/;\s/g, ';\n')
const splitDeclarationString = declarationString
.replace(/{/g, '{\n')
.replace(/}/g, '\n}')
.replace(/;/g, ';\n')

let depth = 0
let result = ''
Expand All @@ -87,6 +90,11 @@ export function formatDeclarationString (declarationString: string, indentation:
}
}

// Remove empty braces newlines
result = result.replace(/{\s*\n*\s*}/g, '{}')

// Remove empty lines
result = result.replace(/^\s*[\r\n]/gm, '')
return result
}

Expand Down

0 comments on commit 72cf592

Please sign in to comment.