-
Notifications
You must be signed in to change notification settings - Fork 808
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
support for generalized "references" queries #1911
Comments
A related enhancement proposal to the I like the approach you describe though, in that it avoids the need to build anything specific (like a notion of read vs. write references) into the protocol -- that customization can take the form of the server offering whatever variations of the request are relevant as different code actions. |
The LSP's
references
method takes the client editor's selected range, and returns a set of locations--of all the identifiers that refer to the same symbol as the selected identifier. A large variety of useful queries can be expressed as minor variations on this theme. For example:Point2D{1, 2}
is shorthand forPoint2D{X: 1, Y: 2}
, and it might be useful to highlight it when finding references to X or Y.x = 1
,x.a[i] = 2
andp = &x
all use x as an l-value, whereasy = x
andprint(x)
use it as an r-value. When trying to comprehend aliasing and mutation, this difference is crucial.func f(x, y int)
might report the expression456
in the callf(123, 456)
.writer = file
might implicitly convert an*os.File
to anio.Writer
.These examples use Go, but I'm sure you can think of other examples in your second-favorite language. ;-)
I'm not going to prescribe any particular implementation, but I think it would be very useful if the LSP allowed a server to respond to a CodeAction query with a command that tells the client: the result of this command should be displayed with a similar user interface to an ordinary 'references' query.
One subtlety: some of these queries produce slightly more information than a set of locations, especially when describing implicit operations with no obvious syntax; they need an annotation too. For example, the first query might annotate the location of
Point2D{1, 2}
with "implicit reference to Point.X", orx.f
with "shorthand forx.A.B.C.f
"; the second query might annotate each free variable with its type information; and the last one might annotate the assignment with "RHS has type*os.File
". Thus the result type would need to be a list of (Location, string) pairs.What do you think?
The text was updated successfully, but these errors were encountered: