@@ -8,7 +8,7 @@ import * as path from 'path';
88import * as fs from 'fs' ;
99import * as child_process from 'child_process' ;
1010import * as settings from './configSettings' ;
11- import { CancellationToken } from 'vscode' ;
11+ import { CancellationToken , TextDocument , Range , Position } from 'vscode' ;
1212import { isNotInstalledError } from './helpers' ;
1313import { mergeEnvVariables , parseEnvFile } from './envFileParser' ;
1414
@@ -303,16 +303,19 @@ export function getCustomEnvVars(): any {
303303 return null ;
304304}
305305
306- export function getWindowsLineEndingCount ( text : String , offset :Number ) {
307- const eolPattern = new RegExp ( '\r' , 'g' ) ;
306+ export function getWindowsLineEndingCount ( document : TextDocument , offset :Number ) {
307+ const eolPattern = new RegExp ( '\r\n ' , 'g' ) ;
308308 const readBlock = 1024 ;
309309 let count = 0 ;
310310
311311 // In order to prevent the one-time loading of large files from taking up too much memory
312312 for ( let pos = 0 ; pos < offset ; pos += readBlock ) {
313- let partialText = text . slice ( pos , pos + readBlock ) ;
314- let cr = partialText . match ( eolPattern ) ;
313+ let startAt = document . positionAt ( pos )
314+ let endAt = document . positionAt ( pos + readBlock ) ;
315315
316+ let text = document . getText ( new Range ( startAt , endAt ) ) ;
317+ let cr = text . match ( eolPattern ) ;
318+
316319 count += cr ? cr . length : 0 ;
317320 }
318321 return count ;
0 commit comments