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: feature request: adding postfx snippets for errors #50550

Open
urandom opened this issue Jan 11, 2022 · 4 comments
Open

x/tools/gopls: feature request: adding postfx snippets for errors #50550

urandom opened this issue Jan 11, 2022 · 4 comments

Comments

@urandom
Copy link

@urandom urandom commented Jan 11, 2022

gopls version

golang.org/x/tools/gopls v0.7.4

Would it be possible to add postfix snippets that are specific for the error type.

I was thinking something like:

err.if!

// Which would expand to:

if err != nil {
    |
}

I guess this one could be uses for any type, not just an error, though maybe the snippet name should be better (ifNot!?)

and a more complex one that returns and takes into account the other return types:

func MyFunc() (*Ptr, int, error) {
    ...

    err.ret!

    // Which would expand to:
    if err != nil {
         return nil, 0, fmt.Errorf("|: %w", err)  
    }
}
@gopherbot gopherbot added this to the Unreleased milestone Jan 11, 2022
@suzmue suzmue removed this from the Unreleased milestone Jan 11, 2022
@suzmue suzmue added this to the gopls/unplanned milestone Jan 11, 2022
@muirdm
Copy link

@muirdm muirdm commented Jan 12, 2022

You can get something similar via statement completions. Does that satisfy your use cases?

@urandom
Copy link
Author

@urandom urandom commented Jan 12, 2022

These statement completions seem to be quite old, but I've never seen them being offered as part of any completion request.

I just checked what is currently being returned, and this is not part of the result:

Screenshot from 2022-01-12 10-35-01

I also installed vscode, in case neovim somehow didn't support this, but the result is the same:
Screenshot from 2022-01-12 10-41-46

According to the diff, this requires placeholders, but adding usePlaceholders to both vscode and neovim didn't make a difference for the results, though I'm not sure that placeholders are worth it for me even for this feature (they require a different workflow from what I'm used to)

@muirdm
Copy link

@muirdm muirdm commented Jan 12, 2022

It should work in any client that supports snippets (do you have snippets disabled?). What does your VSCode go config look like?

This is an example where I see it:
Screen Shot 2022-01-12 at 1 19 13 PM

@urandom
Copy link
Author

@urandom urandom commented Jan 12, 2022

Snippets are enabled and working in both neovim and vscode. Both non lsp snippets and ones coming from gopls. The latter was quite visible when I enabled placeholders and was able to jump between the various positions.

The vscode config is empty (fresh install to test this), except for the 3 lines needed to enable placeholders. I'm not in front of a computer right now, so I can't actually post it.

Edit: settings.json:

{
    "gopls": {
        "ui.completion.usePlaceholders": true,
    }
}

@findleyr findleyr removed this from the gopls/unplanned milestone Jan 14, 2022
@findleyr findleyr added this to the gopls/on-deck milestone Jan 14, 2022
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
5 participants