Handle modulepath: file imports
#120
Open
+16
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for resolving
modulepath:URIs using the module paths declared in aPklProject'sevaluatorSettings, as the CLI does. This is a different approach than #93, which instead adds an LSP setting for these paths. Let me know if you'd prefer that approach over usingevaluatorSettings.modulePath. I thought that using the standardPklProjectsetting may avoid a bit of editor setup for users and allow the LSP to match the CLI's behavior more closely.This is my first time writing Kotlin, so please tell me if there's a better way of expressing this code. In particular, I can't tell if a more functional or imperative style is typical here.
My use case for this is to have workspace root-relative imports for generated Pkl files in Bazel. As a demonstration, here is the behavior of
pkl-vscode(v0.21.0, unchanged) before and after this patch topkl-lsp, with the followingPklProject:Before ("Cannot resolve import" error on

amends):After ("Go to definition" jumpts to

Example.pklwithinbazel-bin):This does not completely implement
modulepath:, as it makes no attempt to read files within JARs or Zip files, which the spec (and CLI) supports.Closes #91.