@@ -2,7 +2,7 @@ import type { getReactiveReferences } from '@vue/typescript-plugin/lib/requests/
2
2
import * as vscode from 'vscode' ;
3
3
import { config } from './config' ;
4
4
5
- const dependenciesDecorations = vscode . window . createTextEditorDecorationType ( {
5
+ const dependencyDecorations = vscode . window . createTextEditorDecorationType ( {
6
6
isWholeLine : true ,
7
7
backgroundColor : 'rgba(120,120,255,0.1)' ,
8
8
border : '1px solid rgba(120,120,255,0.6)' ,
@@ -12,7 +12,7 @@ const dependenciesDecorations = vscode.window.createTextEditorDecorationType({
12
12
// color: 'rgba(120,120,255,0.6)',
13
13
// },
14
14
} ) ;
15
- const subscribersDecorations = vscode . window . createTextEditorDecorationType ( {
15
+ const dependentDecorations = vscode . window . createTextEditorDecorationType ( {
16
16
// outlineColor: 'rgba(80,200,80,0.6)',
17
17
// outlineStyle: 'dashed',
18
18
// borderRadius: '3px',
@@ -62,8 +62,8 @@ export function activate(
62
62
return ;
63
63
}
64
64
if ( ! config . editor . reactivityVisualization ) {
65
- editor . setDecorations ( dependenciesDecorations , [ ] ) ;
66
- editor . setDecorations ( subscribersDecorations , [ ] ) ;
65
+ editor . setDecorations ( dependencyDecorations , [ ] ) ;
66
+ editor . setDecorations ( dependentDecorations , [ ] ) ;
67
67
return ;
68
68
}
69
69
@@ -82,27 +82,47 @@ export function activate(
82
82
{ isAsync : true , lowPriority : true } ,
83
83
) ;
84
84
editor . setDecorations (
85
- dependenciesDecorations ,
86
- result ?. body ?. dependencyRanges . map ( range =>
87
- new vscode . Range (
88
- document . positionAt ( range . start ) ,
89
- document . positionAt ( range . end ) ,
90
- )
91
- ) ?? [ ] ,
85
+ dependencyDecorations ,
86
+ getFlatRanges ( document , result ?. body ?. dependencyRanges ?? [ ] ) ,
92
87
) ;
93
88
editor . setDecorations (
94
- subscribersDecorations ,
95
- result ?. body ?. dependentRanges . map ( range =>
96
- new vscode . Range (
97
- document . positionAt ( range . start ) ,
98
- document . positionAt ( range . end ) ,
99
- )
100
- ) ?? [ ] ,
89
+ dependentDecorations ,
90
+ getFlatRanges ( document , result ?. body ?. dependentRanges ?? [ ] ) ,
101
91
) ;
102
92
}
103
93
catch {
104
- editor . setDecorations ( dependenciesDecorations , [ ] ) ;
105
- editor . setDecorations ( subscribersDecorations , [ ] ) ;
94
+ editor . setDecorations ( dependencyDecorations , [ ] ) ;
95
+ editor . setDecorations ( dependentDecorations , [ ] ) ;
106
96
}
107
97
}
108
98
}
99
+
100
+ function getFlatRanges ( document : vscode . TextDocument , ranges : {
101
+ start : number ;
102
+ end : number ;
103
+ } [ ] ) {
104
+ const documentRanges = ranges
105
+ . map ( range =>
106
+ new vscode . Range (
107
+ document . positionAt ( range . start ) ,
108
+ document . positionAt ( range . end ) ,
109
+ )
110
+ )
111
+ . sort ( ( a , b ) => a . start . compareTo ( b . start ) ) ;
112
+
113
+ for ( let i = 1 ; i < documentRanges . length ; i ++ ) {
114
+ const prev = documentRanges [ i - 1 ] ! ;
115
+ const curr = documentRanges [ i ] ! ;
116
+
117
+ if ( prev . end . compareTo ( curr . start ) >= 0 ) {
118
+ if ( curr . end . compareTo ( prev . end ) <= 0 ) {
119
+ documentRanges . splice ( i , 1 ) ;
120
+ }
121
+ else {
122
+ documentRanges . splice ( i - 1 , 2 , new vscode . Range ( prev . start , curr . end ) ) ;
123
+ }
124
+ i -- ;
125
+ }
126
+ }
127
+ return documentRanges ;
128
+ }
0 commit comments