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

swarm-lang IDE hover #972

Merged
merged 3 commits into from
Jan 7, 2023
Merged

swarm-lang IDE hover #972

merged 3 commits into from
Jan 7, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Jan 7, 2023

Closes #124

To test:

  1. stack install
  2. Close and re-open VS Code
  3. Open a .sw file and mouseover some text.

@kostmo kostmo force-pushed the swarmlang-ide-hover branch 2 times, most recently from 6955ebc to 47e1cd9 Compare January 7, 2023 07:28
explain :: Term -> Text
explain = \case
TUnit -> "The unit value."
TConst c -> briefDoc $ constDoc $ constInfo c
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I utilize the programmatic documentation of TConst. For all of the other terms, I copied and pasted the Haddocks.

@kostmo kostmo force-pushed the swarmlang-ide-hover branch 4 times, most recently from ab048d5 to 8f0086d Compare January 7, 2023 09:24
@kostmo kostmo marked this pull request as ready for review January 7, 2023 09:33
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

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

Looks nice! I can confirm that this also works in emacs.

How hard would it be to also recurse into type annotations (on def or let) and generate a tooltip about the specific type one is hovering on? Right now, if I hover over a type it just says something about def. Feel free to leave that to another PR though.

src/Swarm/Language/LSP/Hover.hs Outdated Show resolved Hide resolved
TRef {} -> "A memory reference. These likewise never show up in surface syntax but are here to facilitate pretty-printing."
TRequireDevice {} -> "Require a specific device to be installed."
TRequire {} -> "Require a certain number of an entity."
TVar {} -> "A variable."
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's all that useful for it to pop up with "A variable." every time you hover on a variable.

src/Swarm/Language/LSP/Hover.hs Outdated Show resolved Hide resolved
@kostmo kostmo force-pushed the swarmlang-ide-hover branch from 8f0086d to cd7428d Compare January 7, 2023 20:16
TRequire {} -> pure $ pureDoc "Require a certain number of an entity."
TVar x -> pure $ pureDoc $ "var: " <> U.bquote x
SLam {} -> pure $ pureDoc "A lambda expression, with or without a type annotation on the binder."
SApp (Syntax _ t1) (Syntax _ t2) ->
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm now rendering function application as a tree:

f

Copy link
Member

Choose a reason for hiding this comment

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

This seems like overkill to me. It's a lot of information and it's not immediately clear how the nested bullet points correspond to the syntax. What's the intended audience for these hover tips?

Copy link
Member Author

Choose a reason for hiding this comment

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

My original motivation was that when hovering over operators, all it would say about them was "function application". So I wanted to see if I could get a bit more detail out of it, e.g. for ==, now it at least mentions equality:
Screenshot from 2023-01-07 12-36-55

However, for functions of multiple arguments it does get messy. So this is still experimental. I would kind of like to commit the progress on this tree rendering and see if I can wrangle some more useful output from it.

SPair {} -> pure $ pureDoc "A pair."
SDef {} -> pure $ pureDoc "A (recursive) definition command, which binds a variable to a value in subsequent commands."
SBind {} -> pure $ pureDoc "A monadic bind for commands, of the form `c1 ; c2` or `x <- c1; c2`."
SDelay {} -> pure $ pureDoc "Delay evaluation of a term, written `{...}`. Swarm is an eager language, but in some cases (e.g. for `if` statements and recursive bindings) we need to delay evaluation. The counterpart to `{...}` is `force`, where `force {t} = t`. Note that 'Force' is just a constant, whereas 'SDelay' has to be a special syntactic form so its argument can get special treatment during evaluation."
Copy link
Member

Choose a reason for hiding this comment

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

This description probably needs to be cut down a lot.

@kostmo
Copy link
Member Author

kostmo commented Jan 7, 2023

Right now, if I hover over a type it just says something about def. Feel free to leave that to another PR though.

Do you suppose we can merge as is now? There's certainly more iteration to be done, but I think it's at a decent milestone such that others (or me, sometime later) can continue with refinements.

@byorgey
Copy link
Member

byorgey commented Jan 7, 2023

Do you suppose we can merge as is now? There's certainly more iteration to be done, but I think it's at a decent milestone such that others (or me, sometime later) can continue with refinements.

Yes, I think that is reasonable.

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Jan 7, 2023
@mergify mergify bot merged commit 4c2f1e6 into main Jan 7, 2023
@mergify mergify bot deleted the swarmlang-ide-hover branch January 7, 2023 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement language server OnHover handler
2 participants