Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions R/help/getAliases.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
add_lib_paths <- Sys.getenv("VSCR_LIB_PATHS")
if (nzchar(add_lib_paths)) {
add_lib_paths <- strsplit(add_lib_paths, "\n", fixed = TRUE)[[1L]]
.libPaths(c(.libPaths(), add_lib_paths))
}

loadNamespace("jsonlite")

ip <- installed.packages()
Expand Down
7 changes: 6 additions & 1 deletion R/help/helpServer.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# get values from extension-set env values
add_lib_paths <- Sys.getenv("VSCR_LIB_PATHS")
if (nzchar(add_lib_paths)) {
add_lib_paths <- strsplit(add_lib_paths, "\n", fixed = TRUE)[[1L]]
.libPaths(c(.libPaths(), add_lib_paths))
}

lim <- Sys.getenv("VSCR_LIM")

NEW_PACKAGE_STRING <- "NEW_PACKAGES"
Expand Down
6 changes: 3 additions & 3 deletions R/languageServer.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_lib_paths <- Sys.getenv("R_LSP_LIB_PATHS")
add_lib_paths <- Sys.getenv("VSCR_LIB_PATHS")
if (nzchar(add_lib_paths)) {
add_lib_paths <- strsplit(add_lib_paths, "\n", fixed = TRUE)[[1L]]
.libPaths(c(.libPaths(), add_lib_paths))
Expand All @@ -8,8 +8,8 @@ if (!requireNamespace("languageserver", quietly = TRUE)) {
q(save = "no", status = 10)
}

debug <- Sys.getenv("R_LSP_DEBUG")
port <- Sys.getenv("R_LSP_PORT")
debug <- Sys.getenv("VSCR_LSP_DEBUG")
port <- Sys.getenv("VSCR_LSP_PORT")

debug <- if (nzchar(debug)) as.logical(debug) else FALSE
port <- if (nzchar(port)) as.integer(port) else NULL
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,13 @@
"default": [],
"description": "The command line arguments to use when launching R Language Server."
},
"r.lsp.libPaths": {
"r.libPaths": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"markdownDescription": "Additional library paths to launch R Language Server with. These paths will be appended to `.libPaths()`. `${workspaceFolder}` and `${home}` could be used in the paths."
"markdownDescription": "Additional library paths to launch R background processes (R languageserver, help server, etc.). These paths will be appended to `.libPaths()` on process startup. It could be useful for projects with [renv](https://rstudio.github.io/renv/index.html) enabled. `${workspaceFolder}` and `${home}` could be used in the paths."
},
"r.lsp.promptToInstall": {
"type": "boolean",
Expand Down
9 changes: 7 additions & 2 deletions src/helpViewer/helpProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as cp from 'child_process';

import * as rHelp from '.';
import { extensionContext } from '../extension';
import { DisposableProcess, spawn, spawnAsync } from '../util';
import { DisposableProcess, getRLibPaths, spawn, spawnAsync } from '../util';

export interface RHelpProviderOptions {
// path of the R executable
Expand Down Expand Up @@ -58,7 +58,11 @@ export class HelpProvider {
];
const cpOptions = {
cwd: this.cwd,
env: { ...process.env, 'VSCR_LIM': lim },
env: {
...process.env,
VSCR_LIB_PATHS: getRLibPaths(this.cwd),
VSCR_LIM: lim
},
};

const childProcess: ChildProcessWithPort = spawn(this.rPath, args, cpOptions);
Expand Down Expand Up @@ -272,6 +276,7 @@ export class AliasProvider {
cwd: this.cwd,
env: {
...process.env,
VSCR_LIB_PATHS: getRLibPaths(this.cwd),
VSCR_LIM: lim
}
};
Expand Down
13 changes: 4 additions & 9 deletions src/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net = require('net');
import url = require('url');
import { LanguageClient, LanguageClientOptions, StreamInfo, DocumentFilter, ErrorAction, CloseAction, RevealOutputChannelOn } from 'vscode-languageclient/node';
import { Disposable, workspace, Uri, TextDocument, WorkspaceConfiguration, OutputChannel, window, WorkspaceFolder } from 'vscode';
import { DisposableProcess, getRpath, promptToInstallRPackage, spawn } from './util';
import { DisposableProcess, getRLibPaths, getRpath, promptToInstallRPackage, spawn } from './util';
import { extensionContext } from './extension';
import { CommonOptions } from 'child_process';

Expand Down Expand Up @@ -63,13 +63,8 @@ export class LanguageService implements Disposable {
}
const use_stdio = config.get<boolean>('lsp.use_stdio');
const env = Object.create(process.env);
env.R_LSP_DEBUG = debug ? 'TRUE' : 'FALSE';
env.R_LSP_LIB_PATHS = config.get<string[]>('lsp.libPaths')
.map(dir => dir
.replace('${workspaceFolder}', workspaceFolder?.uri.fsPath || cwd)
.replace('${home}', os.homedir())
)
.join('\n');
env.VSCR_LSP_DEBUG = debug ? 'TRUE' : 'FALSE';
env.VSCR_LIB_PATHS = getRLibPaths(workspaceFolder?.uri.fsPath || cwd);

const lang = config.get<string>('lsp.lang');
if (lang !== '') {
Expand Down Expand Up @@ -111,7 +106,7 @@ export class LanguageService implements Disposable {
// Listen on random port
server.listen(0, '127.0.0.1', () => {
const port = (server.address() as net.AddressInfo).port;
env.R_LSP_PORT = String(port);
env.VSCR_LSP_PORT = String(port);
return this.spawnServer(client, rPath, args, options);
});
});
Expand Down
11 changes: 9 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { existsSync, PathLike, readFile } from 'fs-extra';
import * as fs from 'fs';
import os = require('os');
import winreg = require('winreg');
import * as path from 'path';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -296,8 +297,14 @@ export async function getCranUrl(path: string = '', cwd?: string): Promise<strin
return url;
}



export function getRLibPaths(cwd: string): string {
return config().get<string[]>('libPaths')
.map(dir => dir
.replace('${workspaceFolder}', cwd)
.replace('${home}', os.homedir())
)
.join('\n');
}

// executes an R command returns its output to stdout
// uses a regex to filter out output generated e.g. by code in .Rprofile
Expand Down