@@ -175,7 +175,6 @@ describe('TreeSitterLanguageMode', () => {
175
175
] )
176
176
177
177
buffer . append ( ')' )
178
- await nextHighlightingUpdate ( languageMode )
179
178
expectTokensToEqual ( editor , [
180
179
[
181
180
{ text : 'a' , scopes : [ 'function' ] } ,
@@ -459,6 +458,50 @@ describe('TreeSitterLanguageMode', () => {
459
458
} )
460
459
} )
461
460
461
+ describe ( 'when changes are small enough to be re-parsed synchronously' , ( ) => {
462
+ it ( 'can incorporate multiple consecutive synchronous updates' , ( ) => {
463
+ const grammar = new TreeSitterGrammar ( atom . grammars , jsGrammarPath , {
464
+ parser : 'tree-sitter-javascript' ,
465
+ scopes : {
466
+ 'property_identifier' : 'property' ,
467
+ 'call_expression > identifier' : 'function' ,
468
+ 'call_expression > member_expression > property_identifier' : 'method' ,
469
+ }
470
+ } )
471
+
472
+ const languageMode = new TreeSitterLanguageMode ( { buffer, grammar} )
473
+ buffer . setLanguageMode ( languageMode )
474
+ buffer . setText ( 'a' ) ;
475
+ expectTokensToEqual ( editor , [ [
476
+ { text : 'a' , scopes : [ ] } ,
477
+ ] ] )
478
+
479
+ buffer . append ( '.' )
480
+ expectTokensToEqual ( editor , [ [
481
+ { text : 'a.' , scopes : [ ] } ,
482
+ ] ] )
483
+
484
+ buffer . append ( 'b' )
485
+ expectTokensToEqual ( editor , [ [
486
+ { text : 'a.' , scopes : [ ] } ,
487
+ { text : 'b' , scopes : [ 'property' ] } ,
488
+ ] ] )
489
+
490
+ buffer . append ( '()' )
491
+ expectTokensToEqual ( editor , [ [
492
+ { text : 'a.' , scopes : [ ] } ,
493
+ { text : 'b' , scopes : [ 'method' ] } ,
494
+ { text : '()' , scopes : [ ] } ,
495
+ ] ] )
496
+
497
+ buffer . delete ( [ [ 0 , 1 ] , [ 0 , 2 ] ] )
498
+ expectTokensToEqual ( editor , [ [
499
+ { text : 'ab' , scopes : [ 'function' ] } ,
500
+ { text : '()' , scopes : [ ] } ,
501
+ ] ] )
502
+ } )
503
+ } )
504
+
462
505
describe ( 'injectionPoints and injectionPatterns' , ( ) => {
463
506
let jsGrammar , htmlGrammar
464
507
@@ -526,7 +569,6 @@ describe('TreeSitterLanguageMode', () => {
526
569
const range = buffer . findSync ( 'html' )
527
570
buffer . setTextInRange ( range , 'xml' )
528
571
await nextHighlightingUpdate ( languageMode )
529
- await nextHighlightingUpdate ( languageMode )
530
572
531
573
expectTokensToEqual ( editor , [
532
574
[
@@ -1371,6 +1413,23 @@ describe('TreeSitterLanguageMode', () => {
1371
1413
'property.name'
1372
1414
] )
1373
1415
} )
1416
+
1417
+ it ( 'includes the root scope name even when the given position is in trailing whitespace at EOF' , ( ) => {
1418
+ const grammar = new TreeSitterGrammar ( atom . grammars , jsGrammarPath , {
1419
+ scopeName : 'source.js' ,
1420
+ parser : 'tree-sitter-javascript' ,
1421
+ scopes : {
1422
+ program : 'source.js' ,
1423
+ property_identifier : 'property.name'
1424
+ }
1425
+ } )
1426
+
1427
+ buffer . setText ( 'a; ' )
1428
+ buffer . setLanguageMode ( new TreeSitterLanguageMode ( { buffer, grammar} ) )
1429
+ expect ( editor . scopeDescriptorForBufferPosition ( [ 0 , 3 ] ) . getScopesArray ( ) ) . toEqual ( [
1430
+ 'source.js'
1431
+ ] )
1432
+ } )
1374
1433
} )
1375
1434
1376
1435
describe ( '.bufferRangeForScopeAtPosition(selector?, position)' , ( ) => {
0 commit comments