@@ -34,6 +34,7 @@ import { withUndefinedAsNull } from 'vs/base/common/types';
3434import { VSBufferReadableStream , VSBuffer } from 'vs/base/common/buffer' ;
3535import { TokensStore , MultilineTokens , countEOL , MultilineTokens2 , TokensStore2 } from 'vs/editor/common/model/tokensStore' ;
3636import { Color } from 'vs/base/common/color' ;
37+ import { Constants } from 'vs/base/common/uint' ;
3738
3839function createTextBufferBuilder ( ) {
3940 return new PieceTreeTextBufferBuilder ( ) ;
@@ -2341,7 +2342,7 @@ export class TextModel extends Disposable implements model.ITextModel {
23412342 return null ;
23422343 }
23432344
2344- public findEnclosingBrackets ( _position : IPosition ) : [ Range , Range ] | null {
2345+ public findEnclosingBrackets ( _position : IPosition , maxDuration = Constants . MAX_SAFE_SMALL_INTEGER ) : [ Range , Range ] | null {
23452346 const position = this . validatePosition ( _position ) ;
23462347 const lineCount = this . getLineCount ( ) ;
23472348 const savedCounts = new Map < number , number [ ] > ( ) ;
@@ -2385,7 +2386,12 @@ export class TextModel extends Disposable implements model.ITextModel {
23852386
23862387 let languageId : LanguageId = - 1 ;
23872388 let modeBrackets : RichEditBrackets | null = null ;
2389+ const startTime = Date . now ( ) ;
23882390 for ( let lineNumber = position . lineNumber ; lineNumber <= lineCount ; lineNumber ++ ) {
2391+ const elapsedTime = Date . now ( ) - startTime ;
2392+ if ( elapsedTime > maxDuration ) {
2393+ return null ;
2394+ }
23892395 const lineTokens = this . _getLineTokens ( lineNumber ) ;
23902396 const tokenCount = lineTokens . getCount ( ) ;
23912397 const lineText = this . _buffer . getLineContent ( lineNumber ) ;
0 commit comments