File tree 2 files changed +56
-3
lines changed
2 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -29,15 +29,18 @@ local get_node_at_cursor = function()
29
29
end
30
30
31
31
M .get_effective_filetype = function ()
32
- local current_line_nr = vim .api .nvim_win_get_cursor (0 )[1 ]
33
- local current_line_col = vim .api .nvim_win_get_cursor (0 )[2 ]
32
+ local current_line_nr = vim .api .nvim_win_get_cursor (0 )[1 ] - 1
33
+ -- Looking at the last column is more accurate because there are some
34
+ -- embeddings (e.g. JS in HTML) where the Treesitter embedding doesn't begin
35
+ -- until the first non-whitespace column
36
+ local current_line_col = vim .fn .col (' $' )
34
37
35
38
local success , parser = pcall (vim .treesitter .get_parser , 0 )
36
39
37
40
if success then
38
41
-- For some reason I don't understand, this parse line is necessary to
39
42
-- make embedded languages work
40
- parser :parse ({ 0 , current_line_nr } )
43
+ parser :parse (true )
41
44
42
45
return parser
43
46
:language_for_range ({
Original file line number Diff line number Diff line change @@ -1481,5 +1481,55 @@ if vim.fn.has("nvim-0.9.0") == 1 then
1481
1481
" bar" ,
1482
1482
})
1483
1483
end )
1484
+
1485
+ it (" lua in markdown above" , function ()
1486
+ local filename = init_file ({
1487
+ " foo" ,
1488
+ " ```lua" ,
1489
+ " x = 1" ,
1490
+ " ```" ,
1491
+ " bar" ,
1492
+ }, " markdown" , 3 , 0 )
1493
+
1494
+ feedkeys (" g?P" )
1495
+
1496
+ check_lines ({
1497
+ " foo" ,
1498
+ " ```lua" ,
1499
+ " print('DEBUGPRINT[1]: " .. filename .. " :3 (before x = 1)')" ,
1500
+ " x = 1" ,
1501
+ " ```" ,
1502
+ " bar" ,
1503
+ })
1504
+ end )
1505
+
1506
+ it (" javascript in html" , function ()
1507
+ local filename = init_file ({
1508
+ " <html>" ,
1509
+ " <body>" ,
1510
+ " <script>" ,
1511
+ " let x = 3;" ,
1512
+ " " ,
1513
+ " console.log(x);" ,
1514
+ " </script>" ,
1515
+ " </body>" ,
1516
+ " </html>" ,
1517
+ }, " html" , 6 , 0 )
1518
+
1519
+ feedkeys (" g?p" )
1520
+
1521
+ check_lines ({
1522
+ " <html>" ,
1523
+ " <body>" ,
1524
+ " <script>" ,
1525
+ " let x = 3;" ,
1526
+ " " ,
1527
+ " console.log(x);" ,
1528
+ " console.warn(\" DEBUGPRINT[1]: " .. filename .. " :6 (after console.log(x);)\" )" ,
1529
+ " </script>" ,
1530
+ " </body>" ,
1531
+ " </html>" ,
1532
+ })
1533
+ end )
1484
1534
end )
1485
1535
end
You can’t perform that action at this time.
0 commit comments