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
Assignees
Labels
Milestone

Comments

@muirdm
Copy link

@muirdm 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 9, 2019

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 9, 2019

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

@muirdm

This comment has been minimized.

Copy link
Author

@muirdm 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

This comment has been minimized.

Copy link

@ridersofrohan ridersofrohan commented Dec 9, 2019

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

This comment has been minimized.

Copy link
Author

@muirdm muirdm commented Dec 9, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.