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

x/tools/gopls: return statement steals highlighting #36057

Closed
muirdm opened this issue Dec 9, 2019 · 5 comments
Closed

x/tools/gopls: return statement steals highlighting #36057

muirdm opened this issue Dec 9, 2019 · 5 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@muirdm
Copy link

muirdm commented Dec 9, 2019

It looks like the "return" highlighting is taking precedence over things within the return statement.

type foo struct{ bar int }

func _() foo {
	return foo{
		bar: 123, // trigger highlight at the "bar"
	}
}

If you trigger highlighting at the "bar" in the composite literal, I expect it to highlight just the "bar" field, but it highlights the entire return statement.

/cc @ridersofrohan

@gopherbot gopherbot added this to the Unreleased milestone Dec 9, 2019
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 9, 2019
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@ridersofrohan ridersofrohan self-assigned this Dec 9, 2019
@gopherbot
Copy link

Change https://golang.org/cl/210558 mentions this issue: internal/lsp: fix control flow taking precedence

@muirdm
Copy link
Author

muirdm commented Dec 9, 2019

Thanks for looking at this. Out of curiosity why do we highlight the entire return statement instead of just the "return" keyword? If the return statement is long (esp if multiline), it's really a lot of highlighting. Similarly we highlight the entire composite literal (body) instead of just the composite literal's type name when highlighting on the type name (e.g. foo{ in the example above).

@ridersofrohan
Copy link

We looked at what Goland does when it comes to highlighting inside of a return statement and if you highlight any field in the return list, then it will highlight the entire field and the corresponding param in the return list within the function declaration. For instance,

func test() (bool, int) {
    return false, 1;
}

When you highlight false, it will also highlight bool and if you highlight bool it will highlight all the first fields for each return statement.

In the case that you used as an example, if you just highlight the foo in the type declaration, it will only highlight the composite literal's type name, not the whole body. Highlighting inside the return statement is the only case where the whole body would get highlighted.

@muirdm
Copy link
Author

muirdm commented Dec 9, 2019

Thanks for the explanation. I didn't realize it was connected to the function results like that.

@golang golang locked and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants