Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add hover #107

Merged
merged 21 commits into from
May 13, 2018
Merged

Add hover #107

merged 21 commits into from
May 13, 2018

Conversation

faustinoaq
Copy link
Member

@faustinoaq faustinoaq commented May 6, 2018

Fixes #103 🎉

Depends on #95 Merged! 🎉

vokoscreen-2018-05-05_20-30-04

This uses crystal tool context to get context information

@faustinoaq
Copy link
Member Author

screenshot_20180505_211014

Makdown content has been enhanced ✨

context.each do |key, value|
contents << "| #{key} | #{value} |"
escaped_value = "`#{value.gsub("|", "∣")}`"
Copy link
Contributor

Choose a reason for hiding this comment

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

is that a special unicode pipe? if yes, can you add a comment saying that (and maybe the unicode code (in hexa) too)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

end

private def vertical_align(contexts)
contents = [] of String
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an IO::Memory instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

private def vertical_align(contexts)
contents = [] of String
contexts.each_with_index do |context, i|
contents << "**Context #{i + 1}**\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is only one context we should hide the Context 1/2/...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

titles_lines = ["| :--- |"] of String
contents_hash = {} of String => Array(String)
contexts.each_with_index do |context, i|
titles << " Type #{i + 1} |"
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@faustinoaq
Copy link
Member Author

faustinoaq commented May 6, 2018

screenshot_20180506_000708

Changed to vertical layout and group per context 🎉

Copy link
Contributor

@bew bew left a comment

Choose a reason for hiding this comment

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

more comments ;)

contexts.each_with_index do |context, i|
contents << "**Context #{i + 1}**\n" if contexts.size > 1
contents << "```crystal\n"
max_size = context.keys.max_by(&.size).size
Copy link
Contributor

Choose a reason for hiding this comment

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

can be calculated outside the each_with_index loop

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

contents << "```crystal\n"
max_size = context.keys.max_by(&.size).size
context.each do |key, value|
key_aligned = "#{key}".ljust(max_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

key is already a String, no?
So: key.ljust(max_size)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

contents << "**Context #{i + 1}**\n" if contexts.size > 1
contents << "```crystal\n"
max_size = context.keys.max_by(&.size).size
context.each do |key, value|
Copy link
Contributor

Choose a reason for hiding this comment

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

key => var_name
value => var_type (or juste type ?)

wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

# | arg1 | `String` | `String` |
# | arg2 | `Int32 ∣ Nil` | `Bool` |
private def horizontal_align(contexts)
contents = [] of String
Copy link
Contributor

Choose a reason for hiding this comment

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

You could build this one with an IO::Memory too, by generating the output line by line (first the header, then the lines, then the types)

I think it would lead to cleaner/readable code

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@faustinoaq faustinoaq requested a review from a team May 6, 2018 06:42
@faustinoaq
Copy link
Member Author

#95 is already merged 🎉 , waiting for more reviews...

JSON.mapping({
contents: MarkupContent,
range: Range?,
}, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use named arg static: true here, 'cause by just reading true I have no idea what it refers to for a json mapping, I think it's better with the named arg

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why only this mapping have this static check?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member Author

Choose a reason for hiding this comment

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

static: true is not needed here anymore, I'm already fixing that on lsp shard

Lets remove it for now 👍

@faustinoaq faustinoaq requested review from bmulvihill, laginha87, a team and bew May 7, 2018 18:12
@bmulvihill
Copy link
Contributor

@faustinoaq More of an overall comment, I noticed a lot of the code between hover_provider.cr and implementations.cr is duplicated. I am wondering if there is an shared abstraction there since they are both running the crystal tool

Copy link

@bararchy bararchy left a comment

Choose a reason for hiding this comment

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

Looks good to me, and if specs passing im 👍

@faustinoaq faustinoaq merged commit 26a1e43 into master May 13, 2018
@faustinoaq faustinoaq deleted the fa/hover branch May 13, 2018 22:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants