Code intelligence popup only shows for the last token in a line
Summary
Code intelligence information (from LSIF artifacts) is correctly parsed (all tokens in a line have hover indicators), but the popup for the declaration and reference information only shows when the last token is clicked.
Steps to reproduce
Open https://gitlab.com/scottpledger2005/2024.01-ci-popup-issue/-/blob/main/src/index.ts. The following tests should pass:
- Action: Click on
foo
on line 1. Expected: A code intelligence popup should appear. Actual: nothing happens. - Action: Click on
bar
on line 1. Expected: A code intelligence popup should appear. Actual: nothing happens. - Action: Click on
Bar
on line 1. Expected: A code intelligence popup should appear. Actual: nothing happens. - Action: Click on
Baz
on line 1. Expected: A code intelligence popup should appear. Actual: A code intelligence popup should appear.
Example Project
https://gitlab.com/scottpledger2005/2024.01-ci-popup-issue/
What is the current bug behavior?
Only clicking on the last token in a line shows the code intelligence popup.
What is the expected correct behavior?
Clicking on any token in a line shows the code intelligence popup.
Relevant logs and/or screenshots
No related console log output in the DevTools console.
Output of checks
This bug happens on all GitLab instances, including GitLab.com and on my company's private instance.
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
!142343 (merged) should fix this issue.
The line of code that causes this is https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/code_navigation/utils/index.js?ref_type=heads#L22. The function containing this line (addInteractionClass
) gets called once per token. Thus, each token in a line overrides the dataset information that was set on all previous tokens in the line. This results in only the last token in a line having the charIndex
and lineIndex
dataset
entries, and thus making it the only token in the line that will display the code intelligence popup.