@@ -173,15 +173,51 @@ const getTextFromChildren = (root: Node): string => {
173
173
return text ;
174
174
} ;
175
175
176
+ function getPropertiesInfoFromYAML ( yamlText : string ) : {
177
+ [ key : string ] : { key : string ; value : string ; text : string ; line : number } ;
178
+ } {
179
+ const yamlProps = yamlText
180
+ . split ( / ( \w + : ) / g)
181
+ . filter ( item => item . trim ( ) !== '' ) ;
182
+ const lines = yamlText . split ( '\n' ) ;
183
+ let result : { line : number ; key : string ; text : string ; value : string } [ ] = [ ] ;
184
+ for ( let i = 0 ; i < yamlProps . length / 2 ; i ++ ) {
185
+ const key = yamlProps [ i * 2 ] . replace ( ':' , '' ) ;
186
+ const value = yamlProps [ i * 2 + 1 ] . trim ( ) ;
187
+ const text = yamlProps [ i * 2 ] + yamlProps [ i * 2 + 1 ] ;
188
+ result . push ( { key, value, text, line : - 1 } ) ;
189
+ }
190
+ result = result . map ( p => {
191
+ const line = lines . findIndex ( l => l . startsWith ( p . key + ':' ) ) ;
192
+ return { ...p , line } ;
193
+ } ) ;
194
+ return result . reduce ( ( acc , curr ) => {
195
+ acc [ curr . key ] = curr ;
196
+ return acc ;
197
+ } , { } ) ;
198
+ }
199
+
176
200
const tagsPlugin : ParserPlugin = {
177
201
name : 'tags' ,
178
202
onDidFindProperties : ( props , note , node ) => {
179
203
if ( isSome ( props . tags ) ) {
204
+ const tagPropertyInfo = getPropertiesInfoFromYAML ( ( node as any ) . value ) [
205
+ 'tags'
206
+ ] ;
207
+ const tagPropertyStartLine =
208
+ node . position ! . start . line + tagPropertyInfo . line ;
209
+ const tagPropertyLines = tagPropertyInfo . text . split ( '\n' ) ;
180
210
const yamlTags = extractTagsFromProp ( props . tags ) ;
181
211
for ( const tag of yamlTags ) {
212
+ const tagLine = tagPropertyLines . findIndex ( l => l . includes ( tag ) ) ;
213
+ const line = tagPropertyStartLine + tagLine ;
214
+ const charStart = tagPropertyLines [ tagLine ] . indexOf ( tag ) ;
182
215
note . tags . push ( {
183
216
label : tag ,
184
- range : astPositionToFoamRange ( node . position ! ) ,
217
+ range : Range . createFromPosition (
218
+ Position . create ( line , charStart ) ,
219
+ Position . create ( line , charStart + tag . length )
220
+ ) ,
185
221
} ) ;
186
222
}
187
223
}
0 commit comments