Skip to content

Commit 43580f4

Browse files
Leave the declaration positions out of a copied error
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7257b89 commit 43580f4

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎client/src/webview/views/diagnostics/diagnostics.spec.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, describe, expect, it } from 'vitest';
22
import type { CustomError, CustomWarning, StateRefinementError } from '../../../types/diagnostics';
33
import { renderLocation } from '../sections';
4-
import { renderDiagnosticsView } from './diagnostics';
4+
import { formatDiagnosticForClipboard, renderDiagnosticsView } from './diagnostics';
55

66
const currentFile = 'file:///workspace/Current.java';
77
const otherFile = 'file:///workspace/Other.java';
@@ -90,17 +90,21 @@ describe('diagnostics view', () => {
9090
it('shows every declaration of a refinement with their notes under them', () => {
9191
const declaredAt = (lineStart: number) =>
9292
({ file: '/workspace/DoorRefinements.java', lineStart, colStart: 29, lineEnd: lineStart, colEnd: 58 });
93-
document.body.innerHTML = renderLocation({
93+
const stateError = {
9494
...error(), type: 'state-refinement-error', declarationPosition: declaredAt(12),
9595
declarationPositions: [declaredAt(12), declaredAt(13)],
9696
declarationNotes: ['where closed(this) means doorState(this) == closed', 'where ajar(this) means doorState(this) == ajar'],
97-
} as unknown as StateRefinementError);
97+
} as unknown as StateRefinementError;
98+
document.body.innerHTML = renderLocation(stateError);
9899

99100
expect(Array.from(document.querySelectorAll('pre > *')).map(element => element.textContent)).toEqual([
100101
'DoorRefinements.java:13', 'DoorRefinements.java:14',
101102
'where closed(this) means doorState(this) == closed', 'where ajar(this) means doorState(this) == ajar',
102103
]);
103104
expect(document.querySelector('pre > :last-child')?.className).toBe('location-note');
105+
// the copied error keeps the notes but not the raw positions
106+
expect(formatDiagnosticForClipboard(stateError)).toContain('Declaration Notes: where closed(this) means');
107+
expect(formatDiagnosticForClipboard(stateError)).not.toContain('Declaration Positions');
104108
});
105109

106110
it.each([false, true])('keeps warnings in the passed state (showAll=%s)', showAll => {

‎client/src/webview/views/diagnostics/diagnostics.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function copyDiagnosticToClipboard(button: any, displayDiagnostics:
9696
}
9797

9898
export function formatDiagnosticForClipboard(diagnostic: LJDiagnostic): string {
99-
const skippedFields = new Set(['category', 'type', 'translationTable', 'position', 'file', 'declarationPosition', 'stateMachines']);
99+
const skippedFields = new Set(['category', 'type', 'translationTable', 'position', 'file', 'declarationPosition', 'declarationPositions', 'stateMachines']);
100100
const lines: string[] = [];
101101

102102
Object.entries(diagnostic).forEach(([key, value]) => {

0 commit comments

Comments
 (0)