hooking up VS2005's "Implement Interface" functionality

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Dan Smith - Novi, MI USA
Version: 4.0.0246
Avatar
I'm just getting started with SyntaxEditor.

I've created a new language that is "in the spirit" of VB.NET and have been able to modify the supplied samples for VB.NET to get syntax coloring and outlining for my language.

Now, I'm trying to hook up some "meatier" functionality and I haven't been able to figure out how best to proceed. Specifically, I want to do something similar to the “Implement Interface” functionality in Visual Studio 2005: when you right click on an interface name that is part of a class definition, you get a context menu with “Implement Interface” on it. Right now, I’m only concerned with displaying & handling the context menu. Using the SyntaxEditor’s “Smart Tags” instead of context menu would also be acceptable.

In reading through the documentation, it looks like there may be several options available, but right now I can’t really figure out even where to start. For example, just like with the VS2005 “Implement Interface” functionality, I only want the context menu (or smart tag) in a very particular situation. For me, the code looks like
CHILD childName AS ParentName
'other stuff here
END CHILD
I want the “Implement Interface”-like functionality on “ParentName”, but only when it is part of a CHILD definition shown above.

It looks like maybe one place to start is by adding a child state to my dynamic language definition; am I going to be able to (easily) do what I want by using a dynamic language? Or am I going to have to create a SyntaxLanguage directly?

And once I get past that, I need to know how to actually hook up the UI. There didn't seem to be much sample code using "Smart Tags", I didn't find any custom context menu sample.

Thanks for the help & guidance.
Dan

Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Dan,

You can make a lexical state for your CHILD block, or you could get a TextStream (via Document.GetTextStream) and iterate back through tokens to see if you are in a CHILD block. The second way lets you keep your existing language design.

For some sample smart tag code, look for "smartTagContextMenuItem" in the MainForm. You'll see how we create the menu in response to a smart tag popup button click and then handle the menu items.

Also the code that adds the smart tag underline block after paste operation in MainForm is in "editor_PasteDragDrop".


Actipro Software Support

Posted 12 years ago by Dan Smith - Novi, MI USA
Avatar
OK, I see the sample code that adds a Smart Tag after a paste operation...

But how do I add the smart tag while parsing? In my sample:
CHILD childName AS ParentName
'other stuff here
END CHILD
I want the smart tag around just the "ParentName" identifer; "childName" is also an identifer, but should not have a smart tag.

And this could be code that is read in from an existing file, so the user should not have to do anything (like paste in the example code) to get the smart tag.

Or is going to be easier to respond to the ContextMenuRequested event? If I do that, I'll have to check to be sure I'm in the right parse state (I created a new state for CHILD) and over the right identifer.

It looks like getting any kind of "intelligence" out of a dynamic language involves creating multiple states, is that correct? And if so, how do I avoid duplicating code in each state? For example, I have to do the "identifer" and "number" stuff twice: once for the default state and again in the child state.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The way we do intelligence for what is in a document in our .NET Languages Add-on is two-fold. We do a lot of IToken scanning around the area you are interested in (generally where the caret is) via the use of a TextStream. We combine that info with AST info that was created by a previous semantic parse. And by looking at both those things, we determine as best we can the context of a given offset.

In our .NET Languages Add-on we have context classes which store information such as what type and member the context is in, etc. By using that sort of information it becomes somewhat trivial to then show an appropriate member list or do whatever you need to do.

But the hard part is the initial building of the context. Especially since you have to consider that as an end user types, the code in the editor is probably not valid compilable code most of the time. Since every language is different, each requires different code towards how you scan tokens and build up context info.

In your case, you might want to do your smart tag stuff in PerformSemanticParse of your language. You are passed the range of offsets where lexical parsing occurred. So you know the range of text to scan. Then use a TextStream (via Document.GetTextStream) to iterate through the tokens in that range and add smart tags where appropriate.

You are correct that if you go with the state approach you will be defining the same patterns again in the second state.


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.