languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

Cannot parse xml document with xmlTreeParse

Open qqlearn123 opened this issue 3 years ago • 2 comments

The language server fails to start because it tries to parse an xml file in one of my R package (called xsef) and cannot find xmlTreeParse function.

I am using vscode (v1.72.2), R plugin for vscode (v2.6.0), R (v4.0.3), languageserver (v0.3.13).

The error message is like:


[2022-10-15 12:09:05:322] Error: could not find function "xmlTreeParse" Call: xmlTreeParse(system.file("extdata/xschema.xml", package="xsef")) Stack trace: 1: get(x, envir = ns) 2: FUN(X[[i]], ...) 3: vapply(private$objects, function(x) { is.function(get(x, envir = ns)) }, logical(1L), USE.NAMES = FALSE) 4: initialize(...) 5: PackageNamespace$new(pkgname) 6: self$get_namespace(pkgname) 7: self$load_package(package) 8: self$workspace$load_packages(packages) 9: resolve_callack(self, uri, version, result) 10: private$callback(result) 11: task$check() 12: self$resolve_task_manager$check_tasks() 13: self$process_events()

[2022-10-15 12:09:05:322] exiting


Thanks for your help!

qqlearn123 avatar Oct 15 '22 16:10 qqlearn123

Looks like your package xsef defined a symbol that requires xmlTreeParse on load. Is it possible that we see the source code of xsef or would you like to share the places where you use xmlTreeParse in the package so that we could build a reproducible example?

renkun-ken avatar Oct 16 '22 08:10 renkun-ken

Thanks for your time looking into it.

Yes, it is indeed. There is one R file in my xsef package which have this line in it: .xschema = xmlTreeParse(system.file("extdata/xschema.xml", package="xsef"))

Actually the xsef package depends on the XML package (which have the xmlTreeParse function), but installing and using it independently have no problem for me (since XML is loaded alongside with xsef, maybe??). Not sure how it affects the languageserver's failure to start. Maybe languageserver cannot handle this situation.

My findings so far is that:

  • For scripts which have require(xsef) directly, languageserver fails to start.
  • For scripts which have require(another), where another depends on xsef, languageserver fails to start as well.

Thanks for your help!

qqlearn123 avatar Oct 16 '22 20:10 qqlearn123

When the error occurs, is XML properly installed? Does getNamespace("xsef")$.xschema work properly in your R terminal?

Looks like xsef cannot be loaded in your case.

I create a package that defines the following

but if I remove XML, the error from package loading, not from get(x, envir = ns) as in your case:

[Error - 8:38:17 PM] Request textDocument/completion failed.
  Message: Error: there is no package called 'XML'
Call: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
Stack trace:
1: doWithOneRestart(return(expr), restart)
2: withOneRestart(expr, restarts[[1L]])
3: withRestarts(stop(cond), retry_loadNamespace = function() NULL)
4: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
5: asNamespace(ns)
6: namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, 
    .libPaths()), versionCheck = vI[[j]]), i[[2L]], from = package)
7: loadNamespace(name)
8: getNamespace(ns)
9: asNamespace(pkgname)
10: initialize(...)
11: PackageNamespace$new(pkgname)
12: workspace$get_namespace(nsname)
13: workspace_completion(workspace, token, package, token_result$accessor == 
    "::", snippet_support)
14: completion_reply(id, uri, self$workspace, document, point, self$ClientCapabilities$textDocument$completion)
15: self$deliver(completion_reply(id, uri, self$workspace, document, 
    point, self$ClientCapabilities$textDocument$completion))
16: dispatch(self, id, params)

renkun-ken avatar Oct 17 '22 12:10 renkun-ken

getNamespace("xsef")$.xschema gives me the same error - Error: could not find function "xmlTreeParse"

But, if I just type R and require(xsef), no issues. And, head(.xschema) in R terminal works fine as well.

qqlearn123 avatar Oct 17 '22 15:10 qqlearn123

Is there a solution or workaround to this issue? I tried lazy late loading and use XML:::xmlTreePase, both did not work.

Is it possible that the languageserver just pass through without error out in such scenario?

qqlearn123 avatar Oct 26 '22 02:10 qqlearn123

Would you like to try #582 and see if it works for you?

renkun-ken avatar Oct 26 '22 03:10 renkun-ken

Think the original cause is hard-coded installation path which can be solved by using '--no-staged-install'.

Tried #582, it works now! Thx a lot.

qqlearn123 avatar Oct 26 '22 03:10 qqlearn123