Skip to content

Commit

Permalink
added .vscode and img
Browse files Browse the repository at this point in the history
  • Loading branch information
chwoerz committed Dec 16, 2024
1 parent 2805eba commit c2359aa
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 80 deletions.
2 changes: 0 additions & 2 deletions agnostic/agnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function unwrapParenthesizedType(node: Node | undefined): Node {
throw new Error("Node is undefined");
}
if (node?.isKind(SyntaxKind.ParenthesizedType)) {
console.log('unwrapping', node.getText());
return unwrapParenthesizedType(node.getFirstChildByKind(SyntaxKind.ConditionalType));
}
return node;
Expand Down Expand Up @@ -244,7 +243,6 @@ function transformFnToTernary(func: FunctionDeclaration) {
const ternaryExpr = transformIfStatementToTernary(ifStatement, 2);

const fnName = func.getName();
console.log(fnName);
const fnParameters = func
.getParameters()
.map((p) => p.getText().trim())
Expand Down
5 changes: 5 additions & 0 deletions extension/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint", "connor4312.esbuild-problem-matchers", "ms-vscode.extension-test-runner"]
}
99 changes: 27 additions & 72 deletions extension/README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,27 @@
[Alt](https://github.com/typed-rocks/type-buddy/blob/main/extension/imgs/typebuddy-icon.png?raw=true)
# Type Buddy

Helps you read and write types like normal JavaScript functions.

## Features

### Preview
Just hover over a type and it will show you the type as a function:


\!\[feature X\]\(images/feature-x.png\)

> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

## Extension Settings

Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.

For example:

This extension contributes the following settings:

* `myExtension.enable`: Enable/disable this extension.
* `myExtension.thing`: Set to `blah` to do something.

## Known Issues

Calling out known issues can help limit users opening duplicate issues against your extension.

## Release Notes

Users appreciate release notes as you update your extension.

### 1.0.0

Initial release of ...

### 1.0.1

Fixed issue #.

### 1.1.0

Added features X, Y, and Z.

---

## Following extension guidelines

Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.

* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)

## Working with Markdown

You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:

* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.

## For more information

* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)

**Enjoy!**
<div align="center">
<img src="https://github.com/typed-rocks/type-buddy/blob/main/extension/imgs/typebuddy-icon.png?raw=true" alt="Icon" width="150">
</div>
<h1 align="center" style="font-weight: bold; font-size: 40px;">Type Buddy 🤝</h1>

<p align="center" style="font-size: 30px">Finally make <i>sense</i> of your complex types</p>
<p align="center" style="font-size: 30px"><a href="">💻 VSCode Extension</a> | <a href="">🌐 Web App</a></p>
<div align="center">
<p style="font-size:25px">Just <b><i>hover over</i></b> your complex type and reveal the ✨beautiful function✨...</p>
<img src="https://github.com/typed-rocks/type-buddy/blob/main/extension/imgs/hover.png?raw=true" alt="Type Buddy Hover" height="300">
<br /><br />
<p style="font-size:25px">... or use the command palette using <b><i>Show Type Functions</i></b> which shows the function representation as you type</p>
<ol align="left">
<li>Open any TypeScript file</li>
<li>Use the Command Palette command <code>Type Buddy: Open Type Viewer</code></li>
<li>Update your code and the viewer will show you the results as functions.</li>
</ol>
<img src="https://github.com/typed-rocks/type-buddy/blob/main/extension/imgs/show-functions.png?raw=true" alt="Type Buddy: Show Functions" height="300">

<p style="font-size:25px">... or create a ".tb" file and start writing <i>Types</i> as <i>Functions</i> and let the <b><i>Open Type Viewer</i></b> create the types for you.</p>
<ol align="left">
<li>Either use the command <code>Type Buddy: Create Type Buddy Document</code> to create a new <code>.tb</code></tb> file or use an existing one and run the <code>Type Buddy: Open Type Viewer</code> command to start the viewer.</li>
<li>Use the Command Palette command <code>Type Buddy: Open Type Viewer</code></li>
<li>Update your code and the viewer will show you the results as functions.</li>
</ol>
<img src="https://github.com/typed-rocks/type-buddy/blob/main/extension/imgs/type-preview.png?raw=true" alt="Type Preview" height="300">
</div>
Binary file added extension/imgs/type-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"engines": {
"vscode": "^1.85.0"
},
"icon": "imgs/typebuddy-icon.png",
"categories": [
"Debuggers"
],
Expand All @@ -15,7 +16,7 @@
"main": "./dist/extension.js",
"repository": {
"type": "git",
"url": "https://github.com/typed-rocks/type-buddy"
"url": "https://github.com/typed-rocks/type-buddy/extension"
},
"contributes": {
"languages": [
Expand Down
8 changes: 3 additions & 5 deletions extension/src/agnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function unwrapParenthesizedType(node: Node | undefined): Node {
throw new Error("Node is undefined");
}
if (node?.isKind(SyntaxKind.ParenthesizedType)) {
console.log('unwrapping', node.getText());
return unwrapParenthesizedType(node.getFirstChildByKind(SyntaxKind.ConditionalType));
}
return node;
Expand Down Expand Up @@ -244,7 +243,6 @@ function transformFnToTernary(func: FunctionDeclaration) {
const ternaryExpr = transformIfStatementToTernary(ifStatement, 2);

const fnName = func.getName();
console.log(fnName);
const fnParameters = func
.getParameters()
.map((p) => p.getText().trim())
Expand All @@ -265,7 +263,7 @@ function getBlockReturnExpression(block: Statement, indent: number): string {
const returnExpr = singleStmt.getExpression();
if (!returnExpr) {
throw new Error(
"there needs to be a EXACTLY ONE return inside of if, else if or else blocks. NOTHING else.\nLine: " +
"There needs to be a EXACTLY ONE return inside of if, else if or else blocks. NOTHING else.\nLine: " +
singleStmt.getStartLineNumber()
);
}
Expand All @@ -276,7 +274,7 @@ function getBlockReturnExpression(block: Statement, indent: number): string {
}
}
// If there's more complexity here, you'd need more logic.
throw new Error("Expected a single return or a nested if in the block. \nLine: " + block.getStartLineNumber());
throw new Error("Expected a single return or a nested if in the block. \nLine: " + block.getEndLineNumber());
} else if (block.isKind(SyntaxKind.ReturnStatement)) {
// Direct return, no block
const returnExpr = block.getExpression();
Expand All @@ -288,7 +286,7 @@ function getBlockReturnExpression(block: Statement, indent: number): string {

throw new Error(
"This block structure is not supported. Only if, else if or else blocks with exactly one return in there are supported\n Line: " +
block.getStartLineNumber()
block.getEndLineNumber()
);
}

Expand Down
4 changes: 4 additions & 0 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ function getWebviewContent(content: string): string {
overflow-x: auto;
width: 100%;
}
pre {
font-size: 1.2rem;
}
</style>
</head>
Expand Down

0 comments on commit c2359aa

Please sign in to comment.