Skip to content

Commit

Permalink
feat: workaround jumpy gutter icons #177
Browse files Browse the repository at this point in the history
  • Loading branch information
usernamehw committed Jul 19, 2023
1 parent 8c3caab commit 33afd3d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
31 changes: 29 additions & 2 deletions src/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { createHoverForDiagnostic } from 'src/hover/hover';
import { Constants } from 'src/types';
import { extUtils, type GroupedByLineDiagnostics } from 'src/utils/extUtils';
import { utils } from 'src/utils/utils';
import { Range, ThemeColor, languages, window, workspace, type DecorationInstanceRenderOptions, type DecorationOptions, type DecorationRenderOptions, type ExtensionContext, type TextEditor, type TextEditorDecorationType, type ThemableDecorationAttachmentRenderOptions, type Uri } from 'vscode';
import { Range, ThemeColor, debug, languages, window, workspace, type DecorationInstanceRenderOptions, type DecorationOptions, type DecorationRenderOptions, type ExtensionContext, type Location, type TextEditor, type TextEditorDecorationType, type ThemableDecorationAttachmentRenderOptions, type Uri } from 'vscode';

type DecorationKeys = 'decorationTypeError' | 'decorationTypeGutterError' | 'decorationTypeGutterHint' | 'decorationTypeGutterInfo' | 'decorationTypeGutterWarning' | 'decorationTypeHint' | 'decorationTypeInfo' | 'decorationTypeWarning';
type DecorationKeys = 'decorationTypeError' | 'decorationTypeGutterError' | 'decorationTypeGutterHint' | 'decorationTypeGutterInfo' | 'decorationTypeGutterWarning' | 'decorationTypeHint' | 'decorationTypeInfo' | 'decorationTypeWarning' | 'transparent1x1Icon';
export const decorationTypes = {} as unknown as Record<DecorationKeys, TextEditorDecorationType>;

/**
Expand Down Expand Up @@ -236,6 +236,14 @@ export function setDecorationStyle(context: ExtensionContext): void {
decorationTypes.decorationTypeInfo = window.createTextEditorDecorationType(decorationRenderOptionsInfo);
decorationTypes.decorationTypeHint = window.createTextEditorDecorationType(decorationRenderOptionsHint);

const transparentGutterIcon: DecorationRenderOptions = {
gutterIconPath: gutter?.transparent1x1Icon,
light: {
gutterIconPath: gutter?.transparent1x1Icon,
},
};
decorationTypes.transparent1x1Icon = window.createTextEditorDecorationType(transparentGutterIcon);

$state.statusBarMessage.statusBarColors = [statusBarErrorForeground, statusBarWarningForeground, statusBarInfoForeground, statusBarHintForeground];
}
/**
Expand Down Expand Up @@ -362,6 +370,10 @@ export function doUpdateDecorations(editor: TextEditor, groupedDiagnostics: Grou
}
}

if ($config.gutterIconsEnabled) {
updateWorkaroundGutterIcon(editor);
}

editor.setDecorations(decorationTypes.decorationTypeError, decorationOptionsError);
editor.setDecorations(decorationTypes.decorationTypeWarning, decorationOptionsWarning);
editor.setDecorations(decorationTypes.decorationTypeInfo, decorationOptionsInfo);
Expand Down Expand Up @@ -444,6 +456,21 @@ export function updateDecorationsForUri({

doUpdateDecorations(editor, groupedDiagnostics ?? extUtils.groupDiagnosticsByLine(languages.getDiagnostics(uri)), range);
}
/**
* Issue https://github.com/usernamehw/vscode-error-lens/issues/177
*/
export function updateWorkaroundGutterIcon(editor: TextEditor): void {
const ranges: Range[] = [];
for (const breakpoint of debug.breakpoints) {
// @ts-expect-error location is probably optional, but can be there
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const location: Location = breakpoint?.location;
if (location && location.uri.toString(true) === editor?.document.uri.toString(true)) {
ranges.push(location.range);
}
}
editor.setDecorations(decorationTypes.transparent1x1Icon, ranges);
}

export function disposeAllDecorations(): void {
for (const decorationType of Object.values(decorationTypes)) {
Expand Down
16 changes: 14 additions & 2 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomDelay } from 'src/CustomDelay';
import { updateDecorationsForAllVisibleEditors, updateDecorationsForUri } from 'src/decorations';
import { updateDecorationsForAllVisibleEditors, updateDecorationsForUri, updateWorkaroundGutterIcon } from 'src/decorations';
import { $config, $state } from 'src/extension';
import { TextDocumentSaveReason, languages, window, workspace, type DiagnosticChangeEvent } from 'vscode';
import { TextDocumentSaveReason, debug, languages, window, workspace, type DiagnosticChangeEvent } from 'vscode';

/**
* Update listener for when active editor changes.
Expand Down Expand Up @@ -119,3 +119,15 @@ export function updateOnSaveListener(): void {
}
});
}

export function updateChangeBreakpointsListener(): void {
$state.onDidChangeBreakpoints?.dispose();

if ($config.gutterIconsEnabled) {
$state.onDidChangeBreakpoints = debug.onDidChangeBreakpoints(() => {
for (const editor of window.visibleTextEditors) {
updateWorkaroundGutterIcon(editor);
}
});
}
}
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerAllCommands } from 'src/commands';
import { type CustomDelay } from 'src/CustomDelay';
import { disposeAllDecorations, setDecorationStyle, updateDecorationsForAllVisibleEditors } from 'src/decorations';
import { updateChangedActiveTextEditorListener, updateChangeDiagnosticListener, updateChangeVisibleTextEditorsListener, updateCursorChangeListener, updateOnSaveListener } from 'src/events';
import { updateChangeBreakpointsListener, updateChangedActiveTextEditorListener, updateChangeDiagnosticListener, updateChangeVisibleTextEditorsListener, updateCursorChangeListener, updateOnSaveListener } from 'src/events';
import { StatusBarIcons } from 'src/statusBar/statusBarIcons';
import { StatusBarMessage } from 'src/statusBar/statusBarMessage';
import { Constants, type ExtensionConfig } from 'src/types';
Expand All @@ -27,6 +27,7 @@ export abstract class $state {
public static onDidChangeVisibleTextEditors: Disposable | undefined;
public static onDidSaveTextDocumentDisposable: Disposable | undefined;
public static onDidCursorChangeDisposable: Disposable | undefined;
public static onDidChangeBreakpoints: Disposable | undefined;
/**
* Status bar object. Handles all status bar stuff (for text message)
*/
Expand Down Expand Up @@ -152,6 +153,7 @@ export function updateEverything(context: ExtensionContext): void {
updateOnSaveListener();
updateCursorChangeListener();
updateChangedActiveTextEditorListener();
updateChangeBreakpointsListener();
}
/**
* - Create `RegExp` from string for messages.
Expand Down Expand Up @@ -212,6 +214,7 @@ export function disposeEverything(): void {
$state.onDidChangeActiveTextEditor?.dispose();
$state.onDidSaveTextDocumentDisposable?.dispose();
$state.onDidCursorChangeDisposable?.dispose();
$state.onDidChangeBreakpoints?.dispose();
$state.statusBarMessage?.dispose();
$state.statusBarIcons?.dispose();
disposeAllDecorations();
Expand Down
6 changes: 5 additions & 1 deletion src/gutter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { $config } from 'src/extension';
import { type ExtensionConfig } from 'src/types';
import { extUtils, type GroupedByLineDiagnostics } from 'src/utils/extUtils';
import { vscodeUtils } from 'src/utils/vscodeUtils';
import { type DecorationOptions, type ExtensionContext, type TextEditor, type Uri } from 'vscode';
import { type DecorationOptions, type ExtensionContext, type TextEditor, Uri } from 'vscode';

export interface Gutter {
iconSet: ExtensionConfig['gutterIconSet'];
Expand All @@ -19,6 +19,8 @@ export interface Gutter {

hintIconPath: Uri | string | undefined;
hintIconPathLight: Uri | string | undefined;

transparent1x1Icon: Uri | string;
}

/**
Expand Down Expand Up @@ -109,6 +111,8 @@ export function getGutterStyles(extensionContext: ExtensionContext): Gutter {
hintIconPath: gutter.hintIconPath,
hintIconPathLight: gutter.hintIconPathLight,
iconSet: gutter.iconSet,

transparent1x1Icon: Uri.parse('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='),
};
}

Expand Down

0 comments on commit 33afd3d

Please sign in to comment.