Skip to content

Turn rnvimserver into a language server - #449

Merged
jalvesaq merged 142 commits into
mainfrom
lsp
Nov 17, 2025
Merged

Turn rnvimserver into a language server#449
jalvesaq merged 142 commits into
mainfrom
lsp

Conversation

@jalvesaq

@jalvesaq jalvesaq commented Nov 6, 2025

Copy link
Copy Markdown
Member

No description provided.

@jalvesaq
jalvesaq marked this pull request as ready for review November 17, 2025 18:10
@jalvesaq
jalvesaq requested a review from Copilot November 17, 2025 18:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 68 out of 69 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (4)

nvimcom/src/apps/utilities.c:1

  • Debug logging statement left in production code. This should either be removed or conditionally compiled based on a debug flag.
    nvimcom/src/apps/logging.c:1
  • [nitpick] Silent failure when log file cannot be opened could make debugging difficult. Consider adding a fallback mechanism or one-time stderr warning.
    nvimcom/src/apps/rnvimserver.c:1
  • Callback functions on_attach, on_init, on_exit, and on_error are only enabled when lsp_debug is true, but they still execute vim.notify() calls. These notifications should be gated or removed in production.
    nvimcom/src/apps/rnvimserver.c:1
  • [nitpick] Magic number 380 used for truncating debug output should be defined as a named constant for clarity and maintainability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lua/r/config.lua
local set_directories = function()
-- config.rnvim_home should be the directory where the plugin files are.
config.rnvim_home = vim.fn.expand("<script>:h:h")
local rndir = debug.getinfo(1, "S").source

Copilot AI Nov 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pattern matching to extract plugin directory path could fail on Windows due to backslash path separators. Consider using vim.fn.fnamemodify() or normalizing path separators.

Suggested change
local rndir = debug.getinfo(1, "S").source
local rndir = debug.getinfo(1, "S").source
-- Normalize path separators to forward slashes for cross-platform compatibility
rndir = rndir:gsub("\\", "/")

Copilot uses AI. Check for mistakes.
Comment thread lua/r/lsp/init.lua Outdated
Comment on lines +239 to +242
if not compl_region then
M.send_msg({ code = "E" .. req_id })
return
end

Copilot AI Nov 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compl_region variable is initialized to true but never modified elsewhere in the code. Document the purpose of this variable or remove it if unused.

Copilot uses AI. Check for mistakes.
@PMassicotte

PMassicotte commented Nov 17, 2025

Copy link
Copy Markdown
Collaborator

Cool. I will try that tonight.

image

should not be too long :)

Joke aside, very good job. I will play around a bit to see if I can spot any issues.

@PMassicotte

PMassicotte commented Nov 17, 2025

Copy link
Copy Markdown
Collaborator

One thing, could it be possible to complete data frame columns using the ~, like in ggplot2 facet_*() functions?

@PMassicotte PMassicotte left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a migration guide?

Comment thread lua/r/lsp/init.lua

-- check if the cursor is within comment or string
local snm = ""
local c = vim.treesitter.get_captures_at_pos(0, lnum, cnum - 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local c = vim.treesitter.get_captures_at_pos(0, lnum, cnum - 1)
local ok, c = pcall(vim.treesitter.get_captures_at_pos, 0, lnum, cnum - 1)
if not ok then c = {} end

Maybe replace all occurrences with similar check?

Comment thread nvimcom/DESCRIPTION
@PMassicotte

Copy link
Copy Markdown
Collaborator

Should we propose something like

return {
      {
          "R-nvim/R.nvim",
          version = "^1",  -- Use 1.x.x (new LSP)
          version = "^0",  -- Use old version with cmp-r
          config = function()
              require("r").setup({
                  ...
              })
          end,
      },
  }

@jalvesaq

Copy link
Copy Markdown
Member Author

should not be too long :)

Too long! I hope we do not have to do any other transition like that in the next 20 years.

This PR induces breaking changes. Should we go to 1.0.0?

Not yet, I think. We are free to break compatibility with old code because we haven't released version 1.0.0 yet. I prefer to stay on version 0.99.x for a few months until we fix the bugs that will be reported. At least on Windows, I know there are bugs to be fixed. We can suggest a specific commit for anyone with problems with the "lsp" version. The last commit on the "main" branch was fef990378e4b5157f23314dca4136bc0079cc2c4. Alternatively, we can tag the last commit on the "main" branch as 0.99.1.

One thing, could it be possible to complete data frame columns using the ~, like in ggplot2 facet_*() functions?

Yes, editing the function need_R_args() (lua/r/lsp/init.lua). We may do this in the future, unless you have time to do it now. If we are going to implement this feature, I think it's better if 1.0.0 is released with it.

@PMassicotte

PMassicotte commented Nov 17, 2025

Copy link
Copy Markdown
Collaborator

Not yet, I think. We are free to break compatibility with old code because we haven't released version 1.0.0 yet. I prefer to stay on version 0.99.x for a few months until we fix the bugs that will be reported.

Totally fine with me.

I can take a look to the ~ implementation in the upcoming days. Good opportunity to get more used to the lsp code base.

Ready to get this big one merged? I have not found any issues lately.

@PMassicotte

Copy link
Copy Markdown
Collaborator

Maybe just add something in README to point to the latest main commit without built-in lsp. I expect a lot of new issues due to braking changes.

@jalvesaq

Copy link
Copy Markdown
Member Author

Maybe just add something in README to point to the latest main commit without built-in lsp. I expect a lot of new issues due to braking changes.

I'll release 0.99.1 and the note to the README before merging the "lsp" branch. Then, wait for bug reports...

@jalvesaq
jalvesaq merged commit 9f21d6c into main Nov 17, 2025
9 checks passed
@jalvesaq
jalvesaq deleted the lsp branch November 17, 2025 23:20
@wurli

wurli commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

Congrats on getting this merged! A big step for R.nvim 🥳

@PMassicotte

Copy link
Copy Markdown
Collaborator

For some reason, I am not getting hover:

image

@jalvesaq

Copy link
Copy Markdown
Member Author

Tree-sitter restriction:

(program ; [0, 0] - [1, 0]
  (identifier)) ; [0, 0] - [0, 6]

It only tries to get the summary if the object under the cursor is "variable". The purpose of this restriction was to avoid sending meaningless requests to R. Perhaps we should eliminate this restriction.

@PMassicotte

PMassicotte commented Nov 18, 2025

Copy link
Copy Markdown
Collaborator

It has a strange behavior, does not work on mtcars, neither on res. Does not work on lm unless it is on multiple lines.

Peek 2025-11-18 07-40

@jalvesaq

Copy link
Copy Markdown
Member Author

I created the branch "fix_lsp". We can fix minor bugs there for a few days, but merge it immediately if we fix a serious bug.

@jalvesaq

Copy link
Copy Markdown
Member Author

On the "fix_lsp" branch, we have a new issue. The hover over data returns information on the function data(), which is incorrect:

res <- lm(mpg ~ wt + hp, data = mtcars)

@jalvesaq

Copy link
Copy Markdown
Member Author

If we used tree-sitter information, we would know that data is @variable.parameter and that we don't support hover for function arguments.

@jalvesaq

Copy link
Copy Markdown
Member Author

Perhaps you could make adjustments to the function hover() (lua/r/lsp/init.lua) to optimize it. The meanings of the parameters sent to rnvimserver are:

  • { code = "N" .. req_id }: Null result.
  • { code = "H", orig_id = req_id, word = word, fobj = first_obj }: word is a function; use the first object to check if we should show information for the function itself or for a method.
  • { code = "H", orig_id = req_id, word = word }: try to find the appropriate information (might be a function without a first argument or anything else).

@PMassicotte

PMassicotte commented Nov 18, 2025

Copy link
Copy Markdown
Collaborator

Perhaps you could make adjustments to the function hover()

I think we could really benefit from using TS instead of string based search. What do you think? I do not mind to look at it, but will take few days, a lot of meetings/workshops to do this week on my side :)

@jalvesaq

Copy link
Copy Markdown
Member Author

I think we could really benefit from using TS instead of string based search. What do you think? I do not mind to look at it, but will take few days, a lot of meetings/workshops to do this week on my side :)

Reading this now. I've said the same thing in the other thread. It's better to continue later, when we are both free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants