Skip to content

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

Open

Description

@xieyuschen

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

Activity

  1. added
    goplsIssues related to the Go language server, gopls.
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on May 13, 2025
  2. added this to the Unreleased milestone on May 13, 2025
  3. 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[/+] on May 13, 2025
  4. xieyuschen commented on May 13, 2025

    @xieyuschen
    MemberAuthor

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

  5. 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[/+] on May 13, 2025
  6. adonovan commented on May 13, 2025

    @adonovan
    Member

    Seems reasonable.

  7. gopherbot commented on May 18, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/673935 mentions this issue: gopls/internal/golang: completion: rank 'continue' under cond higher in loop

  8. gopherbot commented on May 18, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/673915 mentions this issue: gopls/internal/golang: completion: rank 'continue' under cond higher in loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/completionIssues related to auto-completion in gopls.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions