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

Add markdown formatting to hover messages #1396

Merged
merged 24 commits into from
Jul 27, 2023

Conversation

chioni16
Copy link
Contributor

No description provided.

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@seanyoung
Copy link
Contributor

Rather than caching the rendered text in the hovers structure, is it possible to only render it on demand, i.e. the hovers contains enough information to render the text, but not the rendered text? I guess this would mean storing some sort of enum in the hovers structure.

@chioni16
Copy link
Contributor Author

chioni16 commented Jun 28, 2023

Rather than caching the rendered text in the hovers structure, is it possible to only render it on demand, i.e. the hovers contains enough information to render the text, but not the rendered text? I guess this would mean storing some sort of enum in the hovers structure.

@seanyoung Sure, that should be possible, but with a caveat.
Suppose we need to display the type of a variable in the hover message, here we can't store the Type directly in the enum.
mainly because in order to get the string representation of the type, we need the Namespace struct which may not be available when we want to render the whole enum as a string at the end, right before we send it back to the client.
So, we will. have to store the string version of Type in the enum.
Also storing the whole Type or Parameter struct can be memory intensive. It might be cheaper to store rendered string.
So, all we are doing at the end is to put these individual string components together to form the final hover message that we want to send to the client.

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@@ -1,5 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

#![allow(unstable_name_collisions)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to use the fully qualified syntax itertools::Itertools::intersperse(...) instead of disabling the lint (as clippy suggests)

contents: HoverContents::Scalar(MarkedString::String(
hover.val.to_string(),
)),
// contents: HoverContents::Scalar(MarkedString::String(
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code is almost never kept in the source (if there is a good exception, you can explain in a comment why it should be kept instead).

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@seanyoung
Copy link
Contributor

Struct type definition members do not use markdown:

image

Struct member expression has no hover:

image

Missing hovers for for loops

image

Builtins have non-markdown hovers that a bit ugly.
image

Hovers should really say where a variable is a constant (and what value it has, if it is a constant) or contract variable.

@LucasSte
Copy link
Contributor

LucasSte commented Jul 10, 2023

Builtins have non-markdown hovers that a bit ugly.

We have descriptions for the builtins in builtins.rs. Is our intention to use them in the hovers description box?

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@chioni16
Copy link
Contributor Author

chioni16 commented Jul 11, 2023

  1. Struct type definition members do not use markdown:
    I have added the markdown for this.
  2. Struct member expression has no hover:
    Hovering over struct member expression now displays its type, which is in accordance with the behaviour observed with hovers over variables.
  3. Missing hovers for for loops
    Variable names of length one sometimes don't show hovers. I believe this has to do with the position sent (0 based indexing vs 1 based indexing, perhaps?)
Screenshot 2023-07-11 at 6 55 49 AM
  1. Builtins have non-markdown hovers that a bit ugly.
    I believe this happens only when the solang::sema::builtin::get_prototype function can't find a suitable entry in solang::sema::builtin::BUILTIN_VARIABLE:. Maybe it's better to not display a hover message in such cases? Or display a generic message without the params, return values etc?
  2. Hovers should really say where a variable is a constant (and what value it has, if it is a constant) or contract variable.
    I have added code to display if the variable is a constant / contract variable.
Screenshot 2023-07-11 at 8 40 11 AM Screenshot 2023-07-11 at 8 40 47 AM

But I had some difficulties displaying the constant value. I decided to make use of Namespace::var_constants, which according to the comments

/// For a variable reference at a location, give the constant value
/// This for use by the language server to show the value of a variable at a location

But this doesn't seem to be working as expected.

@chioni16
Copy link
Contributor Author

Builtins have non-markdown hovers that a bit ugly.

We have descriptions for the builtins in builtins.rs. Is our intention to use them in the hovers description box?

We are already making use of solang::sema::builtin::BUILTIN_VARIABLE in builtin.rs. I believe this is what you were referring to.

@chioni16
Copy link
Contributor Author

Variable names of length one sometimes don't show hovers.

This may be due to the fact that the range (start, stop) isn't inclusive on stop. This causes an issue when start equals stop and the find method seems to skip such intervals.
from rust-lapper docs (https://docs.rs/rust-lapper/1.1.0/rust_lapper/):

So [start, stop) is not inclusive of the stop position for neither the queries, nor the Intervals.

I was able to get hovers displayed for variables of length 1 by incrementing the intervals' stop value by 1.

Screenshot 2023-07-11 at 1 07 54 PM

But adding 1 everywhere looks a bit weird.

TL;DR - rust-lapper expects half open ranges (start is included , end is excluded) but we have been passing inclusive ranges (both start and end are included). This discrepancy doesn't cause any problem unless the range is of length 1 (which happens in case of variable names of length 1).

@seanyoung
Copy link
Contributor

seanyoung commented Jul 11, 2023

@chioni16 this is already looking much better. I do have some more observations:

image
The Solidity syntax is uint32 x, uint32 y. x: uint32, y: uint32 is rust syntax (it's nicer, I agree!). There are also unnecessary spaces in the formatting of the function, and it does not include the contract name.

function test.bar(uint32 x, uint32 y) public returns (uint32)

There is also a needless newline between the doc comment and the prototype.

image
The comment/description now follows the definition, rather than before. Also this is not a function, yet we have ( ).

image
Wrong order of comment/description which is also getting incorrect Solidity syntax highlighting. Also unnecessary spacing.

image
What is : c? It's the contract then it would be better to have address c.token. Would be possible to include the constant value?

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@seanyoung
Copy link
Contributor

Single letter variables don't seem to work:
image

Enums give non-markdown hovers
image

Please can you can walk through all Solidity files in docs/ and ensure everything works.

(I do realize there is stuff missing because it's not in the ast, like import statements, but let's make sure that what's in the ast works.)

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
Signed-off-by: Govardhan G D <chioni1620@gmail.com>
@seanyoung seanyoung requested a review from xermicus July 25, 2023 08:51
chioni16 and others added 2 commits July 27, 2023 14:38
@seanyoung seanyoung merged commit d4e8b8f into hyperledger:main Jul 27, 2023
17 checks passed
@seanyoung
Copy link
Contributor

Thanks @chioni16

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.

4 participants