How to add completion words dynamically to VS2013 Syntax Extension (MEF)
Asked Answered
D

1

8

It's very possible that I just don't understand the problem space, but I'm having trouble figuring out the MEF (Editor Classifier project).

I've created (piecing together the Walkthrough guides from MSDN https://msdn.microsoft.com/en-us/library/ee197665.aspx) a syntax highligher for Informix Stored Procedure language.

One major problem I have is - I want to be able to find all instances of the keyword "DEFINE" and populate the word directly following it into the Statement Completion extension I have (currently it's populated from a defined list of words).

Much like C#'s native support - when you define a variable, it becomes available in the autocompletion dropdown.

I got rid of the in class hardcoding (from the walkthrough) and my completion words are defined like this:

List<Completion> completions = new List<Completion>();

CompletionTags completionTags = new CompletionTags();

foreach (string completionTag in completionTags.completionTags)
{
    completions.Add(new Completion(completionTag));
};

My CompletionTags class is pretty simple:

class CompletionTags { public List completionTags;

public CompletionTags()
{
    this.completionTags = new List<string> {
        // SQL keywords
        "COUNT",
        "FROM",
        "HAVING",
    };
}

I know WHAT I need to do. I somehow need to hijack the buffer when it changes and find all occurrences of 'DEFINE ([a-zA-Z0-9_]{1,})' and add \1 to the completionTags list.

I have no idea HOW to do this. Any pointers in the right (or any) direction at this point would be greatly appreciated.

Be kind - we've all been out of our depth at some stage (I've been programming in C# now for 3 days)...

Demagogue answered 15/5, 2015 at 6:17 Comment(1)
I've managed to get this working by turning the CompletionTags class into a singleton - and then I've hijacked the syntax highlighter classifer to check for the defines and add to the completionTags List. I KNOW this is not the right way to do it, so the question still stands.Demagogue
K
2

Reading this answer will be helpful. Look at:

XML Editor IntelliSense Features

Schema Cache

Kary answered 24/5, 2015 at 15:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.