From 4f2a8e5fe186d8c9b07b27f7196b720f62d8f4e4 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 08:05:14 +0800 Subject: [PATCH 1/3] Fix hover on EQ_ASSIGN --- R/hover.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/hover.R b/R/hover.R index 91a70179..5bce2765 100644 --- a/R/hover.R +++ b/R/hover.R @@ -50,7 +50,7 @@ hover_reply <- function(id, uri, workspace, document, point) { if (length(all_defs)) { last_def <- all_defs[[length(all_defs)]] def_func <- xml_find_first(last_def, - "self::expr[LEFT_ASSIGN | RIGHT_ASSIGN | EQ_ASSIGN]/expr[FUNCTION | OP-LAMBDA]") + "self::*[LEFT_ASSIGN | RIGHT_ASSIGN | EQ_ASSIGN]/expr[FUNCTION | OP-LAMBDA]") if (length(def_func)) { func_line1 <- as.integer(xml_attr(def_func, "line1")) func_col1 <- as.integer(xml_attr(def_func, "col1")) From 9eca144e3b7a1e6d4a31702d57e3808106994d74 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 08:13:28 +0800 Subject: [PATCH 2/3] Add test cases --- tests/testthat/test-hover.R | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-hover.R b/tests/testthat/test-hover.R index fee268c1..c4e92dea 100644 --- a/tests/testthat/test-hover.R +++ b/tests/testthat/test-hover.R @@ -32,7 +32,9 @@ test_that("Hover on user function works", { writeLines( c( "test1 <- function(x, y) x + 1", - "test1" + "test1", + "test2 = function(x, y) x - 1", + "test2" ), temp_file ) @@ -43,6 +45,37 @@ test_that("Hover on user function works", { expect_length(result$contents, 1) expect_equal(result$contents[1], "```r\ntest1(x, y)\n```") expect_equal(result$range$end$character, 5) + + result <- client %>% respond_hover(temp_file, c(3, 3)) + expect_length(result$contents, 1) + expect_equal(result$contents[1], "```r\ntest2(x, y)\n```") + expect_equal(result$range$end$character, 5) +}) + +test_that("Hover on user function with multi-lined arguments works", { + skip_on_cran() + client <- language_client() + + temp_file <- withr::local_tempfile(fileext = ".R") + writeLines( + c( + "test1 <- function(", + " x, # arg 1", + " y # arg 2", + ") {", + " x + y", + "}", + "test1" + ), + temp_file + ) + + client %>% did_save(temp_file) + + result <- client %>% respond_hover(temp_file, c(6, 3)) + expect_length(result$contents, 1) + expect_equal(result$contents[1], "```r\ntest1(x, y)\n```") + expect_equal(result$range$end$character, 5) }) test_that("Hover on variable works", { From 695a0c6dff97f489170d8834ec70c4d6e1c3ef00 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 09:04:12 +0800 Subject: [PATCH 3/3] Update test cases --- tests/testthat/test-hover.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-hover.R b/tests/testthat/test-hover.R index c4e92dea..60353b02 100644 --- a/tests/testthat/test-hover.R +++ b/tests/testthat/test-hover.R @@ -65,7 +65,14 @@ test_that("Hover on user function with multi-lined arguments works", { ") {", " x + y", "}", - "test1" + "test1", + "test2 = function(", + " x, # arg 1", + " y # arg 2", + ") {", + " x + y", + "}", + "test2" ), temp_file ) @@ -76,6 +83,11 @@ test_that("Hover on user function with multi-lined arguments works", { expect_length(result$contents, 1) expect_equal(result$contents[1], "```r\ntest1(x, y)\n```") expect_equal(result$range$end$character, 5) + + result <- client %>% respond_hover(temp_file, c(13, 3)) + expect_length(result$contents, 1) + expect_equal(result$contents[1], "```r\ntest2(x, y)\n```") + expect_equal(result$range$end$character, 5) }) test_that("Hover on variable works", {