Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Snippet improvement suggestions #1920

Closed
alecthomas opened this issue Sep 8, 2018 · 5 comments
Closed

Snippet improvement suggestions #1920

alecthomas opened this issue Sep 8, 2018 · 5 comments

Comments

@alecthomas
Copy link
Contributor

Hello,

First off, let me just say that coming from Sublime Text, I am loving vscode and vscode-go. They're clean, functional, maintained, professional products.

I have a couple of suggestions for snippets which I think would improve the common use case, based on similar functionality in GoSublime:

  1. For "iferr", it seems like the 99% common case is to "return err", but the snippet does not have this and instead highlights "return" for replacement. I found the following to be much more convenient:

    if err ${1:!=} nil {
      return ${2:}err
    }
  2. A set of "method" snippets could be dynamically generated from the existing types in the package. That is, if a type type Foo <...> exists, dynamically add a snippet of the form func (f *Foo) ${1:method}(${2}) ${3} { ${4} }

Anyway, thanks for listening and all the best,
Alec

@alecthomas alecthomas changed the title Snippet improvements Snippet improvement suggestions Sep 8, 2018
@ramya-rao-a
Copy link
Contributor

For the iferr, doesnt return ${2:err} make more sense than return ${2:}err?

The second case is supported in a way already. After declaring the type Foo just start typing Foo in another line and one of the auto-completion options should be for func (*Foo)

@ramya-rao-a
Copy link
Contributor

I'd be happy to accept a PR for the first issue.

@alecthomas
Copy link
Contributor Author

The second case is supported in a way already. After declaring the type Foo just start typing Foo in another line and one of the auto-completion options should be for func (*Foo)

Aha! I totally did not see that at all, thanks.

For the iferr, doesnt return ${2:err} make more sense than return ${2:}err?

${2:}err is more convenient because 99% of the time you either want to return just the error, or return the error and add more return parameters (unless using goreturns). If ${2:err} is used and you want to add more return values you either have to overwrite "err" with them all, or cancel the snippet to prepend them.

I'd be happy to accept a PR for the first issue.

Okay, I will take a look 👍

@ramya-rao-a
Copy link
Contributor

Ah, understood.

@ramya-rao-a
Copy link
Contributor

Also, feel free to go through the other snippets in that file, to see if they can be improved

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants