Skip to content

x/tools/gopls: completion: rank 'continue' higher inside a loop #73690

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

Open
xieyuschen opened this issue May 13, 2025 · 2 comments
Open

x/tools/gopls: completion: rank 'continue' higher inside a loop #73690

xieyuschen opened this issue May 13, 2025 · 2 comments
Labels
gopls/completion Issues related to auto-completion in gopls. 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

@xieyuschen
Copy link
Member

gopls version

v0.18.1

go env

irrevelant

What did you do?

func _() {
	for {
		if true {
			con| // | is the cursor position
		}
	}
}

What did you see happen?

The const is put as the best option.

Image

What did you expect to see?

I expect to see the continue as the best option. My reason is:

  • when we use if inside a for loop, we have more confidence typed con wants to use continue rather than const.
  • const declared constants are prefered to put in file level.

Hence, I want to adjust the gopls logic for this part:

  • check whether direct parent node is if-stmt
  • check whether parent's ancestor has for stmt

If both of them are satisfied, provide continue with a higher score. I can help to do the code change.

Editor and settings

No response

Logs

No response

@xieyuschen xieyuschen added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels May 13, 2025
@gopherbot gopherbot added this to the Unreleased milestone May 13, 2025
@xieyuschen xieyuschen changed the title x/tools/gopls: issue title x/tools/gopls: provide continue with higher score when it's inside a if-stmt with a for loop May 13, 2025
@xieyuschen
Copy link
Member Author

Hi @adonovan @findleyr , how do you think about this change? I can help to do the code change.

@adonovan adonovan added the gopls/completion Issues related to auto-completion in gopls. label May 13, 2025
@adonovan adonovan changed the title x/tools/gopls: provide continue with higher score when it's inside a if-stmt with a for loop x/tools/gopls: completion: rank 'continue' higher inside a loop May 13, 2025
@adonovan
Copy link
Member

Seems reasonable.

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/completion Issues related to auto-completion in gopls. 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

4 participants