@@ -28,66 +28,84 @@ export function create(): LanguageServicePlugin {
28
28
return diagnostics ;
29
29
} ,
30
30
/**
31
- * If the editing position is within the virtual code and navigation is enabled,
32
- * skip the CSS renaming feature.
31
+ * If the position is within the virtual code and navigation is enabled,
32
+ * skip the CSS navigation feature.
33
33
*/
34
+ provideReferences ( document , position ) {
35
+ if ( isWithinNavigationVirtualCode ( document , position ) ) {
36
+ return ;
37
+ }
38
+ return worker ( document , ( stylesheet , cssLs ) => {
39
+ return cssLs . findReferences ( document , position , stylesheet ) ;
40
+ } ) ;
41
+ } ,
34
42
provideRenameRange ( document , position ) {
35
- do {
36
- const uri = URI . parse ( document . uri ) ;
37
- const decoded = context . decodeEmbeddedDocumentUri ( uri ) ;
38
- const sourceScript = decoded && context . language . scripts . get ( decoded [ 0 ] ) ;
39
- const virtualCode = decoded && sourceScript ?. generated ?. embeddedCodes . get ( decoded [ 1 ] ) ;
40
- if ( ! sourceScript ?. generated || ! virtualCode ?. id . startsWith ( 'style_' ) ) {
41
- break ;
42
- }
43
+ if ( isWithinNavigationVirtualCode ( document , position ) ) {
44
+ return ;
45
+ }
46
+ return worker ( document , ( stylesheet , cssLs ) => {
47
+ return cssLs . prepareRename ( document , position , stylesheet ) ;
48
+ } ) ;
49
+ }
50
+ } ;
43
51
44
- const root = sourceScript . generated . root ;
45
- if ( ! ( root instanceof VueVirtualCode ) ) {
46
- break ;
47
- }
52
+ function isWithinNavigationVirtualCode (
53
+ document : TextDocument ,
54
+ position : css . Position
55
+ ) {
56
+ const uri = URI . parse ( document . uri ) ;
57
+ const decoded = context . decodeEmbeddedDocumentUri ( uri ) ;
58
+ const sourceScript = decoded && context . language . scripts . get ( decoded [ 0 ] ) ;
59
+ const virtualCode = decoded && sourceScript ?. generated ?. embeddedCodes . get ( decoded [ 1 ] ) ;
60
+ if ( ! sourceScript ?. generated || ! virtualCode ?. id . startsWith ( 'style_' ) ) {
61
+ return false ;
62
+ }
48
63
49
- const block = root . sfc . styles . find ( style => style . name === decoded ! [ 1 ] ) ;
50
- if ( ! block ) {
51
- break ;
52
- }
64
+ const root = sourceScript . generated . root ;
65
+ if ( ! ( root instanceof VueVirtualCode ) ) {
66
+ return false ;
67
+ }
53
68
54
- let script : VirtualCode | undefined ;
55
- for ( const [ key , value ] of sourceScript . generated . embeddedCodes ) {
56
- if ( key . startsWith ( 'script_' ) ) {
57
- script = value ;
58
- break ;
59
- }
60
- }
61
- if ( ! script ) {
62
- break ;
63
- }
69
+ const block = root . sfc . styles . find ( style => style . name === decoded ! [ 1 ] ) ;
70
+ if ( ! block ) {
71
+ return false ;
72
+ }
64
73
65
- const offset = document . offsetAt ( position ) + block . startTagEnd ;
66
- for ( const { sourceOffsets, lengths, data } of script . mappings ) {
67
- if (
68
- ! sourceOffsets . length
69
- || ! data . navigation
70
- || typeof data . navigation === 'object' && ! data . navigation . shouldRename
71
- ) {
72
- continue ;
73
- }
74
+ let script : VirtualCode | undefined ;
75
+ for ( const [ key , value ] of sourceScript . generated . embeddedCodes ) {
76
+ if ( key . startsWith ( 'script_' ) ) {
77
+ script = value ;
78
+ break ;
79
+ }
80
+ }
81
+ if ( ! script ) {
82
+ return false ;
83
+ }
74
84
75
- const start = sourceOffsets [ 0 ] ;
76
- const end = sourceOffsets . at ( - 1 ) ! + lengths . at ( - 1 ) ! ;
85
+ const offset = document . offsetAt ( position ) + block . startTagEnd ;
86
+ for ( const { sourceOffsets, lengths, data } of script . mappings ) {
87
+ if (
88
+ ! sourceOffsets . length
89
+ || ! data . navigation
90
+ || typeof data . navigation === 'object' && ! data . navigation . shouldRename
91
+ ) {
92
+ continue ;
93
+ }
77
94
78
- if ( offset >= start && offset <= end ) {
79
- return ;
80
- }
81
- }
82
- } while ( 0 ) ;
95
+ const start = sourceOffsets [ 0 ] ;
96
+ const end = sourceOffsets . at ( - 1 ) ! + lengths . at ( - 1 ) ! ;
83
97
84
- return worker ( document , ( stylesheet , cssLs ) => {
85
- return cssLs . prepareRename ( document , position , stylesheet ) ;
86
- } ) ;
98
+ if ( offset >= start && offset <= end ) {
99
+ return true ;
100
+ }
87
101
}
88
- } ;
102
+ return false ;
103
+ }
89
104
90
- function worker < T > ( document : TextDocument , callback : ( stylesheet : css . Stylesheet , cssLs : css . LanguageService ) => T ) {
105
+ function worker < T > (
106
+ document : TextDocument ,
107
+ callback : ( stylesheet : css . Stylesheet , cssLs : css . LanguageService ) => T
108
+ ) {
91
109
const cssLs = getCssLs ( document ) ;
92
110
if ( ! cssLs ) {
93
111
return ;
0 commit comments