
MonoDevelop auto complete addin
WARNING
Deprecated project
I got a question about how to do autocompletion features in an MonoDevelop addin. Since I’m in the middle of fixing autocompletion bugs in PyBinding, this was perfect, so here’s a little guide on how to do it step by step.
This is in short, exact instructions with as few 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:
<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 thenamespace
in the addin-tag must have the valueMonoDevelop
. - 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
toEmbed 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.
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 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.