Problems: Copy Plus
Copy diagnostic messages from the Problems Panel to the clipboard or a file. This extension provides powerful features to filter, format, and save exactly what you need, overcoming the limitations of VS Code's built-in functionality.
Key Features
- Copy Everything: Copy diagnostics from all files in your workspace or just from the currently active file.
- Flexible Filtering: Filter problems by severity (errors, warnings, etc.), file path (e.g.,
**/src/*.js
), or message content (with simple text like 'variable'
or regular expressions like /deprecated/i
).
- Custom Formatting: Define your own output format using a simple template string, replacing the default verbose format.
- JSON Output: Save problems to a JSON file with a configurable structure—from raw diagnostic data to objects based on your custom templates.
- Template Preview: Instantly see what your custom template will look like with a dedicated preview command.
- Powerful Keybindings: Create custom shortcuts for specific tasks, like a hotkey to copy only errors from your test files as JSON.
Commands
The extension provides two types of commands:
General Commands
These commands copy problems based on your saved settings. They are ideal for use from the Command Palette (Ctrl+Shift+P
).
Problems: Copy All Problems
Problems: Copy Current File Problems
Specialized Commands
These commands are designed for specific, recurring tasks and are ideal for assigning to keybindings. They ignore the default severity filter settings and copy only what their name implies.
Problems: Copy All Errors Only
Problems: Copy Current File Errors Only
Problems: Copy All Errors and Warnings Only
Problems: Copy Current File Errors and Warnings Only
Settings
You can easily configure the extension.
Templates
problems-copy-plus.templateMode
Selects the template mode: default
(built-in format) or custom
(uses your template).
problems-copy-plus.customTemplate
A string for custom output formatting. Only active when templateMode
is set to custom
.
Available Variables:
${problemNumber}
: The sequential number of the problem.
${severity}
: The severity (Error, Warning, Information, Hint).
${path}
: The relative path to the file.
${fileName}
: The file name only.
${message}
: The diagnostic message.
${source}
: The source (e.g., eslint, ts).
${code}
: The error/warning code.
${startLine}
/ ${startCol}
: The starting line/column.
${endLine}
/ ${endCol}
: The ending line/column.
${lineContent}
: The content of the line of code with the problem (may have a minor performance impact).
${relatedInfoBlock}
: A block of related information (formatted by relatedInfoTemplate
).
problems-copy-plus.relatedInfoTemplate
Defines how each relatedInformation
entry is formatted, replacing the ${relatedInfoBlock}
placeholder.
JSON Output
problems-copy-plus.outputAsJson
If true
, enables JSON output and saves it to a file. If false
, copies formatted text to the clipboard.
problems-copy-plus.jsonStructure
Controls the JSON structure: raw
(full diagnostic object), fromDefaultTemplate
(JSON from the built-in template), or fromCustomTemplate
(JSON from your custom template).
problems-copy-plus.jsonOutputTarget
Defines where the JSON file is saved: saveToWorkspaceRoot
(in the project root) or saveAlongsideSourceFile
(next to the source file, only for current-file commands).
Default Filters
These settings control which problem types (errors, warnings, etc.) are included when running commands like Problems: Copy All Problems
etc.
problems-copy-plus.includeErrors
(default: true
)
problems-copy-plus.includeWarnings
(default: true
)
problems-copy-plus.includeInformations
(default: true
)
problems-copy-plus.includeHints
(default: true
)
If you find this extension useful, please consider supporting my work. You can also join our Telegram channel for news and discussions!
Advanced Usage: Keybindings
For specific, repetitive tasks, you can create custom shortcuts that perform actions with their own unique settings. For example, instead of changing your main settings every time you want to copy only errors, you can create a dedicated hotkey just for that.
This is done by adding an args
section to a command in your keybindings.json
file. Any setting defined in args
will override your main settings for that single action.
Example
This keybinding (Alt+C
) copies only errors and warnings from JS files inside the src
directory that contain the word deprecated
, and formats the output as JSON, regardless of your global settings.
{
"key": "alt+c",
"command": "problems-copy-plus.copyAll",
"args": {
// Task: "Find all deprecated code warnings in my JS source files"
// 1. We only want to see actual problems.
"errors": true,
"warnings": true,
"informations": false, // ...so we ignore info and hints.
"hints": false,
// 2. Only search within JavaScript files in the 'src' directory.
"fileFilter": "**/src/**/*.js",
// 3. Find any problem message containing the word 'deprecated', case-insensitively.
"messageFilter": "/deprecated/i",
// 4. Output the result as a JSON object instead of plain text.
"outputAsJson": true
}
}
Available args
errors
, warnings
, informations
, hints
Values: true
or false
.
Use true
to include a severity level. If a level is set to false
or not listed, it will be excluded.
messageFilter
Values: A string of text.
Filters problems to only include messages that contain specific text. You can use simple text (e.g., "variable"
) or a regular expression (e.g., "/deprecated/i"
).
fileFilter
Values: A string with file path patterns.
Filters problems to only include files that match the pattern, e.g., "**/test/**/*.js"
.
outputAsJson
Values: true
or false
.
Use true
to save the output to a .json
file. If omitted or set to false
, the output will be copied to the clipboard as text.
Default Template Output
The default template is:
${problemNumber}. ${severity}: \"${message}\"\\n File: ${path}\\n Location: [${startLine}:${startCol}]\\n Source: ${source}(${code})\\n Code: > ${lineContent}${relatedInfoBlock}
Click to see example output
1. Error: "Missing semicolon."
File: path/to/your/file.js
Location: [11:5]
Source: eslint(semi)
Code: > const name = 'world'
2. Error: "Cannot redeclare block-scoped variable 'myVar'."
File: path/to/your/file.js
Location: [26:7]
Source: typescript(2451)
Code: > const myVar = 42;
- path/to/your/file.js: 'myVar' was also declared here. [6:5]
JSON Output (raw
)
Click to see «raw»
[
{
"resource": "/path/to/your/file.js",
"code": "semi",
"severity": 0,
"message": "Missing semicolon.",
"source": "eslint",
"startLineNumber": 11,
"startColumn": 5,
"endLineNumber": 11,
"endColumn": 16
},
{
"resource": "/path/to/your/file.js",
"code": "2451",
"severity": 0,
"message": "Cannot redeclare block-scoped variable 'myVar'.",
"source": "typescript",
"startLineNumber": 26,
"startColumn": 7,
"endLineNumber": 26,
"endColumn": 12,
"relatedInformation": [
{
"startLineNumber": 6,
"startColumn": 5,
"endLineNumber": 6,
"endColumn": 10,
"message": "'myVar' was also declared here.",
"resource": "/path/to/your/file.js"
}
]
}
]
This extension is a fork of the original Problems: Copy by ArturoDent.