rune-rs / rune

An embeddable dynamic programming language for Rust.
https://rune-rs.github.io
Apache License 2.0
1.75k stars 89 forks source link

Custom Include Path #433

Open SWW13 opened 2 years ago

SWW13 commented 2 years ago

Currently there is no standardized way of bundling own "std" modules written in Rune.

Adding them as additional source files and wrapping the provided functions in a mod-block works as expected for the user. The source can even be compiled into the binary, which makes shipping easy. However the language server is unable to find these modules and all Rune modules have to be compiled during runtime whether they are used or not.

I'm not sure what would be a fitting implementation for Rune, Rhai for example allows to use a custom module loader with arbitrary logic to locate modules.

udoprog commented 2 years ago

Could you elaborate? What is it that you want to work and what did you try to do?

The existing mechanism for overriding how sources are loaded can be specified through Build::with_source_loader. The default implementation used is FileSourceLoader.

SWW13 commented 2 years ago

Oh, totally missed that SourceLoader is a Trait.

That only leaves the question how to integrate a custom SourceLoader with the language server.

udoprog commented 2 years ago

I think only standard included source loaders (possibly configurable) would work with a general purpose language server. Else one would need to provide some way to conveniently build-your-own language server, which wouldn't be that hard either but just a bit inconvenient.

For external definitions, the idea is to support them as through a specific kind of syntax #73, like:

extern "Rust" {
    /// Documentation for function `foo`.
    fn foo();

    /// Documentation for opaque external type `Foo`.
    type Foo;

    /// Documentation for external enum `Bar` with variant `Baz`.
    enum Bar {
        Baz,
    }
}

And so forth... And so forth...