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 rascal hovers showing random types #262

Merged
merged 2 commits into from
Jun 12, 2023
Merged

Fix rascal hovers showing random types #262

merged 2 commits into from
Jun 12, 2023

Conversation

DavyLandman
Copy link
Member

Fixes #260

As discussed, there were 3 bugs:

  1. We were registering offset from different modules as part of our own module (rascal-core (c/s)hould maybe filter that?)
  2. We were merging (with random results) overlapping offsets to a single value
  3. After fixing 2, I found that we also didn't correctly support overlapping ranges.

This PR fixes all 3, where I'm a bit sad I have to walk the whole tree, but that seems inevitable.

@PaulKlint
Copy link
Member

Indeed the summary should filter locations outside current module.

@jurgenvinju
Copy link
Member

Which tree are we walking? I can't find that code in the source. Can you point me to it @DavyLandman ? Typically in the eclipse version of this functionality, we'd use the cursor offset in the file to find a path in the tree to all relevant source locations, in log(n) time where n is the size of the file.

// search all the way to the "bottom" of the tree to see if we are
// contained in something larger than the closest key
var previousKeys = data.headMap(from, true).descendingMap();
for (var candidate : previousKeys.entrySet()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather read the type of candidate here instead of var. I'm getting lost. Same for previousKeys.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I don't really see the value, descendingMap becomes a NavigatableMap<Range, T> and candidated Entry<Range, T>. But for me the readability doesn't improve by it, but that might be because I wrote the code. I would prefer to give better names to the variables.

@DavyLandman
Copy link
Member Author

Which tree are we walking? I can't find that code in the source. Can you point me to it @DavyLandman ? Typically in the eclipse version of this functionality, we'd use the cursor offset in the file to find a path in the tree to all relevant source locations, in log(n) time where n is the size of the file.

The TreeMap in the TreeMapLookup class. We don't have a parse-tree here (we just have a binary rel). So we use the R-B tree inside TreeMap, but yesterday I was thinking that if we would build our own tree (RB or not) it might make it "faster" to iterate it.

@jurgenvinju
Copy link
Member

I think we might separate the (fuzzy) search from the translation; if we use the parse Tree to provide a (list of) candidate source locations, then these ranges can be translated one-to-one to the LSP Range concept. There is no need to walk over the entire data-structure anymore, and the lookup would be twice in log time, once log of the size of the input file and once log the size of the lookup cache. WDYT?

@DavyLandman
Copy link
Member Author

Sounds like a new PR :) This is fixing the bug we have right now.

I don't exactly understand your proposal. We get a summary from the rascal-core with just a few rels in there, do you want to put it back in a parse tree?

I was thinking we could build a specific RB tree to do a some better mapping of this logic, but for now using TreeMaps are good enough. It just could be faster.

@jurgenvinju
Copy link
Member

jurgenvinju commented Jun 6, 2023

The eclipse mirror of the summary feature gets a current parse tree and the cursor position, and the current summary. First the tree is used to extract which ranges are relevant for the current lookup. This is done by traversing a path in the tree that contains the cursor position. The rest of the tree can be ignored, naturally. This gives it the worst case log complexity behavior.

Then the target ranges are identified, which can be searched in the summary, using the index of the relation.

Then the output can be composed out of the answers of the previous and translated to ranges in LSP format.

@DavyLandman
Copy link
Member Author

Ah, thanks for explaining that in a bit more detail.

@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

39.3% 39.3% Coverage
0.0% 0.0% Duplication

@DavyLandman
Copy link
Member Author

I've added a random test that tries to fill the TreeMap with all kinds of ranges (trying to cram lots of overlapping ranges in there) and then made sure the specific range would still be found.

I propose we go ahead with this, and think of a different approach at a later point. As in, it's primarily a performance discussion after this right?

@jurgenvinju
Copy link
Member

jurgenvinju commented Jun 12, 2023

I'm testing the fixes:

  • hover help and jump-to-definition within a file works fine
  • hover help between files seems to work (but I don't know if I'm missing more information)
  • jump-to-definition to another file never works (@DavyLandman this is a false report; caused by old tpl files)

@jurgenvinju
Copy link
Member

Ok, I'm retracting the jump-to-definition bug:

/Users/hillsma/Projects/rascal/pico-analysis/src/main/rascal/lang/pico/Abstract.rsc

So this was an older .tpl file in my target folder that got unzipped.

It is an instance of #242 ; at least if we would have used project URL's where possible, this would not have happened.

  • jump-to-definition works now

Copy link
Member

@jurgenvinju jurgenvinju left a comment

Choose a reason for hiding this comment

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

Excellent fixes. Really happy this is resolved.

@jurgenvinju
Copy link
Member

It really works a lot better now.

@jurgenvinju jurgenvinju merged commit 3e50341 into main Jun 12, 2023
6 checks passed
@jurgenvinju jurgenvinju deleted the fix-tree-map branch June 12, 2023 11:17
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 help in Rascal file displays seemingly random data
3 participants