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

Missing accurate position of the unused import #12734

Open
adpi2 opened this issue Feb 20, 2023 · 4 comments
Open

Missing accurate position of the unused import #12734

adpi2 opened this issue Feb 20, 2023 · 4 comments

Comments

@adpi2
Copy link
Member

adpi2 commented Feb 20, 2023

Reproduction steps

Scala version: 2.13.8 (also in 2.12.15)
scalacOptions: -Wunused:imports (or -Xlint:_)

package example

import scala.annotation.{nowarn, showAsInfix}

@nowarn
class Example(unusedVar: String)

Problem

The position of the unused import warning spans the entire line: the start column is 0 and the end column is 45. The pointer accurately points to 33, the beginning of the unused import.

This is a problem in LSP because the LSP position only contains the start column and end column, not the pointer. Hence we don't know which import is unused.

image

Expected result.

The start column should be 33 and end column should be 44.

@SethTisue
Copy link
Member

(I've optimistically added the "good first issue" as often improving position information isn't too hard, but it's conceivable that if someone investigated, it would turn out that it isn't so easy to get the specific information to where it's needed in this case.)

@som-snytt
Copy link

The position should include just the selector.

I fixed a similar issue IIRC.

@joroKr21
Copy link
Member

case class ImportSelector(name: Name, namePos: Int, rename: Name, renamePos: Int) - it's not a tree

@som-snytt
Copy link

To remind myself, the similar issue was the "NamePos" business.

The selector not being a tree is a nuisance. I implemented rewrite for unused imports on Scala 3 somehow, on my branch for that, the details of course I have suppressed.

@som-snytt som-snytt self-assigned this Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants