Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] ask_format() eats a line #87

Closed
benlubas opened this issue Feb 10, 2024 · 2 comments
Closed

[bug] ask_format() eats a line #87

benlubas opened this issue Feb 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@benlubas
Copy link
Contributor

When formatting code in a markdown cell with the Lua language server like:

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

The result is:

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

I also see this in norg files where the @end that delimits the end of a code cell is removed.

@jmbuhr
Copy link
Owner

jmbuhr commented Feb 11, 2024

Indeed, looks like the range of the returned formatting response includes the next line as well:

{                                                                                                                          
  newText = 'print("this should be formatted")\n',                                                                         
  range = {                                                                                                                
    ["end"] = {                                                                                                            
      character = 0,                                                                                                       
      line = 11                                                                                                            
    },                                                                                                                     
    start = {                                                                                                              
      character = 0,                                                                                                       
      line = 9                                                                                                             
    }                                                                                                                      
  }                                                                                                                        
}

The root cause is that the treesitter node that contains the code chunk content appears to always include the next line as well, e.g.
(code_fence_content ; [10:1 - 11:0] markdown for a one-line chunk.

@jmbuhr jmbuhr added the bug Something isn't working label Feb 11, 2024
@jmbuhr jmbuhr self-assigned this Feb 11, 2024
@jmbuhr
Copy link
Owner

jmbuhr commented Feb 11, 2024

The above linked commit / PR fixes this by simply decrementing the end_row of the node range and I have not encountered any issues so far.

@jmbuhr jmbuhr closed this as completed in db9d131 Feb 11, 2024
benlubas pushed a commit to benlubas/otter.nvim that referenced this issue Feb 12, 2024
…r#88)

fix: decrement end line number of code content node range by 1. fix jmbuhr#87.

testing: add R chunk to qmd example

testing: add norg example

testing: add ts example

testing: document debug-example script
jmbuhr added a commit that referenced this issue Mar 2, 2024
* fix: decrement end line number of code content node range by 1 (#88)

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

* feat: handle leading whitespace

* fix: rename, backward invert logic

* everything works, but it's a little messy

* fix: add nil check

* add more language support and informative error

* small things

---------

Co-authored-by: Jannik Buhr <17450586+jmbuhr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants