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

fix: hover for period qualifiers and single quotes in names #899

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

Durbatuluk1701
Copy link
Contributor

@Durbatuluk1701 Durbatuluk1701 commented Sep 11, 2024

This PR modified the word_at_position function to allow for . and ' to appear in names.

This should fix #884

One note: It does allow for "words" to begin with a ., however it is just handled by providing no hover information since it would not be a legal name in Coq.

Closes #884

@rtetley
Copy link
Collaborator

rtetley commented Sep 11, 2024

@gares Do you think this could possibly create unwanted side effects ?

@gares
Copy link
Member

gares commented Sep 11, 2024

I think that adding ' is a net win, I've seen quite some code naming stuff like foo'.

The . is a bit unclear to me. Nat.pl|us is today considered as plus, that is probably bad since it is more ambiguous than Nat.plus. At the same time Na|t.plus counts a Nat. I don't know if, in that case, if the user expects to get info on the module Nat or the addition. (I use | for the caret position)

@rtetley
Copy link
Collaborator

rtetley commented Sep 11, 2024

I think until we introduce some form of namespace it is a matter of deciding which is worse:

  • Not getting hover information on Nat.pl|us
  • Getting Nat.plus info on Na|t.plus

@@ -87,7 +87,7 @@ let range_of_loc raw loc =
}

let word_at_position raw pos : string option =
let r = Str.regexp {|\([a-zA-Z_][a-zA-Z_0-9]*\)|} in
let r = Str.regexp {|\([a-zA-Z_.][a-zA-Z_0-9.']*\)|} in
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why the . need to be part of the first character set.
The code below tries the regexp at a position and then goes back until it can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally didn't have it there but encountered the following issue since the code rolls back a single character at a time:
A case like Nat.pl|us it would roll back to Nat|.plus which then would no longer match unless the . was in first character set.

If you want I think a more robust way would be to roll back as far as possible to until you encounter [^a-zA-Z_0-9.'] then consume forward with {|\([a-zA-Z_][a-zA-Z_0-9.']*\)|}

Copy link
Member

Choose a reason for hiding this comment

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

then there is an off by one error in the previous code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yes I do think some more errors could creep up. If you hover something like lemma1_te|st I have a feeling it would stop at lemma|1_test since [0-9] does not appear in the first character set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just confirmed this is the case, will rework to be more robust

@gares
Copy link
Member

gares commented Sep 11, 2024

I think we can merge, but I did not test it.

@Durbatuluk1701
Copy link
Contributor Author

Pushed a rework that should handle cases like:
lemma1_te|st
sandbox.mylem|ma (also sand|box.mylemma will have the same results, still not sure if that is desired behavior)
lem|ma' (fully matches lemma' and does not drop at single quotes)

@rtetley
Copy link
Collaborator

rtetley commented Sep 11, 2024

Awesome ! I'll test and merge tomorrow ! Thanks !

This way if we hover over function, i.e. Module.fun|ction (the |
representing the mouse) we get info on function and if we hover
over Module, i.e. Mo|dule.function we get info on Module.
@rtetley
Copy link
Collaborator

rtetley commented Sep 12, 2024

We did some experimenting with @gares and were able to get a solution to the Module.foo problem, I'll merge as soon as CI goes green ! Thanks again !

@rtetley rtetley changed the title Fix Hover for period qualifiers and single quotes in names fix: hover for period qualifiers and single quotes in names Sep 12, 2024
@rtetley rtetley merged commit f4c368a into coq:main Sep 12, 2024
24 checks passed
@Durbatuluk1701 Durbatuluk1701 deleted the hover-fixes branch September 12, 2024 14:21
let forward_reg = Str.regexp {|[^a-zA-Z_0-9']|} in
(* Search forwards ensuring that all characters are part of a well defined word. (Cannot start with [0-9'.] and cannot end with .)*)
let last_word_ind = Str.search_forward forward_reg raw.text start_ind in
let word = String.sub raw.text first_non_word_ind (last_word_ind - first_non_word_ind) in
Copy link
Member

Choose a reason for hiding this comment

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

still looks like an off by one @rtetley .
Did we try (Foo.bar or the like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, think #903 will fix

@Durbatuluk1701 Durbatuluk1701 restored the hover-fixes branch September 12, 2024 21:39
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.

Hover on qualifed names
3 participants