@@ -3,9 +3,12 @@ import { Global, Config, Loader, CurrentFile } from '../core'
33import { ExtensionModule } from '../modules'
44import { createHover } from './hover'
55
6- const noneDecorationType = window . createTextEditorDecorationType ( { } )
7-
86const localeAnnotation : ExtensionModule = ( ctx ) => {
7+ const noneDecorationType = window . createTextEditorDecorationType ( { } )
8+ const missingDecorationType = window . createTextEditorDecorationType ( {
9+ gutterIconPath : ctx . asAbsolutePath ( 'res/dark/info.svg' ) ,
10+ } )
11+
912 const supportedParsers = Global . parsers . filter ( p => p . annotationSupported )
1013
1114 function update ( ) {
@@ -33,6 +36,8 @@ const localeAnnotation: ExtensionModule = (ctx) => {
3336
3437 const annotationDelimiter = Config . annotationDelimiter
3538 const annotations : DecorationOptions [ ] = [ ]
39+ const annotationsMissing : DecorationOptions [ ] = [ ]
40+
3641 const color = 'rgba(153, 153, 153, .7)'
3742 let displayLanguage = Config . displayLanguage
3843 if ( displayLanguage === file . locale ) {
@@ -45,41 +50,49 @@ const localeAnnotation: ExtensionModule = (ctx) => {
4550 const keys = parser . annotationGetKeys ( document )
4651 // get all keys of current file
4752 keys . forEach ( ( { key, start, end } ) => {
48- if ( Config . annotations ) {
49- let text = ''
50-
51- if ( Config . annotations && displayLanguage ) {
52- const node = loader . getTreeNodeByKey ( key )
53- if ( ! node || node . type === 'tree' )
54- return
55- text = node . getValue ( displayLanguage )
56-
57- if ( text ) {
58- if ( maxLength && text . length > maxLength )
59- text = `${ text . substring ( 0 , maxLength ) } …`
60- text = `${ annotationDelimiter } ${ text } `
61- }
62- }
63-
64- annotations . push ( {
65- range : new Range (
66- document . positionAt ( start ) ,
67- document . positionAt ( end ) ,
68- ) ,
69- renderOptions : {
70- after : {
71- color,
72- contentText : text ,
73- fontWeight : 'normal' ,
74- fontStyle : 'normal' ,
75- } ,
53+ let sourceText = ''
54+ let currentText = ''
55+
56+ const node = loader . getTreeNodeByKey ( key )
57+ const showAnnonations = Config . annotations && displayLanguage
58+
59+ if ( node ) {
60+ if ( node . type !== 'node' )
61+ return
62+ sourceText = node . getValue ( displayLanguage )
63+ currentText = node . getValue ( file . locale || Config . sourceLanguage )
64+ }
65+
66+ if ( sourceText ) {
67+ if ( maxLength && sourceText . length > maxLength )
68+ sourceText = `${ sourceText . substring ( 0 , maxLength ) } …`
69+ sourceText = `${ annotationDelimiter } ${ sourceText } `
70+ }
71+
72+ const annotation : DecorationOptions = {
73+ range : new Range (
74+ document . positionAt ( start ) ,
75+ document . positionAt ( end ) ,
76+ ) ,
77+ renderOptions : {
78+ after : {
79+ color,
80+ contentText : showAnnonations ? sourceText : undefined ,
81+ fontWeight : 'normal' ,
82+ fontStyle : 'normal' ,
7683 } ,
77- hoverMessage : createHover ( key , maxLength ) ,
78- } )
84+ } ,
85+ hoverMessage : createHover ( key , maxLength ) ,
7986 }
87+
88+ if ( currentText )
89+ annotations . push ( annotation )
90+ else
91+ annotationsMissing . push ( annotation )
8092 } )
8193
8294 activeTextEditor . setDecorations ( noneDecorationType , annotations )
95+ activeTextEditor . setDecorations ( missingDecorationType , annotationsMissing )
8396 }
8497
8598 const disposables : Disposable [ ] = [ ]
0 commit comments