-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Currently the lsp cannot resolve imports from the modulepath (e.g. import "modulepath:/mymodule/somefile.pkl").
It would be nice if a user could somehow provide a local modulepath for the lsp to use for the project (or even package).
Here is our usecase:
In essence we have a system where our pkl files are deployed to locations we do not know beforehand and which are different from the systems they're beeing developed on.
We pass those locations via --modulepath and import the files from there. This works for evaluating, but since the pkl-lsp does not support modulepaths, development is really unpleasant.
We've tried alternatively to instead use packages and import the dependencies there via modulepath:
amends "pkl:Project"
package {
name = "mypackage"
// ...
}
dependencies {
["myotherpackage"] = import("modulepath:/myotherpackage/PklProject")
}The idea here was that if pkl package resolve would write the resulting local path into the PklProject.deps.json, then the lsp could resolve package imports (like import "@mymodule/somefile.pkl") and only the PklProject file would report "Cannot resolve import.".
But it fails because of two reasons:
- the
dependenciesfield has a constraint for these locally importedProjectsprojectFileUris to effectively start with"file://"(here) - the cli tool evaluates
Projects withoutModulePathResolver(here)
The first one can be "worked around" by spoofing the projectFileUri field in the imported Projects:
local spoofedUri: String? = read?("env:MODULE_PATH").ifNonNull((path) -> "file://" + (path as String)
.split(":")
.map((e) -> if (!e.endsWith("/")) e + "/" else e)
.map((e) -> e + module.package.name + "/" + "PklProject")
.find((e) -> read?("file:" + e) != null))
projectFileUri = if (spoofedUri != null) spoofedUri else super.projectFileUriFor the second issue we had to patch the cli tool ourselfs, but after that we got the lsp to resolve these package dependencies by exporting a MODULE_PATH environment variable.
But obviously this isn't ideal.
If you can point me in the right direction I'd be happy to work on a PR. Or if there is another solution we haven't considered yet, please let me know.
We would be fine with writing an external reader if the lsp would support it (which might be easier to implement).
We would also be okay with publishing and fetching packages for development, but when they are deployed we have to use the local files.