Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions apps/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { has } from "@pretty-ts-errors/utils";
import { formatDiagnostic } from "@pretty-ts-errors/vscode-formatter";
import {
commands,
env,
ExtensionContext,
languages,
MarkdownString,
Expand All @@ -18,6 +20,16 @@ export function activate(context: ExtensionContext) {
const registeredLanguages = new Set<string>();
const converter = createConverter();

// register the copy command
context.subscriptions.push(
commands.registerCommand(
"prettyTsErrors.copyError",
async (errorMessage: string) => {
await env.clipboard.writeText(errorMessage);
}
)
);

registerSelectedTextHoverProvider(context);

context.subscriptions.push(
Expand Down
12 changes: 11 additions & 1 deletion packages/vscode-formatter/src/components/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const title = (diagnostic: Diagnostic) => d/*html*/ `
<span style="color:#5f5f5f;">
(TS${diagnostic.code})
${errorCodeExplanationLink(diagnostic.code)} |
${errorMessageTranslationLink(diagnostic.message)}
${errorMessageTranslationLink(diagnostic.message)} |
${copyErrorLink(diagnostic.message)}
</span>
`
: ""
Expand All @@ -38,3 +39,12 @@ const errorMessageTranslationLink = (message: Diagnostic["message"]) => {
</span>
</a>`;
};

const copyErrorLink = (message: Diagnostic["message"]) => {
const args = encodeURIComponent(JSON.stringify(message));
return d/*html*/ `
<a title="Copy error to clipboard" href="command:prettyTsErrors.copyError?${args}">
<span class="codicon codicon-copy">
</span>
</a>`;
};