3

I have some requirements in making the intellisense customizable. Is this possible?

I want to add a custom item into the dropdown that gets triggered when "." (period) is pressed.
Also any information regarding code completion would be very much appreciated.

Basically, i'm looking for something like:
A doubletab press after typing "for" would generate the following code:

for (int i = 0; i < length; i++)
        {

        }.

Can we have custom items to insert different code snippets as above?

svick
  • 236,525
  • 50
  • 385
  • 514
  • 2
    If i am not wrong you want your own snippets for C# ? Check this one http://stackoverflow.com/questions/3956638/custom-code-snippets-in-intellisense – Ali Umair Jul 30 '15 at 05:45
  • Yes.. I want to create my own items in the Intellisense dropdown menu and then insert custom code snippets – Karthik Bhat Jul 30 '15 at 05:47

2 Answers2

3

Yes, that is possible. Have a look at this MSDN Link.

Here a little Example:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Hello World</Title>
      <Author>Myself</Author>
      <Description>Says a string to the world.</Description>
      <Shortcut>hello</Shortcut> <!-- This is your intellisense Shortcut -->
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>sayValue</ID>
          <ToolTip>Replaced with what you want.</ToolTip>
          <Default>"Hello"</Default>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
        <![CDATA[
          valueToSay = $sayValue$;
          Console.WriteLine(valueToSay);
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

How to install:

  1. Save this somewhere
  2. Go in your VS to Tools -> Code Snipptes Manager
  3. Choose Import
  4. Choose your (in Step 1 saved) file
Mischa
  • 1,303
  • 12
  • 24
2

MSDN have complete steps to do your custom code snippet.

I have developed one sample snippet intellisense for you. Just open the folder path for snippet in file explorer and paste your custom snippet file here.

Step 1: enter image description here

Step2:

Created my custom "janty" snippet file and saved file as .Snippet extension.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>janty</Title>
            <Shortcut>janty</Shortcut>
            <Description>Code snippet for if statement</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>expression</ID>
                    <ToolTip>Expression to evaluate</ToolTip>
                    <Default>true</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[Hello Jayanti ($expression$)
    {
        $selected$ $end$
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Step: 3

Test the snippet using short key "janty". Its working. enter image description here

Its simple approach.

Janty
  • 1,708
  • 2
  • 15
  • 29
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Michel Keijzers Jul 30 '15 at 06:20
  • 1
    @Kartik, If the post helped you please do not forgot to mark it and upvote. – Janty Aug 01 '15 at 05:15