Skip to content

Commit

Permalink
fix: decrement end line number of code content node range by 1 (#88)
Browse files Browse the repository at this point in the history
fix: decrement end line number of code content node range by 1. fix #87.

testing: add R chunk to qmd example

testing: add norg example

testing: add ts example

testing: document debug-example script
  • Loading branch information
jmbuhr authored and benlubas committed Feb 12, 2024
1 parent 8d98011 commit 2bb82fc
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lua/otter/keeper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,19 @@ M.get_current_language_context = function(main_nr)
local name = query.captures[id]

lang_capture = determine_language(main_nr, name, node, metadata, lang_capture)
local start_row, start_col, end_row, end_col = node:range()
end_row = end_row - 1

if lang_capture and (name == "content" or name == "injection.content") then
-- chunks where the name of the injected language is dynamic
-- e.g. markdown code chunks
if ts.is_in_node_range(node, row, col) then
return lang_capture, node:range()
return lang_capture, start_row, start_col, end_row, end_col
end
-- chunks where the name of the language is the name of the capture
elseif fn.contains(injectable_languages, name) then
if ts.is_in_node_range(node, row, col) then
return name, node:range()
return name, start_row, start_col, end_row, end_col
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions tests/debug-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/env bash
# usage: ./tests/debug-example.sh $1

echo "choose an example file based on number of extension."
echo "e.g. ./tests/debug-example.sh 01"
echo "e.g. ./tests/debug-example.sh qmd"
echo "Options"
ls ./tests/examples/

if [ -z "$1" ]; then
echo "Please provide a file extension or a number"
echo "And call this from the project root directory"
exit 1
fi

nvim ./tests/examples/*$1* -c ":lua require'otter'.dev_setup()"
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/examples/01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ engine: markdown

# Hello

```{r}
print('hello world')
plot(1:10)
```


```{python}
print('hello world')
```
Expand Down
17 changes: 17 additions & 0 deletions tests/examples/03.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ engine: markdown

# Hello

```lua
print( "this should be formatted")
```

```lua
print( "this should be formatted")
```

```{python}
print('hello world')
```
Expand Down Expand Up @@ -43,3 +51,12 @@ def hello():
```{python}
hello()
```


```{python}
import numpy as np
np.zeros(10)
```


26 changes: 26 additions & 0 deletions tests/examples/05.norg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@document.meta
title: Norg Example
description: This is an example of Norg document.
@end

* Norg Example

** Code
@code lua
print("Hello, Norg!")
@end


@code python
print("Hello world!")
import numpy as np
x = np.zeros(10)
@end

** Other things
This is a paragraph.

- This is a list.
- This is another list.

This is another paragraph.
16 changes: 16 additions & 0 deletions tests/examples/06.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const foo = html`
<div>
<p>hello</p>
</div>
`;

const bar = css`
.foo {
color: rgb(0, 0, 0);
}
`;

const lua = lua`
local foo = "bar"
print(foo)
`;

0 comments on commit 2bb82fc

Please sign in to comment.