Skip to content

Commit 34ea065

Browse files
authored
feat: make errors copyable (#156)
* feat: make errors copyable
1 parent 8527285 commit 34ea065

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

apps/vscode-extension/src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { has } from "@pretty-ts-errors/utils";
22
import { formatDiagnostic } from "@pretty-ts-errors/vscode-formatter";
33
import {
4+
commands,
5+
env,
46
ExtensionContext,
57
languages,
68
MarkdownString,
@@ -18,6 +20,16 @@ export function activate(context: ExtensionContext) {
1820
const registeredLanguages = new Set<string>();
1921
const converter = createConverter();
2022

23+
// register the copy command
24+
context.subscriptions.push(
25+
commands.registerCommand(
26+
"prettyTsErrors.copyError",
27+
async (errorMessage: string) => {
28+
await env.clipboard.writeText(errorMessage);
29+
}
30+
)
31+
);
32+
2133
registerSelectedTextHoverProvider(context);
2234

2335
context.subscriptions.push(

packages/vscode-formatter/src/components/title.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const title = (diagnostic: Diagnostic) => d/*html*/ `
1111
<span style="color:#5f5f5f;">
1212
(TS${diagnostic.code})
1313
${errorCodeExplanationLink(diagnostic.code)} |
14-
${errorMessageTranslationLink(diagnostic.message)}
14+
${errorMessageTranslationLink(diagnostic.message)} |
15+
${copyErrorLink(diagnostic.message)}
1516
</span>
1617
`
1718
: ""
@@ -38,3 +39,12 @@ const errorMessageTranslationLink = (message: Diagnostic["message"]) => {
3839
</span>
3940
</a>`;
4041
};
42+
43+
const copyErrorLink = (message: Diagnostic["message"]) => {
44+
const args = encodeURIComponent(JSON.stringify(message));
45+
return d/*html*/ `
46+
<a title="Copy error to clipboard" href="command:prettyTsErrors.copyError?${args}">
47+
<span class="codicon codicon-copy">
48+
</span>
49+
</a>`;
50+
};

0 commit comments

Comments
 (0)