File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
src/extension/inlineEdits/vscode-node/features/diagnosticsBasedCompletions Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -245,13 +245,29 @@ export function isDiagnosticWithinDistance(workspaceDocument: IObservableDocumen
245
245
}
246
246
247
247
export function sortDiagnosticsByDistance ( workspaceDocument : IObservableDocument , diagnostics : Diagnostic [ ] , position : Position ) : Diagnostic [ ] {
248
+ const transformer = workspaceDocument . value . get ( ) . getTransformer ( ) ;
248
249
return diagnostics . sort ( ( a , b ) => {
249
250
const aDistance = diagnosticDistanceToPosition ( workspaceDocument , a , position ) ;
250
251
const bDistance = diagnosticDistanceToPosition ( workspaceDocument , b , position ) ;
251
- if ( aDistance . lineDelta === bDistance . lineDelta ) {
252
+
253
+ if ( aDistance . lineDelta !== bDistance . lineDelta ) {
254
+ return aDistance . lineDelta - bDistance . lineDelta ;
255
+ }
256
+
257
+ const aPosition = transformer . getPosition ( a . range . start ) ;
258
+ const bPosition = transformer . getPosition ( b . range . start ) ;
259
+
260
+ if ( aPosition . lineNumber !== bPosition . lineNumber ) {
252
261
return aDistance . characterDelta - bDistance . characterDelta ;
253
262
}
254
- return aDistance . lineDelta - bDistance . lineDelta ;
263
+
264
+ if ( aDistance . lineDelta < 2 ) {
265
+ return aDistance . characterDelta - bDistance . characterDelta ;
266
+ }
267
+
268
+ // If both diagnostics are on the same line and are more than 1 line away from the cursor
269
+ // always prefer the first diagnostic to minimize recomputation and flickering on cursor move
270
+ return - 1 ;
255
271
} ) ;
256
272
}
257
273
You can’t perform that action at this time.
0 commit comments