-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
(require)
does not load ns from user script dir
#38
Comments
Thanks for this issue, @bobisageek! Is there something from the discussion on Slack that we should bring in here as well? For the benefit of whomever wants to tackle this. |
My initial motivation was that I might have a number of functions that I want to re-use across workspaces (e.g. convenience functions around the VSCode API). borkdude made a great point, which is that there are interesting decisions around the relationship between workspace scripts and user scripts. On one hand, the initial desire is to require user scripts from workspace scripts. But, workspace scripts can presumably be shared between users of a workspace, and other users might not have those same user scripts, which means the workspace scripts are potentially broken/incomplete in the context of another user. So, the superficial ask is to search both paths for scripts to
|
I just ran across this trying to add an example User The keybinding can be done like so: {
"key": "cmd+f4",
"command": "joyride.runCode",
"args": "(require '[promesa.core :as p]) (p/do (vscode/commands.executeCommand \"calva.clojureLsp.stop\") (vscode/commands.executeCommand \"calva.clojureLsp.start\"))"
}, I want to do it like so: {
"key": "cmd+f4",
"command": "joyride.runCode",
"args": "(my-lib/restart-clojure-lsp)"
}, Because in For this my plan was to have this in User (ns activate
(:require ...
[my-lib]
...)) And the following User (ns my-lib
(:require ["vscode" :as vscode]
[promesa.core :as p]))
(defn restart-clojure-lsp []
(p/do (vscode/commands.executeCommand "calva.clojureLsp.stop")
(vscode/commands.executeCommand "calva.clojureLsp.start"))) But... running the User
|
I was playing around with this a little bit today, and I had an idea, but I'm not sure if I actually like it, or if it's just appealing because it's sort of novelty. The basic jist is that With just this much, there's a sort of unrecoverable situation - a script with the same name in both the user and workspace directories means we can't require either. The idea that I'm not sure if I like or not is allowing for constraining the search with
Requiring a script To borkdude's original point, this still leaves open the possibility of scripts breaking with sharing - a workspace script that requires a user script will break (or even worse, have different semantics) when run by a different user. With that said, it allows people to "cross the streams" if they're the only one using the workspace, to require user scripts from user scripts, and to constrain the 'load path' to prevent/fix the situation where there's a user script and a workspace script with the same name. There is a very experimental implementation of this in bobisageek@d4b8256. This is not heavily tested and probably not real-world ready - just a proof of concept for feedback on the general idea. Tangentially, there's a change to config.cljs in that commit that I think might be generally helpful - |
I'll have a closer look tomorrow, but even a quick read made me curious. Sounds very interesting. I've fixed that deref bug in #60, btw. It messed with me something crazy! |
About We could just go with detecting the conflict and giving up with an error complaint. Then the user can solve it by renaming one or the other namespace. A nice thing with this approach to not try to prioritize the ”current” script section, is that it will work when there is no such current section. Like in my example above, where the |
Please not! :) After having thought about this more, I think we should simply do this: The "classpath" order is workspace:user. So if you require and the namespace is available in the workspace, we load that. The workspace namespace overrides the user namespace. If it isn't there, we load the user script. That's pretty much how you would expect it in normal Clojure too: project-local code first, then global code (in Yes, this could lead to conflicts, but let's trust the user that they will take that upon themselves (like you can have conflicts in |
I like it. It also takes care of the Want to PR it, @bobisageek? |
The transition to promise chaining is frying my brain a little bit, so you might be able to knock it out more quickly (and better). I'll keep playing around in the meanwhile. |
Wait... we don't have to transition to chaining promises. Where did that come from? |
Well, moving into promise land, anyway. I think using vscode's |
I don't see that as part of this issue, let's keep the scope of this issue to the require + workspace + user dir problem. |
Unless I'm missing a detail here. Do you mean that you want to read a file but vscode will only let you do this asynchronously? Then how were we doing this before? |
I was basing that off this: We were (essentially) constructing a path and if it didn't exist, that failed in VSCode-space. The experimental implementation checks for existence (using node's synchronous |
If we're going to do that, then we would need to move to https://github.com/babashka/sci/blob/master/doc/async.md which is way beyond what this issue is about. |
We will need to do it eventually. But I agree the current issue is not about the |
@PEZ Sounds good. I think that would be an issue for me to work on, so I can co-develop the SCI async API while doing that. |
Issue created: So we agree that when fixing this issue, and checking for file existence, we continue to do it with the sync tools from node |
Sorry about the delay - I got distracted with lunch. A first cut of a PR is in so we maybe have a baseline upon which to improve. |
* add user script directory to search paths of 'require' Fixes #38
OS: Windows 10
Joyride version: 0.0.7
Repro:
$HOME/.config/joyride/scripts/user_lib.cljs
$workspaceRoot/.joyride/scripts/ws_caller.cljs
Executing just the ws_caller script reports:
ERROR: Run Workspace Script Failed: ws_caller.cljs ENOENT: no such file or directory, open 'c:\wspath\.joyride\scripts\user_lib.cljs'
Executing user_lib first and then ws_caller works as expected (the information message is displayed).
My initial speculation based on a small amount of knowledge of sci is that if
:load-fn
looked in both paths, that would let users require namespaces/files from either location.joyride/src/main/joyride/sci.cljs
Lines 34 to 44 in a9e29ec
Presumably this would open up ambiguity around the search order, e.g. identically-named files in both places would lead to a decision needing to be made about which one(s) to load, potentially based on whether a ws or user script is being run.
The text was updated successfully, but these errors were encountered: