Skip to content

Commit fe420dd

Browse files
reimplement button-to-open-in-new-tab + custom webview #133 (monorepo) (#152)
* reimplement #133 in the monorepo setup * port the changes of web-preview-poc; integrate vscode-shiki-bridge * stich everything together * Get the feature working * implement webview as seperate files, implement csp with a lot of headaches * finalize implementation * implement the webviewviewprovider * finalize webview parts * remove obsolete files * remove obsolete file * implement proper markdown rendering * bump vscode-shiki-bridge to v0.3.0 * implement vscode-shiki-bridge * Few minor fixes * fix copy type button * only hide new tab button in the new tab markdown preview * use whitelisted badge urls * avoid triggering complete rerenders of the webview * decrease vertical padding * keep track of shown diagnostic per webview, to ensure the panel is refreshed when the original diagnostic no longer exists * add missing .delete on the weakmap * add another .delete to onDidDispose to prevent leaking memory * fix background color of the panel preview variant * bump version in lock * Remove icons not in use to reduce size --------- Co-authored-by: Yoav Balasiano <yoavbls@gmail.com>
1 parent b0c5aa6 commit fe420dd

23 files changed

Lines changed: 1571 additions & 54 deletions

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<b>Make TypeScript errors prettier and human-readable in VSCode.</b>
1212

1313
[![GitHub stars](https://img.shields.io/github/stars/yoavbls/pretty-ts-errors.svg?style=social&label=Star)](https://GitHub.com/yoavbls/pretty-ts-errors/stargazers/)
14-
[![Visual Studio Code](https://custom-icon-badges.demolab.com/badge/Visual%20Studio%20Code-0078d7.svg?logo=vsc&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)&nbsp;[![GitHub license](https://badgen.net/github/license/yoavbls/pretty-ts-errors)](https://github.com/yoavbls/pretty-ts-errors/blob/main/LICENSE)&nbsp;[![Visual Studio Code](https://img.shields.io/visual-studio-marketplace/i/yoavbls.pretty-ts-errors)](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
14+
[![Visual Studio Code][vsc]](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)&nbsp;[![GitHub license](https://badgen.net/github/license/yoavbls/pretty-ts-errors)](https://github.com/yoavbls/pretty-ts-errors/blob/main/LICENSE)&nbsp;[![Visual Studio Code](https://img.shields.io/visual-studio-marketplace/i/yoavbls.pretty-ts-errors)](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
1515
<a href="https://github.com/yoavbls/pretty-ts-errors/discussions/43#user-content-jetbrains-support"><img src="https://cdn.icon-icons.com/icons2/2530/PNG/512/jetbrains_webstorm_button_icon_151873.png" height="20" alt="Webstorm logo"></a>
16-
[![Cursor](https://custom-icon-badges.demolab.com/badge/Cursor-000000?logo=cursor-ai-white)](https://open-vsx.org/extension/yoavbls/pretty-ts-errors)
16+
[![Cursor](https://img.shields.io/badge/Cursor-000000?logo=cursor)](https://open-vsx.org/extension/yoavbls/pretty-ts-errors)
1717

18-
TypeScript errors become messier as the complexity of types increases. At some point, TypeScript will throw on you a shitty heap of parentheses and `"..."`.
18+
TypeScript errors become messier as the complexity of types increases. At some point, TypeScript will throw on you a shitty heap of parentheses and `"..."`.
1919
This extension will help you understand what's going on. For example, in this relatively simple error:
2020

2121
<img src="./assets/this.png" width="340.438px" />&nbsp; &nbsp; <img src="./assets/instead-of-that.png" width="350px" />
@@ -61,10 +61,10 @@ Follow the instructions [there](./docs/hide-original-errors.md). unfortunately,
6161

6262
## Why isn't it trivial
6363

64-
1. TypeScript errors contain types that are not valid in TypeScript.
64+
1. TypeScript errors contain types that are not valid in TypeScript.
6565
Yes, these types include things like `... more ...`, `{ ... }`, etc in an inconsistent manner. Some are also cutting in the middle because they're too long.
6666
2. Types can't be syntax highlighted in code blocks because the part of `type X = ...` is missing, so I needed to create a new TextMate grammar, a superset of TypeScript grammar called `type`.
67-
3. VSCode markdown blocks all styling options, so I had to find hacks to style the error messages. e.g., there isn't an inlined code block on VSCode markdown, so I used a code block inside a codicon icon, which is the only thing that can be inlined. That's why it can't be copied. but it isn't a problem because you can still hover on the error and copy things from the original error pane.
67+
3. VSCode markdown blocks all styling options, so I had to find hacks to style the error messages. e.g., there isn't an inlined code block on VSCode markdown, so I used a code block inside a codicon icon, which is the only thing that can be inlined. That's why it can't be copied. but it isn't a problem because you can still hover on the error and copy things from the original error pane.
6868
<img src="./assets/errors-hover.png" width="600" />
6969

7070
## Hype section
@@ -82,7 +82,7 @@ Follow the instructions [there](./docs/hide-original-errors.md). unfortunately,
8282
</picture>
8383
</a>
8484
<a href="https://twitter.com/t3dotgg/status/1647759462709747713">
85-
<picture>
85+
<picture>
8686
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/yoavbls/pretty-ts-errors/main/assets/mentions/theo-dark.png#gh-dark-mode-only">
8787
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/yoavbls/pretty-ts-errors/main/assets/mentions/theo-light.png#gh-light-mode-only">
8888
<img width="400" src="https://raw.githubusercontent.com/yoavbls/pretty-ts-errors/main/assets/mentions/theo-dark.png#gh-dark-mode-only" alt="Theo's tweet">
@@ -104,13 +104,13 @@ Follow the instructions [there](./docs/hide-original-errors.md). unfortunately,
104104
<td align="center">
105105
<a href="https://github.com/kentcdodds">
106106
<img src="https://images.weserv.nl/?url=github.com/kentcdodds.png&fit=cover&mask=circle" width="80"><br>
107-
Kent C. Dodds
107+
Kent C. Dodds
108108
<a/>
109109
</td>
110110
<td align="center">
111111
<a href="https://github.com/mattpocock">
112112
<img src="https://images.weserv.nl/?url=github.com/mattpocock.png&fit=cover&mask=circle" width="80"><br>
113-
Matt Pocock
113+
Matt Pocock
114114
<a/>
115115
</td>
116116
<td align="center">
@@ -122,7 +122,7 @@ Follow the instructions [there](./docs/hide-original-errors.md). unfortunately,
122122
<td align="center">
123123
<a href="https://github.com/tannerlinsley">
124124
<img src="https://images.weserv.nl/?url=github.com/tannerlinsley.png&fit=cover&mask=circle" width="80"><br>
125-
Tanner Linsley
125+
Tanner Linsley
126126
<a/>
127127
</td>
128128
<td align="center">
@@ -137,10 +137,12 @@ Follow the instructions [there](./docs/hide-original-errors.md). unfortunately,
137137

138138
## Sponsorship
139139

140-
Every penny will be invested in other contributors to the project, especially ones that work
140+
Every penny will be invested in other contributors to the project, especially ones that work
141141
on things that I can't be doing myself like adding support to the extension for other IDEs 🫂
142142

143143
## Contribution
144144

145-
Help by upvoting or commenting on issues we need to be resolved [here](https://github.com/yoavbls/pretty-ts-errors/discussions/43)
145+
Help by upvoting or commenting on issues we need to be resolved [here](https://github.com/yoavbls/pretty-ts-errors/discussions/43)
146146
Any other contribution is welcome. Feel free to open any issue / PR you think.
147+
148+
[vsc]: https://img.shields.io/badge/Visual%20Studio%20Code-0078d7?logoColor=white&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABAAAAAQAAgMAAAACc8MQAAAAAXNSR0IArs4c6QAAAAxQTFRFR3BM////////////Bp/QCgAAAAN0Uk5TABla6sjVLAAAFQlJREFUeNrtnUFu7Dp2hg9l4GmggRdwB1yClmBuJpNk8JYgLsHbyChLkJegJTCBBxkWAgWh0yWeRnfjgbN2qZ7I/5DH3/heoPD5nA+UjDLphx9++OGHH35olH8h3az8RZqZmDmQYhZmTo7UMvDf2HVvADO/k1Zm/jsHaWXlf/CpNgF/4LQm4A++FCdAcwfXLCA5nQnIfCpNQMbrTEDmS2kCMkFnAtAdxCcgE5UmIPOuMwGZpDQBmU+lCch4nQnIfClNQCboTEAmOZ0JyESlCci860xAJilNQOZTaQIyXmcCMl9KE5AJOhOQSU5nAjK70gRk3nUmIHMoTUDmU0ECNHdw5m/5UpAAvR0c+AGSggSo7eDMD+EVJEBnBwd+kKAzAZnkdCYgE5UmIPOuMwGZpDQBmU+lCch4nQnIfClNQCboTEAmOZ0JyESlCci860xAJilNQOZTaQIyXmcCMl9KE5AJOhOQSU5nAjK70gRk3nUmIHMoTUDmU2kCMk5nAjJRaQIy7zoTkElKE5D5VJqAjNeZgMyX0gRkgs4EZJLTmYBMVJqAzLvOBGSS0gRkPpUmION1JiDzpTQBmaAzAZnkdCYgE5UmIPOuMwGZpDQBmU+lCch4nQnIfClNQ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SKSKV8BDkOwIRFIG4AggOgKBtPEKOAIIjoAnfQCOAGIjkEgjr4AjgNAIRNIJ4AggMwKBlPIKOAJIjIAnteQjgFLmfATQyW/5CKCUf+P/ph9++OGHH3744Ycn+StuK4YiyBVN0wAAAABJRU5ErkJggg==

apps/vscode-extension/package.json

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Pretty TypeScript Errors",
44
"publisher": "YoavBls",
55
"description": "Make TypeScript errors prettier and more human-readable in VSCode",
6-
"version": "0.6.3",
6+
"version": "0.7.0",
77
"icon": "assets/icon.png",
88
"repository": {
99
"type": "git",
@@ -45,9 +45,35 @@
4545
"dist/**/*",
4646
"assets/**/*",
4747
"syntaxes/**/*",
48+
"webview/**/*",
4849
"LICENSE"
4950
],
5051
"contributes": {
52+
"views": {
53+
"explorer": [
54+
{
55+
"id": "prettyTsErrors.markdownPreview",
56+
"icon": "$(open-preview)",
57+
"name": "Pretty TypeScript Error",
58+
"type": "webview",
59+
"visibility": "collapsed"
60+
}
61+
]
62+
},
63+
"commands": [
64+
{
65+
"command": "prettyTsErrors.openMarkdownPreview",
66+
"title": "Open the diagnostic in a new tab",
67+
"category": "Pretty TS Errors",
68+
"enablement": "!isCommandPanel"
69+
},
70+
{
71+
"command": "prettyTsErrors.revealSelection",
72+
"title": "Reveal the given selection",
73+
"category": "Pretty TS Errors",
74+
"enablement": "!isCommandPanel"
75+
}
76+
],
5177
"languages": [
5278
{
5379
"id": "type",
@@ -78,12 +104,16 @@
78104
"watch-tests": "tsc -p . -w --outDir out",
79105
"pretest": "npm run compile-tests && npm run compile && npm run lint",
80106
"lint": "tsc -p . --noEmit",
81-
"test": "node ./out/test/runTest.js"
107+
"test": "node ./out/test/runTest.js",
108+
"webview": "npx http-server ./webview -o -a localhost -p 8080"
82109
},
83110
"devDependencies": {
111+
"@shikijs/types": "^3.13.0",
84112
"@types/mocha": "^10.0.10",
85113
"@types/node": "^16.11.68",
86114
"@types/vscode": "^1.77.0",
115+
"@types/vscode-webview": "^1.57.5",
116+
"@vscode/codicons": "^0.0.41",
87117
"@vscode/test-electron": "^2.5.2",
88118
"esbuild": "^0.25.11",
89119
"glob": "^11.0.3",
@@ -93,6 +123,9 @@
93123
"dependencies": {
94124
"@pretty-ts-errors/formatter": "*",
95125
"@pretty-ts-errors/vscode-formatter": "*",
96-
"vscode-languageclient": "^9.0.1"
126+
"markdown-exit": "^1.0.0-beta.6",
127+
"shiki": "^3.13.0",
128+
"vscode-languageclient": "^9.0.1",
129+
"vscode-shiki-bridge": "^0.3.0"
97130
}
98-
}
131+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { commands, env, window, type ExtensionContext } from "vscode";
2+
3+
export function registerCopyError(context: ExtensionContext) {
4+
context.subscriptions.push(
5+
commands.registerCommand(
6+
"prettyTsErrors.copyError",
7+
async (errorMessage: string) => {
8+
await env.clipboard.writeText(errorMessage);
9+
window.showInformationMessage("Copied error message to clipboard!");
10+
}
11+
)
12+
);
13+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
type ExtensionContext,
3+
commands,
4+
Range,
5+
TabInputText,
6+
TabInputWebview,
7+
Uri,
8+
ViewColumn,
9+
window,
10+
} from "vscode";
11+
import { MarkdownWebviewProvider } from "../provider/markdownWebviewProvider";
12+
13+
export function registerRevealSelection(context: ExtensionContext) {
14+
context.subscriptions.push(
15+
commands.registerCommand(
16+
"prettyTsErrors.revealSelection",
17+
async (uri: Uri, range: Range) => {
18+
// ensure these are real instances
19+
uri = Uri.from({ ...uri });
20+
range = new Range(
21+
range.start.line,
22+
range.start.character,
23+
range.end.line,
24+
range.end.character
25+
);
26+
27+
// default behaviour is to use the active view column
28+
let viewColumn = ViewColumn.Active;
29+
30+
// detect if the active tab is our preview webview
31+
let isFromMarkdownPreviewWebview = false;
32+
const activeTab = window.tabGroups.activeTabGroup.activeTab;
33+
if (activeTab && activeTab.input instanceof TabInputWebview) {
34+
// For an unknown reason this string is prefixed with something like `mainthread-${viewType}`
35+
// endsWith should handle a full match and the prefixed versions
36+
if (
37+
activeTab.input.viewType.endsWith(MarkdownWebviewProvider.viewType)
38+
) {
39+
isFromMarkdownPreviewWebview = true;
40+
}
41+
}
42+
43+
if (isFromMarkdownPreviewWebview) {
44+
// find a tab group where the file is open, then use that view column for the `vscode.open` command
45+
const tabs = window.tabGroups.all.flatMap(
46+
(tabGroup) => tabGroup.tabs
47+
);
48+
const tabWithFileOpen = tabs.find((tab) => {
49+
if (tab.input instanceof TabInputText) {
50+
return tab.input.uri.toString() === uri.toString();
51+
}
52+
return false;
53+
});
54+
if (tabWithFileOpen) {
55+
viewColumn = tabWithFileOpen.group.viewColumn;
56+
} else {
57+
// If markdown preview is not open on 1, open the link in 1, else open the link in 2
58+
viewColumn =
59+
activeTab!.group.viewColumn !== 1
60+
? ViewColumn.One
61+
: ViewColumn.Two;
62+
}
63+
}
64+
65+
return commands.executeCommand("vscode.open", uri, {
66+
selection: range,
67+
viewColumn,
68+
});
69+
}
70+
)
71+
);
72+
}

0 commit comments

Comments
 (0)