rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
43 stars 4 forks source link

Map paths to import roots in Rhai.toml #80

Open schungx opened 2 years ago

schungx commented 2 years ago

Some users may organize their module scripts directly under the source directory, but resolve them into different paths at runtime.

For example, if we have:

src/
  main.rhai
  modules/
    foo/
      baz/
        main.rhai
    bar/
      main.rhai

During runtime, the user may want imports to work this way:

import "baz" as baz;
import "bar" as bar;

So can something like this be put into Rhai.toml:

[modules]
foo = "./modules/foo"
bar = "./modules/bar"
baz = "./modules/foo/baz"
tamasfe commented 2 years ago

Currently import remapping is not exposed in the HIR, but it is planned.

Maybe we could let the user do it via rhai scripts themselves from the config, what do you think?

schungx commented 2 years ago

Maybe we could let the user do it via rhai scripts themselves from the config, what do you think?

Sort of like a build script? Possible, but I think a bit cumbersome for users. And, in order to provide the flexibility, we'd need to define a complete config API in Rhai.

So maybe something simple that takes the cue from Node and WebPack config options... that might already be enough.