Open schungx opened 2 years ago
I wonder why this same thing doesn't happen under the examples/definitions
foler:
Is it because of the magic .rhai
directory?
Definitions now always have to start with module
(apart from comments/whitespace). The api/definitions
are not valid definitions, they are there to be included in Rust code, then module
is prepended to them depending on what the user wants to do with them.
Also we could silence the errors by placing a Rhai.toml
in the root of the project that restricts the LSP to a specific set of rhai files:
[source]
include = [ "scripts/**/*.rhai" ]
Putting in Rhai.toml
yields this:
INFO created workspace root=root:///
INFO LSP server listening transport="stdio"
INFO initialize: created workspace root=file:///c%3A/Git/rhai
INFO initialized: found Rhai.toml path="c:/Git/rhai\\Rhai.toml"
INFO initialized: found files count=39 excluded=0
ERROR initialized: failed to read file error=Access is denied. (os error 5)
There is probably an extra backslash... or should it be a forward slash instead? Windows should read forward-slash paths just fine.
The path should be fine like that, it's something else. The error message is not too helpful.
Maybe decreasing the log level could help a bit?
// vscode settings.json
"rhai.executable.environment": {
"RUST_LOG": "debug"
},
DEBUG initialized: found file path="c:/Git/rhai/examples/definitions/.rhai"
ERROR initialized: failed to read file error=Access is denied. (os error 5)
I see, I did not check whether the path is a directory, whoops.
Also, I see slightly strange behavior.
Firstly, whenever the LSP is run, it successfully finds undeclared variables.
However, when I click open that file in the editor, all errors go away:
With no definitions, the scope variables bool_state
, value
etc. should all flag errors.
I'm sure it did originally, but only until the file is open; then it no longer flag those errors.
I'm sure it did originally, but only until the file is open; then it no longer flag those errors.
I suspect a panic, what is in the logs?
Nothing in the logs that show a panic...
Restarted VScode, and the problem seems to have gone away -- strange, as I restarted before and it persists.
Now it correctly flags the undeclared variables.
There is probably a race condition somewhere in the LSP, I'll look into it.
Restarted VScode, and the problem seems to have gone away -- strange, as I restarted before and it persists.
Just a hunch. The situation disappeared once I excluded the api/definitions
from LSP using Rhai.toml
.
Currently, it seems that files with
.d.rhai
extension are treated the same as Rhai script files instead of LSP definition files.This makes, for example, some Rhai code with definition files come back with parse errors. For example, in the
definitions
API folder:The solution is to treat
*.d.rhai
as definition files automatically.Or require all definition files to have some magic doc comment at the top? For example: