Closed xzbdmw closed 1 week ago
@pjweinb Is the modification
modifier in the semantic token for this distinction?
On the other hand, I wonder what write-access vs read-access means in Go, unlike rust.
In io.Copy(w, r)
, is w
read access or write access?
@pjweinb Is the
modification
modifier in the semantic token for this distinction? On the other hand, I wonder what write-access vs read-access means in Go, unlike rust. Inio.Copy(w, r)
, isw
read access or write access?
no,only variable reassign is considered write in pylance,clangd and rust-analyzer.
The documentation says nothing about the meaning of the 'modification' modifier, and gopls doesn't use it. I suspect the uses would vary widely by language, but I don't know what would be useful (and practical) in Go.
The easiest definition to implement is the variable/value distinction (which C calls lvalue/rvalue). For example:
var v struct { x int }
ptr := &v // ptr and v are both lvalues
ptr.x = ptr.x + 1 // the first x is an lvalue; the second x, and both ptrs, are rvalues
ptr.x++ // x is an lvalue, ptr is an rvalue
v.x = v.x + 1 // the first v and x are lvalues; the second v and x are rvalues
But I have no idea if that's actually what people want. As @hyangah points out with the io.Copy
example, what we mean by a read and a write is highly context-dependent.
I think the easiest way is what most people won't feel uncomfortable, and io.Copy example can wait for future improvement
The simplest way is to reference the highlighting style of GoLand.
I have a plan to implement this feature, and want to know if it is acceptable.
The definition of 'write access' is same as it in GoLand. Some examples are access to variables in declaration, assignment(left value), self increasing, channel sending and composite literal.
The algorithm to find write access is same as it in jdt (Java LSP), by visiting every write statement in ast traversal and collecting the positions of access to variables.
A darft version of implementation is here and the preview of the feature in VSCode is:
Thanks @zhzhsx! TIL that this read/write distinction can be marked using DocumentHighlight
. I think this is a less invasive and more reliable approach than using custom modifier-based syntax highlighting. Please send a cl following the contribution guide
https://go.dev/doc/contribute
Change https://go.dev/cl/597675 mentions this issue: gopls: enhance read/write access distinction in document highlighting for symbols
gopls version
0.14.2
go env
What did you do?
first line is write access and second line is read access
What did you expect to see?
vscode distinguishs write access and read access, most lsp implementations have it such as clangd and rust-analyzer an rust example:
see the different color of scoped_interpreter
What did you see instead?
no color difference
Editor and settings
No response
Logs
No response