Skip to content
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

Use cljs for state #1053

Merged
merged 30 commits into from
Mar 10, 2021
Merged

Use cljs for state #1053

merged 30 commits into from
Mar 10, 2021

Conversation

bpringe
Copy link
Member

@bpringe bpringe commented Mar 3, 2021

What has Changed?

  • Adds cljs state namespace to be used for ephemeral state, in place of Immutable.js
  • Moves some things out of state.ts, but ultimately I left the rest as I want to keep these changes as minimal as possible. There are already enough other changes 😄
  • Moves some things out of namespace.ts into a new repl-session.ts. This was to avoid the cljs lib issue noted below, before I found a workaround, but I think the changes make sense so I left them.

The cljs lib issue

In two files that I've seen so far, annotations.ts and namespace.ts, if we import the cljs lib directly and call functions from it, during runtime we get an error that the function is not defined, even though they work in many other files. If we bundle the extension for release and run the vsix, it works fine. Something is not being linked correctly, but I have not figured out the root of the issue.

The workaround

I've found that if we export the cljs lib from utilities.ts, then import it from utilities.ts in those troublesome files noted above, the function calls work fine during runtime. I tried to make a separate cljs-lib.ts and import+export it from there, then import the lib from that module, but again it doesn't work. Since I know it works from the utilities module I left that workaround in place for now.

Maybe later we can figure out the root issue, but at some point it might not matter anyway. In the meantime I'm not sure if we should make all imports of the cljs lib come from the utilities module just to be safe. There are many places in the code where we call functions from the cljs lib now since we use it for state, and I haven't yet verified every single one of those calls works. If we discover some don't, we can switch it to be imported from the utilities module.

Closes #1052

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Tested the VSIX built from the PR (so, after you've submitted the PR). You'll find the artifacts by clicking Show all checks in the CI section of the PR page, and then Details on the ci/circleci: build test. NB: There is a CircleCI bug that makes the Artifacts hard to find. Please see this issue for workarounds.
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
    • Smoke tested the extension as such.
  • Referenced the issue I am fixing/addressing in a commit message for the pull request.
    • If I am fixing the issue, I have used GitHub's fixes/closes syntax
    • If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
  • Created the issue I am fixing/addressing, if it was not present.
  • Added to or updated docs in this branch, if appropriate

The Calva Team PR Checklist:

Before merging we (at least one of us) have:

  • Made sure the PR is directed at the dev branch (unless reasons).
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and tested it there if so.
  • Read the source changes.
  • Given feedback and guidance on source changes, if needed. (Please consider noting extra nice stuff as well.)
  • Tested the VSIX built from the PR (well, if this is a PR that changes the source code.)
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
    • Smoke tested the extension as such.
  • If need be, had a chat within the team about particular changes.

Ping @PEZ, @kstehn, @cfehse, @bpringe

@bpringe
Copy link
Member Author

bpringe commented Mar 4, 2021

@PEZ I'm having a pretty odd issue that I can't yet figure out. It seems that any function from the cljs-lib called inside the namespace.ts function updateREPLSessionType throws an error on Calva loading like:

Activating extension 'betterthantomorrow.calva' failed: parseForms is not a function.

This originally was happening for the new getStateValue function, so I thought I did something wrong, so then I started trying things and noticed I can call that function right at the beginning of the extension.ts activate function and it works fine, but if I call it from that namespace.ts function I get that error. Something about it being called from that location / point in time is causing the issue.

This branch has my troubleshooting code with just minimal changes from dev. If you could take a look and see if you see anything obvious that would be great. This is really odd to me, especially since parseForms is called elsewhere in that file, and that's been that way. 🤔

@bpringe
Copy link
Member Author

bpringe commented Mar 4, 2021

You can see in the Log (Extension Host) output the stack trace of the error when trying it out. I also noticed that if I move the calls to the cljs functions up one level in the call stack to state.ts/update (here), they work fine. So that seems to narrow it down more to being something about namespace.ts that throws off the execution of the cljs-lib functions.

@bpringe
Copy link
Member Author

bpringe commented Mar 5, 2021

This is really odd. If I copy all of namespace.ts into another file, namespace2.ts, and I change the status.ts update function to this:

function update(context = state.extensionContext) {
    vscode.commands.executeCommand('setContext', 'calva:showReplUi', shouldshowReplUi(context));
    namespace2.updateREPLSessionType();
    //namespace.updateREPLSessionType();
    statusbar.update(context);
}

The call to getStateValue in updateREPLSessionType works, but then if I go and update all imports of namespace to namespace2 instead, the call fails again.

Activating extension 'betterthantomorrow.calva' failed: cljs_lib_1.getStateValue is not a function.

@bpringe
Copy link
Member Author

bpringe commented Mar 5, 2021

Just noticed it works fine when I package it as a vsix and install it, it just doesn't work in dev 🤔. Must be something weird with bundling/compiling going on.

@bpringe
Copy link
Member Author

bpringe commented Mar 5, 2021

Just want to add here that this problem occurs even on dev, without any of this new cljs state stuff added, so it's not anything caused by that, at least. If you call parseForms in namespace.ts/updateREPLSessionType, it throws a similar error to one mentioned above, saying that parseForms is not a function.

Refactor calls to update repl session type to use new function.
@bpringe
Copy link
Member Author

bpringe commented Mar 5, 2021

@PEZ I've worked around the above issue by a little refactoring. I also posted an issue in the shadow repo about it to see if Thomas has any insights, but I think we can move forward now.

If you wouldn't mind looking over these changes and letting me know if you'd like any changes that would be great. Definitely want to test this a good bit before merging.

I also still need to split up the state module / refactor it into other modules. I don't plan to change the code there though. I want to change as little as needed for this PR, but I think leaving the state.ts module named / grouped as it is could be misleading.

@bpringe bpringe changed the title WIP - Use cljs for state Use cljs for state Mar 5, 2021
CHANGELOG.md Outdated Show resolved Hide resolved
src/calva-fmt/src/extension.ts Outdated Show resolved Hide resolved
src/config.ts Outdated Show resolved Hide resolved
src/extension.ts Outdated Show resolved Hide resolved
src/repl-session.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@PEZ PEZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great stuff. I have a few nitpicks, that's all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants