Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should distinguish between *.d.rhai and *.rhai #77

Open
schungx opened this issue Jul 31, 2022 · 13 comments
Open

Should distinguish between *.d.rhai and *.rhai #77

schungx opened this issue Jul 31, 2022 · 13 comments

Comments

@schungx
Copy link
Collaborator

schungx commented Jul 31, 2022

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:

image
image

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:

//! @RHAI-DEF-FILE
@schungx
Copy link
Collaborator Author

schungx commented Jul 31, 2022

I wonder why this same thing doesn't happen under the examples/definitions foler:

image

Is it because of the magic .rhai directory?

@tamasfe
Copy link
Member

tamasfe commented Jul 31, 2022

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.

@tamasfe
Copy link
Member

tamasfe commented Jul 31, 2022

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" ]

@schungx
Copy link
Collaborator Author

schungx commented Jul 31, 2022

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.

@tamasfe
Copy link
Member

tamasfe commented Jul 31, 2022

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"
  },

@schungx
Copy link
Collaborator Author

schungx commented Jul 31, 2022

DEBUG initialized: found file path="c:/Git/rhai/examples/definitions/.rhai"
ERROR initialized: failed to read file error=Access is denied. (os error 5)

@tamasfe
Copy link
Member

tamasfe commented Jul 31, 2022

I see, I did not check whether the path is a directory, whoops.

@schungx
Copy link
Collaborator Author

schungx commented Jul 31, 2022

Also, I see slightly strange behavior.

Firstly, whenever the LSP is run, it successfully finds undeclared variables.

image

However, when I click open that file in the editor, all errors go away:

image

image

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.

@tamasfe
Copy link
Member

tamasfe commented Jul 31, 2022

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?

@schungx
Copy link
Collaborator Author

schungx commented Jul 31, 2022

Nothing in the logs that show a panic...

@schungx
Copy link
Collaborator Author

schungx commented Aug 1, 2022

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.

@tamasfe
Copy link
Member

tamasfe commented Aug 1, 2022

There is probably a race condition somewhere in the LSP, I'll look into it.

@schungx
Copy link
Collaborator Author

schungx commented Aug 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants