Skip to content

Commit 9c267a0

Browse files
authored
Merge pull request #346 from renkun-ken/fix-hover-func-arg
Fix hover func arg
2 parents 4883f44 + 5a57225 commit 9c267a0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

R/hover.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ hover_reply <- function(id, uri, workspace, document, point) {
4949
all_defs <- xml_find_all(enclosing_scopes, xpath)
5050
if (length(all_defs)) {
5151
last_def <- all_defs[[length(all_defs)]]
52-
def_func <- xml_find_first(last_def, "expr[FUNCTION]")
52+
def_func <- xml_find_first(last_def,
53+
"self::expr[LEFT_ASSIGN | RIGHT_ASSIGN | EQ_ASSIGN]/expr[FUNCTION]")
5354
if (length(def_func)) {
5455
func_line1 <- as.integer(xml_attr(def_func, "line1"))
5556
func_col1 <- as.integer(xml_attr(def_func, "col1"))

tests/testthat/test-hover.R

+30
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@ test_that("Hover on function argument works", {
238238
))
239239
})
240240

241+
test_that("Hover on user function with function argument works", {
242+
skip_on_cran()
243+
client <- language_client()
244+
245+
withr::local_tempfile(c("temp_file"), fileext = ".R")
246+
writeLines(
247+
c(
248+
"test <- function(var1, var2 = function(x) x + 1) {",
249+
" var1",
250+
" var2",
251+
"}"
252+
),
253+
temp_file
254+
)
255+
256+
client %>% did_save(temp_file)
257+
258+
result <- client %>% respond_hover(temp_file, c(1, 3))
259+
expect_length(result$contents, 1)
260+
expect_equal(result$contents[1], "```r\ntest <- function(var1, var2 = function(x) x + 1) {\n```")
261+
expect_equal(result$range$start, list(line = 1, character = 2))
262+
expect_equal(result$range$end, list(line = 1, character = 6))
263+
264+
result <- client %>% respond_hover(temp_file, c(2, 3))
265+
expect_length(result$contents, 1)
266+
expect_equal(result$contents[1], "```r\ntest <- function(var1, var2 = function(x) x + 1) {\n```")
267+
expect_equal(result$range$start, list(line = 2, character = 2))
268+
expect_equal(result$range$end, list(line = 2, character = 6))
269+
})
270+
241271
test_that("Hover works with local function", {
242272
skip_on_cran()
243273
client <- language_client()

0 commit comments

Comments
 (0)