Skip to content

Commit

Permalink
Provide way to specify R path directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Arkhipov committed Jun 28, 2020
1 parent 2685853 commit df4928a
Show file tree
Hide file tree
Showing 19 changed files with 1,242 additions and 507 deletions.
3 changes: 2 additions & 1 deletion src/LanguageServer/Impl/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public Task didChangeConfiguration(JToken token, CancellationToken ct) {
return Task.CompletedTask;
}

settings.Interpreter = GetSetting(r, "interpreter", 0);
settings.InterpreterIndex = GetSetting(r, "interpreter", 0);
settings.InterpreterPath = GetSetting(r, "interpreterPath", string.Empty);

var editor = r["editor"];
settings.Editor.TabSize = GetSetting(editor, "tabSize", 2);
Expand Down
9 changes: 8 additions & 1 deletion src/LanguageServer/Impl/Server/LanguageServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ namespace Microsoft.R.LanguageServer.Server {
///
/// </remarks>
public sealed class LanguageServerSettings {
public int Interpreter { get; set; }
/// <summary>
/// Interpreter index in discovered interpreters.
/// </summary>
public int InterpreterIndex { get; set; }
/// <summary>
/// Path to R installation. Overrides <see cref="InterpreterIndex"/>.
/// </summary>
public string InterpreterPath { get; set; }
public EditorSettings Editor { get; set; } = new EditorSettings();
public LinterSettings Linting { get; set; } = new LinterSettings();
}
Expand Down
11 changes: 10 additions & 1 deletion src/LanguageServer/Impl/Server/RConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Common.Core;
using Microsoft.Common.Core.IO;
using Microsoft.Common.Core.Logging;
using Microsoft.Common.Core.Services;
using Microsoft.R.Components.InteractiveWorkflow;
Expand All @@ -16,6 +18,7 @@
using Microsoft.R.LanguageServer.InteractiveWorkflow;
using Microsoft.R.LanguageServer.Settings;
using Microsoft.R.Platform.Interpreters;
using Microsoft.R.Platform.Windows.Interpreters;

namespace Microsoft.R.LanguageServer.Server {
/// <summary>
Expand Down Expand Up @@ -86,6 +89,12 @@ private async Task ConnectAsync(CancellationToken ct) {
public void Dispose() => _workflow?.Dispose();

private IRInterpreterInfo GetREngine() {
var rs = _services.GetService<IREngineSettings>();
if (!string.IsNullOrEmpty(rs.InterpreterPath)) {
_ui.LogMessageAsync($"Using interpreter at '{rs.InterpreterPath}']", MessageType.Info).DoNotWait();
return new RInterpreterInfo("R", rs.InterpreterPath, _services.GetService<IFileSystem>());
}

var ris = _services.GetService<IRInstallationService>();
var engines = ris
.GetCompatibleEngines(new SupportedRVersionRange(3, 2, 4, 9))
Expand All @@ -103,8 +112,8 @@ private IRInterpreterInfo GetREngine() {
_ui.LogMessageAsync($"\t[{i}] {engines[i].Name}", MessageType.Info).DoNotWait();
}
_ui.LogMessageAsync("You can specify the desired interpreter index in the R settings", MessageType.Info).DoNotWait();
_ui.LogMessageAsync("Of provide path to R using `r.interpreterPath` setting.", MessageType.Info).DoNotWait();

var rs = _services.GetService<IREngineSettings>();
if (rs.InterpreterIndex < 0 || rs.InterpreterIndex > engines.Count) {
_ui.ShowMessageAsync($"Selected interpreter [{rs.InterpreterIndex}] does not exist. Using [0] instead", MessageType.Warning).DoNotWait();
rs.InterpreterIndex = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/LanguageServer/Impl/Server/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void UpdateSettings(LanguageServerSettings vscodeSettings) {
_editorSettings.LintOptions = vscodeSettings.Linting;
_editorSettings.RaiseChanged();

_engineSettings.InterpreterIndex = vscodeSettings.Interpreter;
_engineSettings.InterpreterIndex = vscodeSettings.InterpreterIndex;
_engineSettings.InterpreterPath = vscodeSettings.InterpreterPath;

SettingsChanged?.Invoke(this, EventArgs.Empty);
}
Expand All @@ -57,6 +58,7 @@ public void UpdateSettings(LanguageServerSettings vscodeSettings) {
#pragma warning disable 67
private sealed class REngineSettings : IREngineSettings {
public int InterpreterIndex { get; set; }
public string InterpreterPath { get; set; }
}

private sealed class REditorSettings : IREditorSettings {
Expand Down
1 change: 1 addition & 0 deletions src/LanguageServer/Impl/Settings/IREngineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
namespace Microsoft.R.LanguageServer.Settings {
public interface IREngineSettings {
int InterpreterIndex { get; set; }
string InterpreterPath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RInterpreterInfo(string name, string path, IFileSystem fileSystem) {
_fileSystem = fileSystem;
Name = name;
InstallPath = NormalizeRPath(path);
BinPath = Path.Combine(path, @"bin\x64");
BinPath = Path.Combine(path, "bin", "x64");
Version = DetermineVersion();
DocPath = Path.Combine(path, "doc");
IncludePath = Path.Combine(path, "include");
Expand Down
6 changes: 6 additions & 0 deletions src/VSCode/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/dist/**
**/out/**
**/node_modules/**
**/client/server/**
**/extension/server/**
**/tests/fourslash/**
37 changes: 37 additions & 0 deletions src/VSCode/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": [
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin",
"simple-import-sort"
],
"rules": {
"eqeqeq": "error",
"no-constant-condition": 0,
"no-inner-declarations": 0,
"no-undef": 0,
"simple-import-sort/sort": "error",
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-use-before-define": 0
}
}
8 changes: 8 additions & 0 deletions src/VSCode/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.json
**/pyright/**/*.md
**/dist/**
**/out/**
**/client/server/**
**/extension/server/**
**/typeshed-fallback/**
**/bundled-stubs/**
15 changes: 15 additions & 0 deletions src/VSCode/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"singleQuote": true,
"tabWidth": 4,
"useTabs": false,
"printWidth": 120,
"endOfLine": "auto",
"overrides": [
{
"files": ["*.yml", "*.yaml"],
"options": {
"tabWidth": 2
}
}
]
}
6 changes: 6 additions & 0 deletions src/VSCode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.0.9 (28 June 2020)

### Updates

1. Provide `r.interpreterPath` manual setting for cases when R does not get discovered automatically.

## 0.0.8 (01 May 2020)

### Updates
Expand Down
15 changes: 12 additions & 3 deletions src/VSCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ Use `R: Execute line or selection` commands to execute line or selection in the
R session in the editor does not automatically pick up new packages installed in the terminal. You may have to reload the window for the session to pick up newly installed modules.

## Troubleshooting
- **.NET Core not found** You can bypass .NET Core check by setting `dependencyChecks` setting to false.
- **Launching server using command dotnet failed.**. Most probably libzip is missing and extensions was unable to install it. Try installing [Homebrew](https://brew.sh/), then run `brew install libzip`.
- **R Interpreter not found**
**.NET Core not found**

You can bypass .NET Core check by setting `dependencyChecks` setting to false.

**Launching server using command dotnet failed.**.

Most probably libzip is missing and extensions was unable to install it. Try installing [Homebrew](https://brew.sh/), then run `brew install libzip`.

**R Interpreter not found**

Try using `r.intepreterPath` setting and specify path to R installation. The path should be root folder, like `C:\Program Files\R\R-3.4.3`, without `bin/x64`.

The broker (ASP.NET Core process) is configurable via `Microsoft.R.Host.Broker.Config.json`. Example:
```
"r":{"autoDetect":"<true|false>"}
Expand Down
Loading

0 comments on commit df4928a

Please sign in to comment.