R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
128 stars 15 forks source link

Sending a single line sends entire document in .R file #127

Closed LittleTealeaf closed 1 month ago

LittleTealeaf commented 2 months ago

I'm currently writing a R file and running into an issue where <leader>d or <leader>l will send the entire file and not the one line that I'm running.

It seems to have started happening after I use the LSP Format to clean up the code. However, now even if I delete everything and restart it continues to just send the entire file when I ask for only the current line.

Happy to experiment and provide additional information if needed

jalvesaq commented 2 months ago

I can't replicate the issue. With this very simple R script:

x <- 1
y <- 2
z <- 3

The output of :InspectTree is:

(program ; [0, 0] - [3, 0]
  (left_assignment ; [0, 0] - [0, 6]
    name: (identifier) ; [0, 0] - [0, 1]
    value: (float)) ; [0, 5] - [0, 6]
  (left_assignment ; [1, 0] - [1, 6]
    name: (identifier) ; [1, 0] - [1, 1]
    value: (float)) ; [1, 5] - [1, 6]
  (left_assignment ; [2, 0] - [2, 6]
    name: (identifier) ; [2, 0] - [2, 1]
    value: (float))) ; [2, 5] - [2, 6]
PMassicotte commented 2 months ago

Same here, all is working fine.

LittleTealeaf commented 2 months ago

Ok, so I just replicated the issue. It seems that whenever I use the LSP Format it starts doing the "consider everything one line" (at first, it did one line, I then ran the lsp format, and then suddenly it does the whole line

2024-04-30-092642_hyprshot

This is my LSPInfo output if needed

 Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: /home/tealeaf/.local/state/nvim/lsp.log
 Detected filetype:   r

 1 client(s) attached to this buffer: 

 Client: r_language_server (id: 1, bufnr: [4])
    filetypes:       r, rmd
    autostart:       true
    root directory:  /home/tealeaf/dev/EC-366-Final
    cmd:             /usr/bin/R --slave -e languageserver::run()

 Configured servers list: yamlls, html, jsonls, vimls, tsserver, docker_compose_language_service, vuels, emmet_language_server, taplo, gopls, lua_ls, csharp_ls, texlab, bashls, r_language_server, clangd, pylsp, cssls, julials, zls, prismals, asm_lsp

Update: well now it's playing nice so I think it's smelling my intention to replace it with vscode

video demo: https://www.youtube.com/watch?v=kd1zS4i8lu4

jalvesaq commented 2 months ago

The algorithm to send a "line" is:

  1. Get the current tree-sitter node.
  2. Move upward in the tree-sitter hierarchy until the parent node is either "program" or "brace_list".
  3. Send the text of the whole subtree.

The output of :InspectTree looks normal: no node below "program" spans from the beginning of the file to its end. For example, call ; [0, 0] - [0, 18] means "function call beginning at line 1, column 1 and ending at line 1, column 19" (the index is zero-based). That is, only line 1 would be sent after doing <LocalLeader>d on it.

jalvesaq commented 1 month ago

Update: well now it's playing nice so I think it's smelling my intention to replace it with vscode

I'm closing the issue. Please, reopen it if you find a reliable way of replicating the bug.