-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor coverage gutter formatter (#585)
e234ae6 feat: add back light theme status decorations 0c930ef refactor: use common functions from decorations e916d74 fix: use prepared svg icon in coverage formatter
- Loading branch information
Showing
16 changed files
with
329 additions
and
202 deletions.
There are no files selected for viewing
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...s/GutterFormatter/covered-gutter-icon.svg → icons/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
src/Coverage/Formatters/GutterFormatter/partially-covered-gutter-icon.svg
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/Coverage/Formatters/GutterFormatter/uncovered-gutter-icon.svg
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
window, | ||
OverviewRulerLane, | ||
DecorationRangeBehavior, | ||
ExtensionContext, | ||
TextEditorDecorationType, | ||
DecorationRenderOptions, | ||
} from 'vscode'; | ||
import passingIcon from 'vscode-codicons/src/icons/check.svg'; | ||
import failingIcon from 'vscode-codicons/src/icons/chrome-close.svg'; | ||
import skipIcon from 'vscode-codicons/src/icons/debug-step-over.svg'; | ||
import unknownIcon from 'vscode-codicons/src/icons/question.svg'; | ||
import prepareIcon from './prepareIcon'; | ||
|
||
export class StateDecorations { | ||
public passing: TextEditorDecorationType; | ||
public failing: TextEditorDecorationType; | ||
public skip: TextEditorDecorationType; | ||
public unknown: TextEditorDecorationType; | ||
|
||
constructor(context: ExtensionContext) { | ||
this.passing = this.createStateDecoration([ | ||
prepareIcon(context, 'passing', passingIcon, '#35A15E'), | ||
'green', | ||
]); | ||
this.failing = this.createStateDecoration([ | ||
prepareIcon(context, 'failing', failingIcon, '#D6443C'), | ||
'red', | ||
]); | ||
this.skip = this.createStateDecoration([ | ||
prepareIcon(context, 'skip', skipIcon, '#fed37f'), | ||
'yellow', | ||
]); | ||
this.unknown = this.createStateDecoration( | ||
[prepareIcon(context, 'unknown', unknownIcon, '#BBBBBB'), 'darkgrey'], | ||
[prepareIcon(context, 'unknown-light', unknownIcon, '#555555')] | ||
); | ||
} | ||
|
||
private createStateDecoration( | ||
dark: /* default */ [string, string?], | ||
light?: /* optional overrides */ [string, string?] | ||
): TextEditorDecorationType { | ||
const [icon, overviewRulerColor] = dark; | ||
|
||
const options: DecorationRenderOptions = { | ||
gutterIconPath: icon, | ||
gutterIconSize: 'contain', | ||
overviewRulerLane: OverviewRulerLane.Left, | ||
rangeBehavior: DecorationRangeBehavior.ClosedClosed, | ||
dark: { | ||
gutterIconPath: icon, | ||
}, | ||
light: { | ||
gutterIconPath: light !== undefined ? light[0] : icon, | ||
}, | ||
}; | ||
|
||
if (overviewRulerColor) { | ||
options['overviewRulerColor'] = overviewRulerColor; | ||
options['dark']['overviewRulerColor'] = overviewRulerColor; | ||
} | ||
|
||
if (light !== undefined && light[1] !== undefined) { | ||
options['light']['overviewRulerColor'] = light[1]; | ||
} | ||
|
||
return window.createTextEditorDecorationType(options); | ||
} | ||
|
||
public failingAssertionStyle(text: string): TextEditorDecorationType { | ||
return window.createTextEditorDecorationType({ | ||
isWholeLine: true, | ||
overviewRulerColor: 'red', | ||
overviewRulerLane: OverviewRulerLane.Left, | ||
light: { | ||
before: { | ||
color: '#FF564B', | ||
}, | ||
after: { | ||
color: '#FF564B', | ||
contentText: ' // ' + text, | ||
}, | ||
}, | ||
dark: { | ||
before: { | ||
color: '#AD322D', | ||
}, | ||
after: { | ||
color: '#AD322D', | ||
contentText: ' // ' + text, | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { ExtensionContext } from 'vscode'; | ||
const ICONS_PATH = path.join('out', 'icons'); | ||
|
||
export default function prepareIcon( | ||
context: ExtensionContext, | ||
state: string, | ||
source: string, | ||
color?: string | ||
): string { | ||
const resolvePath = (...args: string[]): string => { | ||
return context.asAbsolutePath(path.join(...args)); | ||
}; | ||
|
||
const resultIconPath = resolvePath(ICONS_PATH, `${state}.svg`); | ||
let result = source.toString(); | ||
|
||
if (color !== undefined) { | ||
result = result.replace('fill="currentColor"', `fill="${color}"`); | ||
} | ||
|
||
if (!fs.existsSync(resultIconPath) || fs.readFileSync(resultIconPath).toString() !== result) { | ||
if (!fs.existsSync(resolvePath(ICONS_PATH))) { | ||
fs.mkdirSync(resolvePath(ICONS_PATH)); | ||
} | ||
|
||
fs.writeFileSync(resultIconPath, result); | ||
} | ||
|
||
return resultIconPath; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.