5
5
6
6
import * as assert from 'assert' ;
7
7
import { suite , test } from 'vitest' ;
8
+ import { DiagnosticData } from '../../../../platform/inlineEdits/common/dataTypes/diagnosticData' ;
9
+ import { URI } from '../../../../util/vs/base/common/uri' ;
8
10
import { StringEdit } from '../../../../util/vs/editor/common/core/edits/stringEdit' ;
9
- import { Range } from '../../../../util/vs/editor/common/core/range' ;
10
11
import { OffsetRange } from '../../../../util/vs/editor/common/core/ranges/offsetRange' ;
11
12
import { StringText } from '../../../../util/vs/editor/common/core/text/abstractText' ;
12
- import { Diagnostic , DiagnosticSeverity } from '../../vscode-node/features/diagnosticsBasedCompletions/diagnosticsCompletions' ;
13
+ import { Diagnostic } from '../../vscode-node/features/diagnosticsBasedCompletions/diagnosticsCompletions' ;
13
14
import { DiagnosticsCollection } from '../../vscode-node/features/diagnosticsCompletionProcessor' ;
14
15
15
- // Helper function to create a mock VS Code diagnostic
16
- function createMockVSCodeDiagnostic (
17
- message : string ,
18
- range : Range ,
19
- severity : number = 0 ,
20
- source ?: string ,
21
- code ?: string | number
22
- ) : any {
23
- return {
24
- message,
25
- range : {
26
- start : { line : range . startLineNumber - 1 , character : range . startColumn - 1 } ,
27
- end : { line : range . endLineNumber - 1 , character : range . endColumn - 1 }
28
- } ,
29
- severity,
30
- source,
31
- code
32
- } ;
33
- }
34
-
35
16
// Helper function to create a Diagnostic from a mock VS Code diagnostic
36
- function createDiagnostic (
37
- message : string ,
38
- range : Range ,
39
- severity : DiagnosticSeverity = DiagnosticSeverity . Error ,
40
- source ?: string ,
41
- code ?: string | number
42
- ) : Diagnostic {
43
- const mockVSCodeDiagnostic = createMockVSCodeDiagnostic ( message , range , severity , source , code ) ;
44
- return Diagnostic . fromVSCodeDiagnostic ( mockVSCodeDiagnostic ) ;
17
+ function createDiagnostic ( message : string , range : OffsetRange ) : Diagnostic {
18
+ return new Diagnostic ( new DiagnosticData (
19
+ URI . parse ( 'file:///test/document.ts' ) ,
20
+ message ,
21
+ 'error' ,
22
+ range ,
23
+ undefined ,
24
+ undefined
25
+ ) ) ;
45
26
}
46
27
47
28
suite ( 'DiagnosticsCollection' , ( ) => {
@@ -54,7 +35,7 @@ suite('DiagnosticsCollection', () => {
54
35
const collection = new DiagnosticsCollection ( ) ;
55
36
const diagnostic = createDiagnostic (
56
37
'Test error' ,
57
- new Range ( 1 , 1 , 1 , 5 )
38
+ new OffsetRange ( 0 , 4 )
58
39
) ;
59
40
60
41
const result = collection . isEqualAndUpdate ( [ diagnostic ] ) ;
@@ -63,8 +44,8 @@ suite('DiagnosticsCollection', () => {
63
44
} ) ;
64
45
test ( 'isEqualAndUpdate should return true when diagnostics are equal' , ( ) => {
65
46
const collection = new DiagnosticsCollection ( ) ;
66
- const diagnostic1 = createDiagnostic ( 'Test error' , new Range ( 1 , 1 , 1 , 5 ) ) ;
67
- const diagnostic2 = createDiagnostic ( 'Test error' , new Range ( 1 , 1 , 1 , 5 ) ) ;
47
+ const diagnostic1 = createDiagnostic ( 'Test error' , new OffsetRange ( 0 , 4 ) ) ;
48
+ const diagnostic2 = createDiagnostic ( 'Test error' , new OffsetRange ( 0 , 4 ) ) ;
68
49
69
50
collection . isEqualAndUpdate ( [ diagnostic1 ] ) ;
70
51
const result = collection . isEqualAndUpdate ( [ diagnostic2 ] ) ;
@@ -73,8 +54,8 @@ suite('DiagnosticsCollection', () => {
73
54
} ) ;
74
55
test ( 'isEqualAndUpdate should return false when a diagnostics is invalidated' , ( ) => {
75
56
const collection = new DiagnosticsCollection ( ) ;
76
- const diagnostic1 = createDiagnostic ( 'Test error' , new Range ( 1 , 1 , 1 , 5 ) ) ;
77
- const diagnostic2 = createDiagnostic ( 'Test error' , new Range ( 1 , 1 , 1 , 5 ) ) ;
57
+ const diagnostic1 = createDiagnostic ( 'Test error' , new OffsetRange ( 0 , 4 ) ) ;
58
+ const diagnostic2 = createDiagnostic ( 'Test error' , new OffsetRange ( 0 , 4 ) ) ;
78
59
79
60
collection . isEqualAndUpdate ( [ diagnostic1 ] ) ;
80
61
@@ -88,12 +69,12 @@ suite('DiagnosticsCollection', () => {
88
69
suite ( 'applyEdit' , ( ) => {
89
70
test ( 'should invalidate when typing numbers at the end of a diagnostic range' , ( ) => {
90
71
const collection = new DiagnosticsCollection ( ) ;
91
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
72
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 17 ) ) ; // "test" = positions 12-15 (0 -based)
92
73
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
93
74
94
75
// Replace "test" with "test123"
95
76
const before = new StringText ( 'hello world test' ) ;
96
- const edit = StringEdit . replace ( new OffsetRange ( 12 , 16 ) , 'test123' ) ; // 0-based: 12-15
77
+ const edit = StringEdit . replace ( new OffsetRange ( 12 , 17 ) , 'test123' ) ; // 0-based: 12-16
97
78
const after = edit . applyOnText ( before ) ;
98
79
99
80
const hasInvalidated = collection . applyEdit ( before , edit , after ) ;
@@ -103,7 +84,7 @@ suite('DiagnosticsCollection', () => {
103
84
104
85
test ( 'should invalidate diagnostic when range shrinks' , ( ) => {
105
86
const collection = new DiagnosticsCollection ( ) ;
106
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 7 , 1 , 12 ) ) ; // "world"
87
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 6 , 11 ) ) ; // "world"
107
88
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
108
89
109
90
// Create an edit that removes "w"
@@ -119,7 +100,7 @@ suite('DiagnosticsCollection', () => {
119
100
120
101
test ( 'should update range when content stays the same and range length unchanged' , ( ) => {
121
102
const collection = new DiagnosticsCollection ( ) ;
122
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ;
103
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ;
123
104
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
124
105
125
106
// Insert " big" without touching the diagnostic range
@@ -135,7 +116,7 @@ suite('DiagnosticsCollection', () => {
135
116
136
117
test ( 'should invalidate diagnostic when content at range changes with same length' , ( ) => {
137
118
const collection = new DiagnosticsCollection ( ) ;
138
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test"
119
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test"
139
120
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
140
121
141
122
// Replace "test" with "best"
@@ -150,7 +131,7 @@ suite('DiagnosticsCollection', () => {
150
131
} ) ;
151
132
test ( 'should handle range growth with same prefix content' , ( ) => {
152
133
const collection = new DiagnosticsCollection ( ) ;
153
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ;
134
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ;
154
135
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
155
136
156
137
// "test" becomes "test!" (non-alphanumeric edge)
@@ -164,13 +145,13 @@ suite('DiagnosticsCollection', () => {
164
145
assert . strictEqual ( diagnostic . isValid ( ) , true ) ;
165
146
166
147
// Range should still point to the original "test" part
167
- assert . strictEqual ( diagnostic . range . startColumn , 13 ) ;
168
- assert . strictEqual ( diagnostic . range . endColumn , 17 ) ;
148
+ assert . strictEqual ( diagnostic . range . start , 12 ) ;
149
+ assert . strictEqual ( diagnostic . range . endExclusive , 16 ) ;
169
150
} ) ;
170
151
171
152
test ( 'should handle range growth with same suffix content' , ( ) => {
172
153
const collection = new DiagnosticsCollection ( ) ;
173
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test"
154
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test"
174
155
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
175
156
176
157
const before = new StringText ( 'hello world test' ) ;
@@ -179,16 +160,13 @@ suite('DiagnosticsCollection', () => {
179
160
180
161
const hasInvalidated = collection . applyEdit ( before , edit , after ) ;
181
162
182
- assert . strictEqual ( hasInvalidated , false ) ;
183
- assert . strictEqual ( diagnostic . isValid ( ) , true ) ;
184
- // Range should point to the suffix "test" part
185
- assert . strictEqual ( diagnostic . range . startColumn , 15 ) ; // 13 + 2 ("ab")
186
- assert . strictEqual ( diagnostic . range . endColumn , 19 ) ; // 17 + 2 ("ab")
163
+ assert . strictEqual ( hasInvalidated , true ) ;
164
+ assert . strictEqual ( diagnostic . isValid ( ) , false ) ;
187
165
} ) ;
188
166
189
167
test ( 'should invalidate when edge character is alphanumeric with prefix match' , ( ) => {
190
168
const collection = new DiagnosticsCollection ( ) ;
191
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test"
169
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test"
192
170
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
193
171
194
172
const before = new StringText ( 'hello world test' ) ;
@@ -205,14 +183,13 @@ suite('DiagnosticsCollection', () => {
205
183
206
184
test ( 'should not invalidate when edge character is non-alphanumeric with prefix match' , ( ) => {
207
185
const collection = new DiagnosticsCollection ( ) ;
208
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
186
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test" = positions 12-15 (0 -based)
209
187
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
210
188
211
- const before = new StringText ( 'hello world test' ) ;
212
- const after = new StringText ( 'hello world test!' ) ; // "test" becomes "test!" (non-alphanumeric edge)
213
-
214
189
// Replace "test" with "test!"
190
+ const before = new StringText ( 'hello world test' ) ;
215
191
const edit = StringEdit . replace ( new OffsetRange ( 12 , 16 ) , 'test!' ) ; // 0-based: 12-15
192
+ const after = edit . applyOnText ( before ) ;
216
193
217
194
const hasInvalidated = collection . applyEdit ( before , edit , after ) ;
218
195
@@ -222,15 +199,13 @@ suite('DiagnosticsCollection', () => {
222
199
223
200
test ( 'should handle multiple diagnostics correctly' , ( ) => {
224
201
const collection = new DiagnosticsCollection ( ) ;
225
- const diagnostic1 = createDiagnostic ( 'Error 1' , new Range ( 1 , 1 , 1 , 6 ) ) ; // "hello" = positions 0-4 (1 -based: 1-5), but using 6 for end
226
- const diagnostic2 = createDiagnostic ( 'Error 2' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
202
+ const diagnostic1 = createDiagnostic ( 'Error 1' , new OffsetRange ( 0 , 5 ) ) ; // "hello" = positions 0-4 (0 -based)
203
+ const diagnostic2 = createDiagnostic ( 'Error 2' , new OffsetRange ( 12 , 16 ) ) ; // "test" = positions 12-15 (0 -based)
227
204
collection . isEqualAndUpdate ( [ diagnostic1 , diagnostic2 ] ) ;
228
205
229
206
const before = new StringText ( 'hello world test' ) ;
230
- const after = new StringText ( 'hello big world test' ) ;
231
-
232
- // Insert "big " at position 6 (0-based)
233
207
const edit = StringEdit . replace ( new OffsetRange ( 6 , 6 ) , 'big ' ) ;
208
+ const after = edit . applyOnText ( before ) ;
234
209
235
210
const hasInvalidated = collection . applyEdit ( before , edit , after ) ;
236
211
@@ -239,17 +214,17 @@ suite('DiagnosticsCollection', () => {
239
214
assert . strictEqual ( diagnostic2 . isValid ( ) , true ) ;
240
215
241
216
// First diagnostic range should be unchanged
242
- assert . strictEqual ( diagnostic1 . range . startColumn , 1 ) ;
243
- assert . strictEqual ( diagnostic1 . range . endColumn , 6 ) ;
217
+ assert . strictEqual ( diagnostic1 . range . start , 0 ) ;
218
+ assert . strictEqual ( diagnostic1 . range . endExclusive , 5 ) ;
244
219
245
220
// Second diagnostic range should be shifted by 4 positions ("big ")
246
- assert . strictEqual ( diagnostic2 . range . startColumn , 17 ) ; // 13 + 4
247
- assert . strictEqual ( diagnostic2 . range . endColumn , 21 ) ; // 17 + 4
221
+ assert . strictEqual ( diagnostic2 . range . start , 16 ) ;
222
+ assert . strictEqual ( diagnostic2 . range . endExclusive , 20 ) ;
248
223
} ) ;
249
224
250
225
test ( 'should handle edge case with empty edge character' , ( ) => {
251
226
const collection = new DiagnosticsCollection ( ) ;
252
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
227
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test" = positions 12-15 (0 -based)
253
228
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
254
229
255
230
const before = new StringText ( 'hello world test' ) ;
@@ -267,7 +242,7 @@ suite('DiagnosticsCollection', () => {
267
242
268
243
test ( 'should handle suffix match with non-alphanumeric edge character' , ( ) => {
269
244
const collection = new DiagnosticsCollection ( ) ;
270
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
245
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test" = positions 12-15 (0 -based)
271
246
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
272
247
273
248
const before = new StringText ( 'hello world test' ) ;
@@ -281,13 +256,13 @@ suite('DiagnosticsCollection', () => {
281
256
assert . strictEqual ( hasInvalidated , false ) ;
282
257
assert . strictEqual ( diagnostic . isValid ( ) , true ) ;
283
258
// Range should point to the suffix "test" part
284
- assert . strictEqual ( diagnostic . range . startColumn , 14 ) ; // 13 + 1 (".")
285
- assert . strictEqual ( diagnostic . range . endColumn , 18 ) ; // 17 + 1 (".")
259
+ assert . strictEqual ( diagnostic . range . start , 13 ) ;
260
+ assert . strictEqual ( diagnostic . range . endExclusive , 17 ) ; // 17 + 1 (".")
286
261
} ) ;
287
262
288
263
test ( 'should handle case where newOffsetRange is null' , ( ) => {
289
264
const collection = new DiagnosticsCollection ( ) ;
290
- const diagnostic = createDiagnostic ( 'Test error' , new Range ( 1 , 13 , 1 , 17 ) ) ; // "test" = positions 12-15 (1 -based: 13-17 )
265
+ const diagnostic = createDiagnostic ( 'Test error' , new OffsetRange ( 12 , 16 ) ) ; // "test" = positions 12-15 (0 -based)
291
266
collection . isEqualAndUpdate ( [ diagnostic ] ) ;
292
267
293
268
// Mock applyEditsToRanges to return null (would happen if range is completely removed)
0 commit comments