Skip to content

Commit

Permalink
feat: add command to force update decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
usernamehw committed Dec 20, 2024
1 parent 45521ba commit 6869ea1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the entire line wherever a diagnostic is generated by the language and also prin
- Show message in status bar

<!-- COMMANDS_START -->
## Commands (13)
## Commands (14)

|Command|Description|
|-|-|
Expand All @@ -33,6 +33,7 @@ the entire line wherever a diagnostic is generated by the language and also prin
|errorLens.findLinterRuleDefinition|Error Lens: Search in local linter files (like `.eslintrc.json`) for the rule definition. Target files are controlled by "errorLens.lintFilePaths" setting.|
|errorLens.copyProblemMessage|Error Lens: Copy problem message to the clipboard (at the active cursor).|
|errorLens.copyProblemCode|Error Lens: Copy problem code to the clipboard (at the active cursor).|
|errorLens.updateEverything|Error Lens: Update all decorations. Supports args {"kind": "update" \| "clear"}|
<!-- COMMANDS_END -->
<!-- SETTINGS_START -->
## Settings (72)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
"title": "Copy Problem Code",
"description": "Copy problem code to the clipboard (at the active cursor).",
"category": "Error Lens"
},
{
"command": "errorLens.updateEverything",
"title": "Update Everything",
"description": "Update all decorations. Supports args {\"kind\": \"update\" | \"clear\"}",
"category": "Error Lens"
}
],
"configuration": {
Expand Down
4 changes: 4 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { selectProblemCommand } from 'src/commands/selectProblemCommand';
import { statusBarCommand } from 'src/commands/statusBarCommand';
import { toggleEnabledLevels } from 'src/commands/toggleEnabledLevels';
import { toggleWorkspaceCommand } from 'src/commands/toggleWorkspaceCommand';
import { updateEverythingCommand } from 'src/commands/updateEverythingCommand';
import { $config } from 'src/extension';
import { vscodeUtils } from 'src/utils/vscodeUtils';
import { commands, type ExtensionContext } from 'vscode';
Expand Down Expand Up @@ -39,6 +40,8 @@ export const enum CommandId {
SearchForProblem = 'errorLens.searchForProblem',
/** {@link disableLineCommand} */
DisableLine = 'errorLens.disableLine',
/** {@link updateEverythingCommand} */
UpdateEverything = 'errorLens.updateEverything',
// ──── Internal ──────────────────────────────────────────────
/** {@link statusBarCommand} */
StatusBarCommand = 'errorLens.statusBarCommand',
Expand Down Expand Up @@ -81,6 +84,7 @@ export function registerAllCommands(context: ExtensionContext): void {
context.subscriptions.push(commands.registerCommand(CommandId.SearchForProblem, searchForProblemCommand));
context.subscriptions.push(commands.registerCommand(CommandId.DisableLine, disableLineCommand));
context.subscriptions.push(commands.registerCommand(CommandId.CopyProblemMessage, copyProblemMessageCommand));
context.subscriptions.push(commands.registerCommand(CommandId.UpdateEverything, updateEverythingCommand));
// ────────────────────────────────────────────────────────────
// ──── Text Editor commands ──────────────────────────────────
// ────────────────────────────────────────────────────────────
Expand Down
24 changes: 24 additions & 0 deletions src/commands/updateEverythingCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { clearDecorations, updateDecorationsForUri } from 'src/decorations';
import { $state } from 'src/extension';
import { extUtils } from 'src/utils/extUtils';
import { languages, window } from 'vscode';

interface UpdateEverythingArgs {
kind?: 'update' | 'clear';
}

export function updateEverythingCommand(arg?: UpdateEverythingArgs): void {
for (const editor of window.visibleTextEditors) {
if (arg?.kind === 'clear') {
clearDecorations({ editor });
} else {
updateDecorationsForUri({
uri: editor.document.uri,
editor,
});
$state.statusBarMessage.updateText(editor, extUtils.groupDiagnosticsByLine(languages.getDiagnostics(editor.document.uri)));
}
}

$state.statusBarIcons.updateText();
}
1 change: 1 addition & 0 deletions src/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ function doUpdateDecorations({
}

export function updateDecorationsForAllVisibleEditors(): void {
// TODO: maybe this condition should not be here
if (
$config.onSave &&
!$config.onSaveUpdateOnActiveEditorChange
Expand Down

0 comments on commit 6869ea1

Please sign in to comment.