MonoDevelop auto complete addin
I 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 | <Addin id = "AzComplete" |
- 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 | using System; |
- 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.
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
Comments
Display comments as Linear | Threaded