Skip to content
Nick Spagnola edited this page Feb 19, 2018 · 6 revisions

Notes on development:

Hopefully this can help someone needing to maintain this or for VS for Mac addins in general. The extension platform for Visual Studio for Mac uses the MonoDevelop APIs. The API resource is the best place to start: http://www.monodevelop.com/developers/articles/api-overview/

Commands:

You create an extension's functionality by registering new commands with an extension point. See the MonoDevelop Extension Tree Reference here, for the available areas of the IDE that can be extended.

This extension mainly deals with adding a new command to the Edit Menu. You do two things. Registering the command, and providing a CommandHandler for it. Registering a command, as well as adding a custom line for it to the Edit Menu, are defined in Manifest.addin.xml.

When registering, the id of the command must match a duplicate enum in the same namespace. In our case, a simple QuickTypeCommands enum, with a single member of PasteJSONAsCode works. The id is then quicktypevsmac.QuickTypeCommands.PasteJSONAsCode. The defaultHandler property should refer to the specific handler. Ours is simply PasteJSONAsCodeHandler, so quicktypevsmac.PasteJSONAsCode.

To provide a handler, create a subclass of CommandHandler, and override Run() and Update(). Update() is called to determine if the command is enabled. Set the Enabled property of the provided CommandInfo to true or false, depending on any custom logic. Ours checks if there is a document to paste to, and if there is anything on the clipboard. The run method of course contains the logic of the command itself.

File type check

There is a file check in the form of a helper method here, to ensure the code is being pasted in to a file for a language that quicktype supports. First it checks extensions for .cs, .cpp, or .ts, which will cover most everything. The latter two weren't technically supported at the time of writing but can be opened by it. If it doesn't find either, it uses MonoDevelop's extension method GetLanguageItems, which returns an ISymbol (Microsoft.CodeAnalysis) with a language property string and cleans up that string to be consumed by quicktype's executable. The latter check is just in the event of a weird scenario that it's being pasted in to a file without an extension name or something.

Adding files:

Set the build action of any bundled resources (in our case a quicktype executable from npm building the core library) as an AddInFile.

Use of the status bar:

Outlined here for posterity.

Clone this wiki locally