-
Notifications
You must be signed in to change notification settings - Fork 53
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
swarm-lang IDE hover #972
Conversation
6955ebc
to
47e1cd9
Compare
src/Swarm/Language/LSP/Hover.hs
Outdated
explain :: Term -> Text | ||
explain = \case | ||
TUnit -> "The unit value." | ||
TConst c -> briefDoc $ constDoc $ constInfo c |
There was a problem hiding this comment.
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.
ab048d5
to
8f0086d
Compare
There was a problem hiding this 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
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." |
There was a problem hiding this comment.
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.
8f0086d
to
cd7428d
Compare
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) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
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." |
There was a problem hiding this comment.
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.
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. |
Closes #124
To test:
stack install
.sw
file and mouseover some text.