Simple code completion sample in Roslyn

asked12 years ago
last updated12 years ago
viewed9.2k times
Up Vote16Down Vote

I'd like to get started with code completion in Roslyn but could not find any simple examples that show how to do code completion.

What would be a good example to finish this code so that I can obtain all possible completion items (AKA Intellisense or CTRL+Space completion) at the caretIndex?

static void Main(string[] args)
{
    var code = @"
    using System;
    public class Test
    {
        public void TestMethod()
        {
            var now = DateTime.Now;
            now.
        }
    }";
    Console.WriteLine(code);

    var st = SyntaxTree.ParseText(code);
    var caretIndex = code.IndexOf("now.") + 4;

    //how to get possible code completions at caret index? (Intellisense)
}