@@ -7,6 +7,7 @@ import { findAll, indexToPosition } from './util/find'
7
7
import { getTextWithoutComments } from './util/doc'
8
8
import { absoluteRange } from './util/absoluteRange'
9
9
import * as semver from './util/semver'
10
+ import { getCssBlocks } from './util/language-blocks'
10
11
11
12
export function getDocumentLinks (
12
13
state : State ,
@@ -38,34 +39,27 @@ function getDirectiveLinks(
38
39
}
39
40
40
41
let links : DocumentLink [ ] = [ ]
41
- let ranges : Range [ ] = [ ]
42
42
43
- if ( isCssDoc ( state , document ) ) {
44
- ranges . push ( undefined )
45
- } else {
46
- let boundaries = getLanguageBoundaries ( state , document )
47
- if ( ! boundaries ) return [ ]
48
- ranges . push ( ...boundaries . filter ( ( b ) => b . type === 'css' ) . map ( ( { range } ) => range ) )
49
- }
43
+ for ( let block of getCssBlocks ( state , document ) ) {
44
+ let text = block . text
50
45
51
- for ( let range of ranges ) {
52
- let text = getTextWithoutComments ( document , 'css' , range )
53
46
let matches : RegExpMatchArray [ ] = [ ]
54
47
55
48
for ( let pattern of patterns ) {
56
49
matches . push ( ...findAll ( pattern , text ) )
57
50
}
58
51
59
52
for ( let match of matches ) {
53
+ let path = match . groups . path . slice ( 1 , - 1 )
54
+
55
+ let range = {
56
+ start : indexToPosition ( text , match . index + match [ 0 ] . length - match . groups . path . length ) ,
57
+ end : indexToPosition ( text , match . index + match [ 0 ] . length ) ,
58
+ }
59
+
60
60
links . push ( {
61
- target : resolveTarget ( match . groups . path . slice ( 1 , - 1 ) ) ,
62
- range : absoluteRange (
63
- {
64
- start : indexToPosition ( text , match . index + match [ 0 ] . length - match . groups . path . length ) ,
65
- end : indexToPosition ( text , match . index + match [ 0 ] . length ) ,
66
- } ,
67
- range ,
68
- ) ,
61
+ target : resolveTarget ( path ) ,
62
+ range : absoluteRange ( range , block . range ) ,
69
63
} )
70
64
}
71
65
}
0 commit comments