Skip to content

MonoDevelop auto complete addin

MonoDevelop logoI got a question about how to do auto completion features in an MonoDevelop addin. Since I’m in the middle of fixing auto completion bugs in PyBinding, this was perfect, so here’s a little guide on how to do it step by step.

Ok so I’ll do this in short exact instructions with as little explanations as possible. Most should be understandable from my limited amount of code.



  • Create a new solution, and select C# library (other .NET languages should work too).

  • Create a new xml file in your root directory named with the pattern “MonoDevelop.{YourAddinName}.addin.xml”.

  • In the xml add this code and rewrite it to match your addin:




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<Addin id          = "AzComplete"
name = "Az Completion"
namespace = "MonoDevelop"
author = "Rohde Fischer"
copyright = "MIT X11"
url = "http://www.rohdef.dk"
description = "Dummy autocompletion, to do proof of concept"
category = "Language bindings"
version = "1.0.0">
 
<Runtime>
<Import assembly = "AzComplete.dll"/>
</Runtime>
 
<Dependencies>
<Addin id = "Core" version = "2.8.1"/>
<Addin id = "Ide" version = "2.8.1"/>
<Addin id = "SourceEditor2" version = "2.8.1"/>
</Dependencies>
 
<Extension path = "/MonoDevelop/Ide/TextEditorExtensions">
<Class fileExtensions = ".az" id = "AzComplete.AzComplete" class = "AzComplete.AzComplete" />
</Extension>
</Addin>




  • You could change the ‘id’-attribute value for the completion part, but I recommend matching your addin name. Note that the ‘namespace’ in the addin-tag must have the value “MonoDevelop”.

  • Check that you use the right version numbers for your dependencies, otherwise it won’t work. My dependencies here are from the git checkout of MonoDevelop. Most likely you need the value ‘2.6.0’ at the moment.

  • In the properties for the addin.xml set “Build action” to “Embed as resource”

  • Enter the references and add “MonoDevelop.Core.dll” and “MonoDevelop.Ide.dll”. You may need to find the assemblies manually depending on your setup, this can especially be likely if you have multiple installations.

  • Create a ┬ánew C#-file to do the auto completion. Note that the namespace and class name must match what you declared in the addin.xml.

  • Extend “CompletionTextEditorExtension”, and override “HandleCodeCompletion(CodeCompletionContext completionContext, char completionChar)”.

  • Return null for an empty completion list or an┬áICompletionDataList for the completion you want. Here’s an example of a completion that suggests “Miav” if the user types a period.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.Ide.CodeCompletion;
 
namespace AzComplete
{
public class AzComplete : CompletionTextEditorExtension
{
public override ICompletionDataList HandleCodeCompletion(CodeCompletionContext completionContext,
char completionChar)
{
if (completionChar != '.') return null;
 
var completionList = new CompletionDataList(
new CompletionData[] {new CompletionData("Miav")});
return completionList;
}
}
}




  • Build the project[1] and copy the dll file from the build folder to a folder where MonoDevelop can see it, most likely it will be something like ‘/usr/lib/monodevelop/AddIns’. I recommend creating a new file for it. Restart MonoDevelop and enjoy.



Auto complete demonstration

Important note about installation: Here I use the bad way of installing. It’s good for testing and if you only run it on your own system. If you release it DON’T DO THIS! Use mtool to create an addin repository and use this.


[1]: For some reason some MonoDevelop installations defaults to using a .NET version lower than 4.0. In this case the code won’t compile. Please ensure that the project is set to Mono/.NET 4.0


Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options