TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TypeScript snippets in VS

Open craigktreasure opened this issue 12 years ago • 67 comments

Moving this over from CodePlex (23 votes, assigned to jonturner, http://typescript.codeplex.com/workitem/938):

I would really like to be able to use a TypeScript version of the JavaScript code snippets when writing TypeScript in Visual Studio.

craigktreasure avatar Jul 30 '14 15:07 craigktreasure

What kind of snippets would you like to see?

RyanCavanaugh avatar Jul 30 '14 17:07 RyanCavanaugh

I think all of the existing snippets for the JavaScript language would be a good start. JSDoc snippets and auto completion would be a huge win! I would love it if TypeScript code was as quick and easy to document as it is in C# today. For example, a /// is all it takes to generate the documentation scaffolding and then I just need to add descriptions.

Also, TypeScript doesn't appear as a language in the Code Snippets Manager, so I can't add custom snippets (that i'm aware of anyways).

craigktreasure avatar Jul 31 '14 00:07 craigktreasure

I miss the language too within the Code Snippets Manager. So for me it would be great if I just could add custom snippets. That's all what I need.

Cotspheer avatar Aug 05 '14 13:08 Cotspheer

What kind of snippets would you like to see? @RyanCavanaugh

For starter I love /// to create a template of a documentation comment and fill in the parameters and other information. There are loads of different snippets that could make coding quicker and easier:

  • ctor
  • prop
  • switch
  • for
  • try
  • tryf

And a shortcut to launch the Insert Snippet menu (ie. CTRL+K, X) would be nice. I also miss the magical smart tag (ctrl + .) to automatically import, implement interfaces, etc.. like everyday when I'm coding TypeScript in VS!

knazeri avatar Aug 07 '14 16:08 knazeri

@KamyarNazeri /// comments template support should be an issue by itself. Just having snippets will not give you what you are looking for.

mhegazy avatar Aug 07 '14 18:08 mhegazy

@mhegazy What kind of issue are we talking about?

knazeri avatar Aug 07 '14 18:08 knazeri

He just means it's a separate feature from code snippets and should be tracked in a separate issue on the issue tracker.

danquirk avatar Aug 07 '14 19:08 danquirk

yup. thanks @danquirk for the clarification, we need two issues here :)

mhegazy avatar Aug 07 '14 19:08 mhegazy

AngularJS code snippets for controllers, services, directives, etcetera would be really nice to have available in VS.

frodegil avatar Aug 12 '14 09:08 frodegil

@frodegil, AngularJS and code snippets for other frameworks will need to be handled by custom snippets. A custom snippet for JavaScript is defined as follows:

<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <Header>
        <Title>Closure</Title>
        <Author>Me</Author>
        <Shortcut>closure</Shortcut>
        <Description>Code snippet for a JavaScript closure</Description>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
            <SnippetType>SurroundsWith</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Code Language="JavaScript">
            <![CDATA[(function () {
  $selected$
})($end$);]]>
        </Code>
    </Snippet>
</CodeSnippet>

I believe this request is for TypeScript files to support the following: (a). Launch the "Insert Snippet" dialogue on Control+K, Control+X. (b). Provide a set of built-in snippets (for if, try etc) (c). Permit defining custom snippets as above.

NoelAbrahams avatar Aug 12 '14 12:08 NoelAbrahams

Personally I don't think snippets should be in their own menu with a long, awkward key chord to invoke. There's no reason they can't be treated like any other completion result as many other languages/editors do.

danquirk avatar Aug 12 '14 18:08 danquirk

Personally I don't think snippets should be in their own menu with a long, awkward key chord to invoke. There's no reason they can't be treated like any other completion result as many other languages/editors do.

:+1:

NoelAbrahams avatar Aug 17 '14 11:08 NoelAbrahams

I second @NightkingCH ! If TypeScript were visible as a language in Snippet Manager we could create our own snippets and use them. Currently I if make TS snippets as JavaScript they are not usable in TS files :-(

sumitkm avatar Sep 10 '14 12:09 sumitkm

Totally agree with @NightkingCH .

CodeZombieCH avatar Nov 05 '14 16:11 CodeZombieCH

Here's a dark way to make JS snippets work in TS... But certainly we won't use it in practice, just for fun.

  1. Create a JS file and open it.
  2. Rename it to .ts...
  3. LOL...

And it's a shame that there is still no snippet support in TS 1.3 for VS 2013.

vilicvane avatar Nov 14 '14 13:11 vilicvane

Just out of curiosity, are snippets going to make into VS2015 final release? Or the preview release is pretty much everything we will see the final release?

knazeri avatar Nov 14 '14 17:11 knazeri

Just ran into this issue today. :+1: please!

mwilc0x avatar Nov 25 '14 20:11 mwilc0x

Add TS language to Code Snippets Manager, please!

Mogikan avatar Jan 12 '15 14:01 Mogikan

12 more votes for TS Code Snippets!!!! Custom Snippets at a minimum, and maybe useful snippets out of the box.

I am repping my colleagues :)

gravidThoughts avatar Jan 14 '15 20:01 gravidThoughts

An auto curry interface generator would be nice too:

http://stackoverflow.com/questions/28566969/create-programmable-snippet-for-visual-studio-with-node-js-code

jon49 avatar Feb 18 '15 15:02 jon49