File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -398,13 +398,9 @@ function format(msg: p.RequestMessage): Array<m.Message> {
398
398
extension === c . resiExt
399
399
) ;
400
400
if ( formattedResult . kind === "success" ) {
401
- let max = formattedResult . result . length ;
402
401
let result : p . TextEdit [ ] = [
403
402
{
404
- range : {
405
- start : { line : 0 , character : 0 } ,
406
- end : { line : max , character : max } ,
407
- } ,
403
+ range : utils . getSourceRange ( code ) ,
408
404
newText : formattedResult . result ,
409
405
} ,
410
406
] ;
Original file line number Diff line number Diff line change @@ -476,3 +476,23 @@ export let parseCompilerLogOutput = (
476
476
477
477
return { done, result } ;
478
478
} ;
479
+
480
+ export let getSourceRange = ( source : string ) : p . Range => {
481
+ let start = { line : 0 , character : 0 } ;
482
+
483
+ // Calculate end position
484
+ let len = source . length ;
485
+ let line = 1 ;
486
+ let colStartIndex = 0 ;
487
+
488
+ for ( let i = 0 ; i < len ; i ++ ) {
489
+ if ( source [ i ] === "\n" ) {
490
+ line ++ ;
491
+ colStartIndex = i + 1 ;
492
+ }
493
+ }
494
+
495
+ let end = { line : line , character : len - colStartIndex } ;
496
+
497
+ return { start, end } ;
498
+ } ;
You can’t perform that action at this time.
0 commit comments