Skip to content

Commit ce8ae9c

Browse files
committed
Substitute variables in r.rterm.option and r.lsp.args settings
1 parent 4b2e340 commit ce8ae9c

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/languageService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as net from 'net';
44
import { URL } from 'url';
55
import { LanguageClient, LanguageClientOptions, StreamInfo, DocumentFilter, ErrorAction, CloseAction, RevealOutputChannelOn } from 'vscode-languageclient/node';
66
import { Disposable, workspace, Uri, TextDocument, WorkspaceConfiguration, OutputChannel, window, WorkspaceFolder } from 'vscode';
7-
import { DisposableProcess, getRLibPaths, getRpath, promptToInstallRPackage, spawn } from './util';
7+
import { DisposableProcess, getRLibPaths, getRpath, promptToInstallRPackage, spawn, substituteVariables } from './util';
88
import { extensionContext } from './extension';
99
import { CommonOptions } from 'child_process';
1010

@@ -84,7 +84,7 @@ export class LanguageService implements Disposable {
8484

8585
const rScriptPath = extensionContext.asAbsolutePath('R/languageServer.R');
8686
const options = { cwd: cwd, env: env };
87-
const args = (config.get<string[]>('lsp.args') ?? []).concat(
87+
const args = (config.get<string[]>('lsp.args')?.map(substituteVariables) ?? []).concat(
8888
'--silent',
8989
'--slave',
9090
'--no-save',

src/rTerminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function runFromLineToEnd(): Promise<void> {
117117
export async function makeTerminalOptions(): Promise<vscode.TerminalOptions> {
118118
const workspaceFolderPath = getCurrentWorkspaceFolder()?.uri.fsPath;
119119
const termPath = await getRterm();
120-
const shellArgs: string[] = config().get('rterm.option') || [];
120+
const shellArgs: string[] = config().get<string[]>('rterm.option')?.map(util.substituteVariables) || [];
121121
const termOptions: vscode.TerminalOptions = {
122122
name: 'R Interactive',
123123
shellPath: termPath,

src/util.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ function substituteVariable(str: string, key: string, getValue: () => string | u
2525
return str;
2626
}
2727

28-
function substituteVariables(str: string) {
28+
export function substituteVariables(str: string): string {
2929
let result = str;
30-
result = substituteVariable(result, '${userHome}', () => homedir());
31-
result = substituteVariable(result, '${workspaceFolder}', () => getCurrentWorkspaceFolder()?.uri.fsPath);
32-
result = substituteVariable(result, '${fileWorkspaceFolder}', () => getActiveFileWorkspaceFolder()?.uri.fsPath);
33-
result = substituteVariable(result, '${fileDirname}', () => {
34-
const activeFilePath = vscode.window.activeTextEditor?.document.uri.fsPath;
35-
if (activeFilePath) {
36-
return path.dirname(activeFilePath);
37-
}
38-
});
39-
30+
if (str.includes('${')) {
31+
result = substituteVariable(result, '${userHome}', () => homedir());
32+
result = substituteVariable(result, '${workspaceFolder}', () => getCurrentWorkspaceFolder()?.uri.fsPath);
33+
result = substituteVariable(result, '${fileWorkspaceFolder}', () => getActiveFileWorkspaceFolder()?.uri.fsPath);
34+
result = substituteVariable(result, '${fileDirname}', () => {
35+
const activeFilePath = vscode.window.activeTextEditor?.document.uri.fsPath;
36+
if (activeFilePath) {
37+
return path.dirname(activeFilePath);
38+
}
39+
});
40+
}
4041
return result;
4142
}
4243

0 commit comments

Comments
 (0)