pre-processing on the code before opening the intellisence

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 12 years ago by ori
Avatar
Hello,

In v4.00: I want to do some pre-processing on the code before opening the intellisence window. so that the code in the editor is not exaclty the code that I want to open the window for.

when the user presses the ctrl+space button I want to open an intelissence window based on a code I will generate from the code in the editor, and a position in the generated source, I will also give.

is there a way to do that?

Thanks,
Ori

Comments (21)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There is a command right now named IntelliPromptCompleteWordCommand that is tied to Ctrl+Space by default. You could remove its link from the SyntaxEditor.CommandLinks collection and then add your own instead.

You could make a custom command like how we do in the Commands QuickStart and tie it to Ctrl+Space and have it do whatever you want. So if you want to show a member list with custom data, you can do that, but you'd have to populate the member list yourself of course.


Actipro Software Support

Posted 12 years ago by ori
Avatar
so what's the use in using the component?

I want to do something like this:

void ctrlSpaceEvent()
{
// convent the c# code to some other c# code
string newCode = convertCode(mySyntaxEditor.Text)
int newPos = calculatePosInCode(mySyntaxEditor.Text,
mySyntaxEditor.Position)

mySyntaxEditor.OpenIntellisenceWindow(newCode, newPos);
}
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
So wait, are you changing the actual text in the editor or are you doing the convert code in memory only? If you are changing the text in the editor then you can use our automated code by replacing our built-in command with something like this:
/// <summary>
/// Performs an auto-complete if the <see cref="SyntaxLanguage"/> supports an IntelliPrompt member list at the current offset.
/// </summary>
public class CustomIntelliPromptCompleteWordCommand : EditCommand {

    /// <summary>
    /// Executes the edit command.
    /// </summary>
    /// <param name="context">An <see cref="EditCommandContext"/> that holds context-related information.</param>
    public override void Execute(EditCommandContext context) {
        context.Document.ReplaceText([proper parameters here], ConvertCode([your text]));
        context.SyntaxEditor.Caret.Offset = [proper offset];
        SyntaxLanguage language = context.View.GetCurrentLanguageForContext();
        if ((language.IntelliPromptMemberListSupported) && (!context.Selection.IsReadOnly))
            language.IntelliPromptCompleteWord(context.SyntaxEditor);
    }

}


Actipro Software Support

Posted 12 years ago by ori
Avatar
I don't want to change the text in the editor
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Well right now the member list context is determined only by looking at the text in the editor. You'd have to purchase the add-on and the blueprint source code for it to change how that works.

But just as a word of warning, the add-on has some extremely advanced code in it since there is a lot of complicated stuff going on to make IntelliPrompt work. Getting what you want would involve probably making a separate call to the semantic parser to generate another AST, and modifying some of our context code to look at external code rather than what is in the editor. It probably could be done but wouldn't be quick or easy.


Actipro Software Support

Posted 12 years ago by ori
Avatar
I don't want to change code (done it in the past, and learned not to do it)

Maybe I can do a trick.
hold two SyntaxEditors, one will be visible and the other will not be.
I will get the code from the visible editor, do the preprocessing on it, and move it to the invisible one.
but then I have to open the intelli-prompt on the invisible editor on the visible editor. Is it possible?
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Unfortuantely that won't work because the member list is tied to the visible SyntaxEditor so when you type, selections are updated, and text is inserted when you press TAB, etc.


Actipro Software Support

Posted 12 years ago by Jeff Hutt - Blade Games World
Avatar
I have the same requirement,

Basically I need to add some hidden text to the top and bottom of the file:

so, if in the editor my customer types

-------- Begin Snippet ------------
void OnChange()
{
// some more user code here
}

-------- End Snippet ------------

What I actually want parsed is...

-------- Begin Snippet ------------
using System;
using MyNamespace;

namespace MyScripts
{
void OnChange()
{
// some more user code here
}

}
-------- End Snippet ------------


I think it's actually a pretty common scenario if you are writing a scripting solution for an app.

Is there is a way to actually add the additional text to the editor but make these extra lines hidden somehow?
Posted 12 years ago by ori
Avatar
my requirement is to do a pre-processing on the text. lets say I want to so some search & replace, and only after open the intellisence window in a given new position in the new text
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Christian,

Hmm... right now it won't parse that unless all the code is there. However we're happy to work with you to implement this functionality.

As a workaround in the meantime you could always put a #region block around the before and after code and then make those two regions read-only.

So onto how to implement this properly, what do you suggest as far as object model enhancements? I suppose what we would need would be to somehow provide the semantic parser the "full" code snippet since it operates on the whole class. Alternatively maybe we modify the semantic parser so that it can parse like a method only. Since you know more about your scenario, we appreciate your feedback.

One problem I see is that if we parse all this out, the error indicators and type/member drop-down lists will run into problems as-is because the offsets will be off (since it might be loading the full text although that's not really in the editor).

Thoughts?


Actipro Software Support

Posted 12 years ago by Jeff Hutt - Blade Games World
Avatar
I really like the #region idea, that sounds like 90% of the code needed is already there. At worst I could definitely use that.

However, maybe you could mark a section as readonly and hidden?

So I initialize the editor, insert my head and tail code, then mark those sections as readonly/hidden and set the caret somewhere between them. The only issue would be that the visible line numbers would be off due to the hidden code in the head section. Not sure what to do about that but it wouldn't be a deal breaker if I turned off the line numbers :)

Basically now I've thought about it more it seems I have no problem with the editor actually having the additional text. It would be just nice if the user didn't know it was there.

Christian
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Maybe you could go into a little bit more about how snippets work too. Like for ALL snippet editing scenarios, are you only editing a single range of code within a grander scheme of code? Meaning will there only ever be a single head and single tail section of code?

For the line numbering, I believe Document has a property that lets you set the line numbering base number which normally is 1.

Adding hidden region functionality probably would be the best solution.


Actipro Software Support

Posted 12 years ago by ori
Avatar
I think the hidden regions can work for me too. But I didn't understand your answer.
can the hidden regions be read only? in fact can I prevent expanding them? I prefer not to see them at all..
Posted 12 years ago by Jeff Hutt - Blade Games World
Avatar
> Like for ALL snippet editing scenarios, are you only editing a single range of code within a grander scheme of code? Meaning will there only ever be a single head and single tail section of code?

Yes. They will always have a precanned head and tail. The only thing editable is the bit in the middle.

> For the line numbering, I believe Document has a property ...

Ah okay that would probably work

> Adding hidden region functionality probably would be the best solution.

Yes, although I did have another grim thought. Automatic indenting for the visible (editable) middle section would probably be incorrect. In the example I gave it would have 2 tabs too many.

Christian
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes that's true, automatic indenting would be incorrect.


Actipro Software Support

Posted 12 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
Hi,
I think the hidden region stuff you have suggested makes sense to me. I think I will try to implement it. My program also has a simple class designer, so instead of giving intelliprompt information to the syntax editor I will just create the source of the class early.

If I create a SyntaxEditor.Document object and put some code in it, will the DotNetProjectResolver keep track of it or do I need to keep an instance of the SyntaxEditor somewhere in the ether?

thanks,
Jake
Posted 12 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
Another question, can I get/set the text of a region from a document, so I don't end of with an override like this in my SyntaxEditor:

private string Header = "namespace MicroSaintSharp{\nclass Simulation{\npublic void Function()\n{";
private string Footer = "}\n}\n";

public override string Text
{
    get
    {
        int headerLength = Header.Length;
        int footerLength = Footer.Length;
        string baseText = base.Text;
        return baseText.Substring(Header, baseText.Length - headerLength - footerLength);
    }
    set
    {
        base.Text = Header + value + Footer;
    }
}
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We don't have the hidden region stuff in there yet but I believe it will be along the lines of something that might use a manual outline node with no collapsed text or indicator.

Yes if you have a Document open with a DotNetProjectResolver attached and a Document.Filename set, it should update the reflection data automatically.

As for getting/setting the text region, you are doing it correctly.


Actipro Software Support

Posted 12 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
What about adding a Header and a Footer property to the Document, for me and the couple of other guys who want to do the same thing. Then you guys can manage the code hiding and fixing up the line numbers.

thanks,
Jake
Posted 12 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
Hi,
I have another request related to scripting. Is there already or could you add in some way to filter off some of the members of the parent class? For example, I would like to hide GetHashCode when users type in "this.". Perhaps, you could define an attribute that would hide a Field, Property, Method from intelliprompt.
thanks,
Jake
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Christian and Jake,

Since this topic was started for a different reason, I've created a new topic related to our discussion:
http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=1823

That topic summarizes the feature request. Please respond with your thoughts there.

Jake, maybe you could be more specific on your filtering members request (and post the reply in the new topic). Like do you want nothing to show up when doing this. or only some items? Or only items defined on the base class and none of it's base classes?


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.