-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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 postfix snippets for errors #50550
Comments
You can get something similar via statement completions. Does that satisfy your use cases? |
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:
|
FWIW, I do see these with the following added to settings.json:
It would be nice if the I would be interested in sending a CL enable this by default if that is considered an appropriate change. (That might be a small change for a seasoned gopls contributor, but it would be an opportunity for me to learn more about contributing to gopls). edit: corrected initial comment (incorrect setting). |
And I guess there are at least two ways to enable this by default:
|
Either makes sense to me. 1) will be contentious, but that is how it defaults already in Emacs lsp-mode. 2) should be easy, but note that I required placeholders so that the "err" in "return err" would be selected on insertion, making it easier to wrap/contextualize the error. There is option 3) which is to ignore the usePlaceholders setting in this case and always give a placeholder. This use of placeholders is pretty benign and may not annoy users like the func call placeholders do. |
How about just |
Just a quick update: I have a basic change (in line with what @muirdm suggested), as well as looking at a slightly larger change, but I’ll probably break the second piece into a separate issue… |
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:
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:
The text was updated successfully, but these errors were encountered: