Skip to content

Commit 9c32315

Browse files
committed
Merge branch 'master' of https://github.com/ElianHugh/vscode-R
2 parents f1eef75 + 8ec924b commit 9c32315

File tree

16 files changed

+764
-259
lines changed

16 files changed

+764
-259
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@
44

55
You can check all of our changes from [Release Page](https://github.com/REditorSupport/vscode-R/releases)
66

7+
## [2.1.0](https://github.com/REditorSupport/vscode-R/releases/tag/v2.1.0)
8+
9+
Important changes
10+
11+
* The project is migrated to [REditorSupport](https://github.com/REditorSupport) organization on
12+
GitHub. (#98)
13+
* The R language service (completion, document outline, definition, etc.,
14+
formerly implemented in [vscode-r-lsp](https://github.com/REditorSupport/vscode-r-lsp)) is now
15+
integrated into vscode-R (#695). The vscode-r-lsp extension will be unpublished from the
16+
VS Code marketplace
17+
at some point.
18+
* Search `r-lsp` extension, uninstall it and vscode-R will start the R langauge service
19+
automatically.
20+
* The language service still depends on the R package [`languageserver`](https://github.com/REditorSupport/languageserver). Make sure the package is installed before using vscode-R.
21+
* To opt-out the language service, set `"r.lsp.enabled": false` in your user settings.
22+
* R session watcher is now enabled by default. (#670)
23+
* `r.previewDataframe` and `r.previewEnvironment` will use the session watcher if enabled.
24+
* To opt-out, set `"r.sessionWatcher": false` in your user settings.
25+
26+
New Features
27+
28+
* Preview R Markdown documents via background process with auto-refresh and dark theme support. (#692, #699)
29+
30+
Enhancements
31+
32+
* Several enhancements of the workspace viewer. (#672)
33+
* The plot viewer now supports customizable CSS file via `r.plot.customStyleOverwrites` and
34+
`r.plot.togglePreviewPlots` now cycles through mutlirow/scroll/hidden. (#678, #681)
35+
* The data viewer is now based on [ag-grid](https://github.com/ag-grid/ag-grid) with better performance and better support for filtering and dark theme. (#708)
36+
* The data viewer might not work with existing R sessions started before the extension update.
37+
A restart of sessions is needed to use the new data viewer.
38+
* Command `r.showPlotHistory` is removed in favor of the httpgd-based plot viewer. (#706)
39+
* The plot viewer now supports full window mode. (#709)
40+
41+
Fixes
42+
43+
* LiveShare API bug fix and enhancements. (#679)
44+
* Fix syntax highlighting of integers in scientific notation. (#683)
45+
746
## [2.0.0](https://github.com/REditorSupport/vscode-R/releases/tag/v2.0.0)
847

948
Highlight

R/vsc.R

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,10 @@ if (use_httpgd && "httpgd" %in% .packages(all.available = TRUE)) {
176176
} else if (use_httpgd) {
177177
message("Install package `httpgd` to use vscode-R with httpgd!")
178178
} else if (show_plot) {
179-
dir_plot_history <- file.path(dir_session, "images")
180-
dir.create(dir_plot_history, showWarnings = FALSE, recursive = TRUE)
181179
plot_file <- file.path(dir_session, "plot.png")
182180
plot_lock_file <- file.path(dir_session, "plot.lock")
183181
file.create(plot_file, plot_lock_file, showWarnings = FALSE)
184182

185-
plot_history_file <- NULL
186183
plot_updated <- FALSE
187184
null_dev_id <- c(pdf = 2L)
188185
null_dev_size <- c(7 + pi, 7 + pi)
@@ -194,8 +191,6 @@ if (use_httpgd && "httpgd" %in% .packages(all.available = TRUE)) {
194191

195192
new_plot <- function() {
196193
if (check_null_dev()) {
197-
plot_history_file <<- file.path(dir_plot_history,
198-
format(Sys.time(), "%Y%m%d-%H%M%OS6.png"))
199194
plot_updated <<- TRUE
200195
}
201196
}
@@ -221,9 +216,6 @@ if (use_httpgd && "httpgd" %in% .packages(all.available = TRUE)) {
221216
on.exit({
222217
dev.off()
223218
cat(get_timestamp(), file = plot_lock_file)
224-
if (!is.null(plot_history_file)) {
225-
file.copy(plot_file, plot_history_file, overwrite = TRUE)
226-
}
227219
})
228220
replayPlot(record)
229221
}
@@ -249,26 +241,38 @@ if (use_httpgd && "httpgd" %in% .packages(all.available = TRUE)) {
249241

250242
show_view <- !identical(getOption("vsc.view", "Two"), FALSE)
251243
if (show_view) {
252-
dataview_data_type <- function(x) {
253-
if (is.numeric(x)) {
254-
if (is.null(attr(x, "class"))) {
255-
"num"
256-
} else {
257-
"num-fmt"
244+
get_column_def <- function(name, field, value) {
245+
filter <- TRUE
246+
if (is.numeric(value)) {
247+
type <- "numericColumn"
248+
if (is.null(attr(value, "class"))) {
249+
filter <- "agNumberColumnFilter"
258250
}
259-
} else if (inherits(x, "Date")) {
260-
"date"
251+
} else if (inherits(value, "Date")) {
252+
type <- "dateColumn"
253+
filter <- "agDateColumnFilter"
261254
} else {
262-
"string"
255+
type <- "textColumn"
256+
filter <- "agTextColumnFilter"
263257
}
258+
list(
259+
headerName = name,
260+
field = field,
261+
type = type,
262+
filter = filter
263+
)
264264
}
265265

266266
dataview_table <- function(data) {
267+
if (is.matrix(data)) {
268+
data <- as.data.frame.matrix(data)
269+
}
270+
267271
if (is.data.frame(data)) {
268272
nrow <- nrow(data)
269273
colnames <- colnames(data)
270274
if (is.null(colnames)) {
271-
colnames <- sprintf("(X%d)", seq_len(ncol(data)))
275+
colnames <- sprintf("V%d", seq_len(ncol(data)))
272276
} else {
273277
colnames <- trimws(colnames)
274278
}
@@ -278,49 +282,23 @@ if (show_view) {
278282
} else {
279283
rownames <- seq_len(nrow)
280284
}
285+
colnames <- c("(row)", colnames)
286+
fields <- sprintf("x%d", seq_along(colnames))
281287
data <- c(list(" " = rownames), .subset(data))
282-
colnames <- c(" ", colnames)
283-
types <- vapply(data, dataview_data_type,
284-
character(1L), USE.NAMES = FALSE)
285-
data <- vapply(data, function(x) {
286-
trimws(format(x))
287-
}, character(nrow), USE.NAMES = FALSE)
288-
dim(data) <- c(length(rownames), length(colnames))
289-
} else if (is.matrix(data)) {
290-
if (is.factor(data)) {
291-
data <- format(data)
292-
}
293-
types <- rep(dataview_data_type(data), ncol(data))
294-
colnames <- colnames(data)
295-
colnames(data) <- NULL
296-
if (is.null(colnames)) {
297-
colnames <- sprintf("(X%d)", seq_len(ncol(data)))
298-
} else {
299-
colnames <- trimws(colnames)
300-
}
301-
rownames <- rownames(data)
302-
rownames(data) <- NULL
303-
data <- trimws(format(data))
304-
if (is.null(rownames)) {
305-
types <- c("num", types)
306-
rownames <- seq_len(nrow(data))
307-
} else {
308-
types <- c("string", types)
309-
rownames <- trimws(rownames)
310-
}
311-
dim(data) <- c(length(rownames), length(colnames))
312-
colnames <- c(" ", colnames)
313-
data <- cbind(rownames, data)
288+
names(data) <- fields
289+
class(data) <- "data.frame"
290+
attr(data, "row.names") <- .set_row_names(nrow)
291+
columns <- .mapply(get_column_def,
292+
list(colnames, fields, data),
293+
NULL
294+
)
295+
list(
296+
columns = columns,
297+
data = data
298+
)
314299
} else {
315-
stop("data must be data.frame or matrix")
300+
stop("data must be a data.frame or a matrix")
316301
}
317-
columns <- .mapply(function(title, type) {
318-
class <- if (type == "string") "text-left" else "text-right"
319-
list(title = scalar(title),
320-
className = scalar(class),
321-
type = scalar(type))
322-
}, list(colnames, types), NULL)
323-
list(columns = columns, data = data)
324302
}
325303

326304
show_dataview <- function(x, title, uuid = NULL,
@@ -385,7 +363,7 @@ if (show_view) {
385363
if (is.data.frame(x) || is.matrix(x)) {
386364
data <- dataview_table(x)
387365
file <- tempfile(tmpdir = tempdir, fileext = ".json")
388-
jsonlite::write_json(data, file, matrix = "rowmajor")
366+
jsonlite::write_json(data, file, auto_unbox = TRUE)
389367
request("dataview", source = "table", type = "json",
390368
title = title, file = file, viewer = viewer, uuid = uuid)
391369
} else if (is.list(x)) {

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
[![Badge](https://aka.ms/vsls-badge)](https://aka.ms/vsls)
44

55
This [VS Code](https://code.visualstudio.com/) extension provides support for the [R programming language](https://www.r-project.org), including features such as
6-
extended syntax highlighting, interacting with R terminals, viewing data, plots, workspace variables, help pages, managing packages, and working with [R Markdown](https://rmarkdown.rstudio.com/) documents.
6+
extended syntax highlighting, R language service based on code analysis, interacting with R terminals, viewing data, plots, workspace variables, help pages, managing packages, and working with [R Markdown](https://rmarkdown.rstudio.com/) documents.
77

88
Go to the [wiki](https://github.com/REditorSupport/vscode-R/wiki) to view the documentation of the extension.
99

1010
## Getting started
1111

1212
1. [Install R](https://cloud.r-project.org/) (>= 3.4.0) on your system. For Windows users, Writing R Path to the registry is recommended in the installation.
1313

14-
2. Install [`jsonlite`](https://github.com/jeroen/jsonlite) and [`rlang`](https://github.com/r-lib/rlang) packages in R.
14+
2. Install [`languageserver`](https://github.com/REditorSupport/languageserver) in R.
1515

1616
```r
17-
install.packages(c("jsonlite", "rlang"))
17+
install.packages("languageserver")
1818
```
1919

2020
3. Install the [R extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=Ikuyadeu.r).
2121

2222
4. Create an R file and start coding.
2323

24-
Note that the above steps only provide basic code editing functionalities and features of interacting with R sessions. To get full R development experience such as code completion, linting, formatting, debugging, etc., go to the installation wiki pages ([Windows](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Windows) | [macOS](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS) | [Linux](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Linux)) for detailed instructions of installing the following recommended software and extensions:
24+
The following software or extensions are recommended to enhance the experience of using R in VS Code:
2525

2626
* [radian](https://github.com/randy3k/radian): A modern R console that corrects many limitations of the official R terminal and supports many features such as syntax highlighting and auto-completion.
2727

28-
* [languageserver](https://github.com/REditorSupport/languageserver): An R package that implements the Language Server Protocol for R to provide a wide range of language analysis features such as auto-completion, function signature, documentation, symbol highlight, document outline, code formatting, symbol hover, diagnostics, go to definition, find references, etc.
29-
30-
* [vscode-r-lsp](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r-lsp): A VS Code extension of R LSP Client to communicate between VS Code and R Language Server.
31-
3228
* [VSCode-R-Debugger](https://github.com/ManuelHentschel/VSCode-R-Debugger): A VS Code extension to support R debugging capabilities.
3329

3430
* [httpgd](https://github.com/nx10/httpgd): An R package to provide a graphics device that asynchronously serves SVG graphics via HTTP and WebSockets.
3531

32+
Go to the installation wiki pages ([Windows](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Windows) | [macOS](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS) | [Linux](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Linux)) for more detailed instructions.
33+
3634
## Features
3735

3836
* Extended syntax highlighting for R, R Markdown, and R Documentation.
3937

4038
* Snippets for R and R Markdown.
4139

40+
* [R Language Service](https://github.com/REditorSupport/vscode-R/wiki/R-Language-Service): Code completion, function signature, symbol highlight, document outline, formatting, definition, refere
41+
4242
* [Interacting with R terminals](https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals): Sending code to terminals, running multiple terminals, working with remote servers.
4343

4444
* [Package development](https://github.com/REditorSupport/vscode-R/wiki/Package-development): Build, test, install, load all and other commands from devtools.

html/httpgd/index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ function getSmallPlots() {
2121
return smallPlots;
2222
}
2323
let isHandlerDragging = false;
24+
let isFullWindow = false;
2425
function postResizeMessage(userTriggered = false) {
25-
const newHeight = largePlotDiv.clientHeight;
26-
const newWidth = largePlotDiv.clientWidth;
26+
let newHeight = largePlotDiv.clientHeight;
27+
let newWidth = largePlotDiv.clientWidth;
28+
if (isFullWindow) {
29+
newHeight = window.innerHeight;
30+
newWidth = window.innerWidth;
31+
}
2732
if (userTriggered || newHeight !== oldHeight || newWidth !== oldWidth) {
2833
const msg = {
2934
message: 'resize',
@@ -66,6 +71,9 @@ window.addEventListener('message', (ev) => {
6671
else if (msg.message === 'togglePreviewPlotLayout') {
6772
togglePreviewPlotLayout(msg.style);
6873
}
74+
else if (msg.message === 'toggleFullWindow') {
75+
toggleFullWindowMode(msg.useFullWindow);
76+
}
6977
});
7078
function addPlot(html) {
7179
const wrapper = document.createElement('div');
@@ -124,6 +132,17 @@ function togglePreviewPlotLayout(newStyle) {
124132
smallPlotDiv.classList.remove('multirow', 'scroll', 'hidden');
125133
smallPlotDiv.classList.add(newStyle);
126134
}
135+
function toggleFullWindowMode(useFullWindow) {
136+
isFullWindow = useFullWindow;
137+
if (useFullWindow) {
138+
document.body.classList.add('fullWindow');
139+
window.scrollTo(0, 0);
140+
}
141+
else {
142+
document.body.classList.remove('fullWindow');
143+
}
144+
postResizeMessage(true);
145+
}
127146
////
128147
// On window load
129148
////
@@ -136,15 +155,15 @@ window.onload = () => {
136155
////
137156
document.addEventListener('mousedown', (e) => {
138157
// If mousedown event is fired from .handler, toggle flag to true
139-
if (e.target === handler) {
158+
if (!isFullWindow && e.target === handler) {
140159
isHandlerDragging = true;
141160
handler.classList.add('dragging');
142161
document.body.style.cursor = 'ns-resize';
143162
}
144163
});
145164
document.addEventListener('mousemove', (e) => {
146165
// Don't do anything if dragging flag is false
147-
if (!isHandlerDragging) {
166+
if (isFullWindow || !isHandlerDragging) {
148167
return false;
149168
}
150169
// postLogMessage('mousemove');

html/httpgd/index.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ function getSmallPlots(): HTMLAnchorElement[] {
4444
let isHandlerDragging = false;
4545

4646

47+
let isFullWindow = false;
4748

4849
function postResizeMessage(userTriggered: boolean = false){
49-
const newHeight = largePlotDiv.clientHeight;
50-
const newWidth = largePlotDiv.clientWidth;
50+
let newHeight = largePlotDiv.clientHeight;
51+
let newWidth = largePlotDiv.clientWidth;
52+
if(isFullWindow){
53+
newHeight = window.innerHeight;
54+
newWidth = window.innerWidth;
55+
}
5156
if(userTriggered || newHeight !== oldHeight || newWidth !== oldWidth){
5257
const msg: ResizeMessage = {
5358
message: 'resize',
@@ -86,6 +91,8 @@ window.addEventListener('message', (ev: MessageEvent<InMessage>) => {
8691
addPlot(msg.html);
8792
} else if(msg.message === 'togglePreviewPlotLayout'){
8893
togglePreviewPlotLayout(msg.style);
94+
} else if(msg.message === 'toggleFullWindow'){
95+
toggleFullWindowMode(msg.useFullWindow);
8996
}
9097
});
9198

@@ -165,6 +172,16 @@ function togglePreviewPlotLayout(newStyle: PreviewPlotLayout): void {
165172
smallPlotDiv.classList.add(newStyle);
166173
}
167174

175+
function toggleFullWindowMode(useFullWindow): void {
176+
isFullWindow = useFullWindow;
177+
if(useFullWindow){
178+
document.body.classList.add('fullWindow');
179+
window.scrollTo(0, 0);
180+
} else {
181+
document.body.classList.remove('fullWindow');
182+
}
183+
postResizeMessage(true);
184+
}
168185

169186
////
170187
// On window load
@@ -183,7 +200,7 @@ window.onload = () => {
183200

184201
document.addEventListener('mousedown', (e) => {
185202
// If mousedown event is fired from .handler, toggle flag to true
186-
if (e.target === handler) {
203+
if (!isFullWindow && e.target === handler) {
187204
isHandlerDragging = true;
188205
handler.classList.add('dragging');
189206
document.body.style.cursor = 'ns-resize';
@@ -192,7 +209,7 @@ document.addEventListener('mousedown', (e) => {
192209

193210
document.addEventListener('mousemove', (e) => {
194211
// Don't do anything if dragging flag is false
195-
if (!isHandlerDragging) {
212+
if (isFullWindow || !isHandlerDragging) {
196213
return false;
197214
}
198215

0 commit comments

Comments
 (0)