REditorSupport / languageserver

An implementation of the Language Server Protocol for R
Other
581 stars 93 forks source link

Daignostics failed on all .R files #448

Open ericnewkirk opened 3 years ago

ericnewkirk commented 3 years ago

Suddenly linting has failed completely for me in vscode. I've tried several approaches to finding the source of the problem, but I can't reproduce it. This occurs in workspaces with and without a .RProject file or .lintr file, in all R files. The languageserver seems to fire up fine and other features such as hints on hover work fine. With extension debugging turned on the error in the output is:

[2021-07-01 10:53:43.405] diagnostics_task: <callr_status_error: callr subprocess failed: cannot open the connection>
 in process 
-->
<callr_remote_error in gzfile(file, "wb"):
 cannot open the connection>
 in process 676 

[2021-07-01 10:53:43.405] diagnostics_callback called: {
  "uri": "file:///c:/Users/Me/Documents/GitHub/MyPackage/R/utils-pipe.R",
  "version": 1
}

I've dug through callr and processx for clues but I don't see anything. I've also tried debugging in RStudio and found that lintr calls gzfile via a long traceback in places, but I only see calls with "rb" as the second argument. Even more strange, I can run the following in vscode and no error occurs:

# create a separate r process
# https://github.com/REditorSupport/languageserver/blob/master/R/session.R#L75
session <- callr::r_session$new(
                callr::r_session_options(
                    system_profile = TRUE, user_profile = TRUE, supervise = TRUE),
                # skip waiting
                wait = FALSE
            )
# read session so it's ready
sess_ready <- session$read()
while (is.null(sess_ready)) {
    sess_ready <- session$read()
}

# run lintr::find_config
# https://github.com/REditorSupport/languageserver/blob/master/R/diagnostics.R#L70
path <- "./R/utils-pipe.R"
target <- function(path) {asNamespace("lintr")$find_config(path)}
args <- list(path)
ret <- session$call(target, args)
lintr_config <- session$read()
while (is.null(lintr_config)) {
    lintr_config <- session$read()
}
# returns NULL without .lintr file, path with .lintr file

# run same function directly with :::
target <- function(path) {lintr:::find_config(path)}
ret <- session$call(target, args)
lintr_config <- session$read()
while (is.null(lintr_config)) {
    lintr_config <- session$read()
}
# same result as above, no error

# run lintr::lint
# https://github.com/REditorSupport/languageserver/blob/master/R/diagnostics.R#L99
target <- function(path, cache = FALSE, text = NULL) {lintr::lint(path)}
ret <- session$call(target, args)
lints <- session$read()
while (is.null(lints)) {
    lints <- session$read()
}
# returns list of lints, no error

args <- list(path, cache = TRUE)
ret <- session$call(target, args)
lints <- session$read()
while (is.null(lints)) {
    lints <- session$read()
}
# same, no error

rl <- readLines(path)
args <- list(path, text = rl)
ret <- session$call(target, args)
lints <- session$read()
while (is.null(lints)) {
    lints <- session$read()
}
# still no error

session$close()
rm(session, sess_ready, target, args, lintr_config, lints, rl)
gc()

Here's some additional system info from languageserver startup in case there's anything there:

[2021-07-01 10:53:40.710] session:  {
  "system": {
    "sysname": "Windows",
    "release": "10 x64",
    "version": "build 19043",
    "nodename": "DESKTOP-MyPC",
    "machine": "x86-64",
    "login": "Me",
    "user": "Me",
    "effective_user": "Me"
  },
  "pid": 4456,
  "wd": "c:/Users/Me/Documents/GitHub/MyPackage",
  "args": ["C:\\PROGRA~1\\R\\R-40~1.3/bin/x64/Rterm.exe", "--quiet", "--slave", "-e", "languageserver::run(port=51084,debug=TRUE)"],
  "ver": {
    "platform": "x86_64-w64-mingw32",
    "arch": "x86_64",
    "os": "mingw32",
    "system": "x86_64, mingw32",
    "status": "",
    "major": "4",
    "minor": "0.3",
    "year": "2020",
    "month": "10",
    "day": "10",
    "svn rev": "79318",
    "language": "R",
    "version.string": "R version 4.0.3 (2020-10-10)",
    "nickname": "Bunny-Wunnies Freak Out"
  },
  "locale": "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252",
  "env": {
    "ALLUSERSPROFILE": "C:\\ProgramData",
    "APPDATA": "C:\\Users\\Me\\AppData\\Roaming",
    "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true",
    "CHROME_CRASHPAD_PIPE_NAME": "\\\\.\\pipe\\crashpad_12144_LFSLUOCQWHIKMJGR",
    "CommonProgramFiles": "C:\\Program Files\\Common Files",
    "CommonProgramFiles(x86)": "C:\\Program Files (x86)\\Common Files",
    "CommonProgramW6432": "C:\\Program Files\\Common Files",
    "COMPUTERNAME": "DESKTOP-MyPC",
    "ComSpec": "C:\\WINDOWS\\system32\\cmd.exe",
    "CUDA_PATH": "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.0",
    "CUDA_PATH_V10_2": "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2",
    "CUDA_PATH_V11_0": "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.0",
    "DriverData": "C:\\Windows\\System32\\Drivers\\DriverData",
    "ELECTRON_RUN_AS_NODE": "1",
    "HOME": "C:\\Users\\Me\\Documents",
    "HOMEDRIVE": "C:",
    "HOMEPATH": "\\Users\\Me",
    "LANG": "en_US.UTF-8",
    "LOCALAPPDATA": "C:\\Users\\Me\\AppData\\Local",
    "LOGONSERVER": "\\\\DESKTOP-MyPC",
    "MSMPI_BENCHMARKS": "C:\\Program Files\\Microsoft MPI\\Benchmarks\\",
    "MSMPI_BIN": "C:\\Program Files\\Microsoft MPI\\Bin\\",
    "MSYS2_ENV_CONV_EXCL": "R_ARCH",
    "NUMBER_OF_PROCESSORS": "12",
    "NVCUDASAMPLES_ROOT": "C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v11.0",
    "NVCUDASAMPLES10_2_ROOT": "C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v10.2",
    "NVCUDASAMPLES11_0_ROOT": "C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v11.0",
    "NVTOOLSEXT_PATH": "C:\\Program Files\\NVIDIA Corporation\\NvToolsExt\\",
    "OneDrive": "C:\\Users\\Me\\OneDrive",
    "OneDriveConsumer": "C:\\Users\\Me\\OneDrive",
    "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined",
    "OS": "Windows_NT",
    "PATH": "C:\\Program Files\\Microsoft MPI\\Bin\\;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.0\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.0\\libnvvp;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\libnvvp;C:\\Program Files\\Python36\\Scripts\\;C:\\Program Files\\Python36\\;C:\\Rtools\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\130\\DTS\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\dotnet\\;C:\\Users\\Me\\AppData\\Local\\Programs\\Python\\Python38;C:\\Users\\Me\\AppData\\Local\\Programs\\Python\\Python38\\Scripts;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\NVIDIA Corporation\\Nsight Compute 2020.1.0\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft SQL Server Migration Assistant for Access\\bin\\;C:\\Program Files\\Azure Data Studio\\bin;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\Program Files\\PuTTY\\;C:\\Program Files (x86)\\dotnet\\;C:\\Program Files\\gs\\gs9.53.3\\bin;C:\\Users\\Me\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Me\\AppData\\Local\\GitHubDesktop\\bin;C:\\Program Files\\JetBrains\\PyCharm Community Edition with Anaconda plugin 2019.3.1\\bin;;C:\\Users\\Me\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Me\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Azure Data Studio\\bin;C:\\Users\\Me\\AppData\\Roaming\\TinyTeX\\bin\\win32;C:\\Program Files\\gs\\gs9.53.3\\bin;",
    "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW",
    "PROCESSOR_ARCHITECTURE": "AMD64",
    "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 158 Stepping 10, GenuineIntel",
    "PROCESSOR_LEVEL": "6",
    "PROCESSOR_REVISION": "9e0a",
    "ProgramData": "C:\\ProgramData",
    "ProgramFiles": "C:\\Program Files",
    "ProgramFiles(x86)": "C:\\Program Files (x86)",
    "ProgramW6432": "C:\\Program Files",
    "PROMPT": "$P$G",
    "PSModulePath": "C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules;C:\\Program Files (x86)\\Microsoft SQL Server\\130\\Tools\\PowerShell\\Modules\\;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\Tools\\PowerShell\\Modules\\",
    "PUBLIC": "C:\\Users\\Public",
    "PyCharm Community Edition with Anaconda plugin": "C:\\Program Files\\JetBrains\\PyCharm Community Edition with Anaconda plugin 2019.3.1\\bin;",
    "R_ARCH": "/x64",
    "R_COMPILED_BY": "gcc 8.3.0",
    "R_HOME": "C:/PROGRA~1/R/R-40~1.3",
    "R_LIBS_USER": "C:\\Users\\Me\\Documents/R/win-library/4.0",
    "R_USER": "C:\\Users\\Me\\Documents",
    "RTOOLS40_HOME": "C:\\rtools40",
    "SESSIONNAME": "Console",
    "SystemDrive": "C:",
    "SystemRoot": "C:\\WINDOWS",
    "TEMP": "C:\\Users\\Me\\AppData\\Local\\Temp",
    "TMP": "C:\\Users\\Me\\AppData\\Local\\Temp",
    "USERDOMAIN": "DESKTOP-MyPC",
    "USERDOMAIN_ROAMINGPROFILE": "DESKTOP-MyPC",
    "USERNAME": "Me",
    "USERPROFILE": "C:\\Users\\Me",
    "VS140COMNTOOLS": "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\",
    "VSCODE_AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess",
    "VSCODE_CWD": "C:\\Users\\Me\\AppData\\Local\\Programs\\Microsoft VS Code",
    "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true",
    "VSCODE_IPC_HOOK": "\\\\.\\pipe\\4a3da3e4ad5f05958243fde888ceebf5-1.57.1-main-sock",
    "VSCODE_IPC_HOOK_EXTHOST": "\\\\.\\pipe\\vscode-ipc-45d10d6e-41d9-46d5-b896-eb8c408c756c-sock",
    "VSCODE_LOG_NATIVE": "false",
    "VSCODE_LOG_STACK": "false",
    "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}",
    "VSCODE_NODE_CACHED_DATA_DIR": "C:\\Users\\Me\\AppData\\Roaming\\Code\\CachedData\\507ce72a4466fbb27b715c3722558bb15afa9f48",
    "VSCODE_PID": "12144",
    "VSCODE_PIPE_LOGGING": "true",
    "VSCODE_VERBOSE_LOGGING": "true",
    "windir": "C:\\WINDOWS",
    "ZES_ENABLE_SYSMAN": "1"
  },
  "namespaces": {
    "processx": "3.5.2",
    "compiler": "4.0.3",
    "R6": "2.5.0",
    "graphics": "4.0.3",
    "parallel": "4.0.3",
    "tools": "4.0.3",
    "collections": "0.3.5",
    "utils": "4.0.3",
    "grDevices": "4.0.3",
    "stats": "4.0.3",
    "datasets": "4.0.3",
    "xml2": "1.3.2",
    "stringi": "1.6.2",
    "callr": "3.7.0",
    "methods": "4.0.3",
    "jsonlite": "1.7.2",
    "ps": "1.6.0",
    "base": "4.0.3",
    "languageserver": "0.3.10"
  },
  "search": [".GlobalEnv", "package:stats", "package:graphics", "package:grDevices", "package:utils", "package:datasets", "package:methods", "Autoloads", "package:base"]
}
randy3k commented 3 years ago

I have seen this issue on CI testing and it is caused by the fact that we have enabled lint cache by default. The current master branch has disabled it by default. We could try installing it from GitHub. The setting options(languageserver.lint_cache = FALSE) may also work in the current CRAN release

ericnewkirk commented 3 years ago

Thanks @randy3k!

I added

options(languageserver.lint_cache = FALSE)

to my .RProfile before the language server is started and everything works again.

randy3k commented 3 years ago

Ya, I only found the cause, but I couldn't understand why it fails. Even strangely, I observed this issue on Linux CI, not Windows.

renkun-ken commented 3 years ago

Are you using the latest dev of lintr? Could you try using the latest dev?

ericnewkirk commented 3 years ago
> devtools::install_github("jimhester/lintr") 
Skipping install of 'lintr' from a github remote, the SHA1 (387b939b) has not changed since last install.
  Use `force = TRUE` to force installation