Fuse Text editor API

Introduction

The following documentation describes the text editor API we are currently maintaining to support our Sublime Text package. In the future we hope this API will support a range of editor plugins to suit your needs. During the beta phase it is constantly subject to change, perhaps dramatically, and we’d appreciate any feedback and suggestions as it is being developed.

Our Sublime package repo can be inspected here.


API VERSION 1.2

Basic description

As now the text editor API uses socket for communication. The host is listening on “127.0.0.1:12122”. There can only be one client connected at any time. The last client connected is the one who can talk with Fuse. The state is per client, so you must send SetFeatures each time you want to connect.

Protocol

The protocol is implemented on top of JSON, using UTF-8. Different predefined commands are sent back and forth between the server and text editor client. An example of a command:

{
    "Command": "RequestCodeCompletion",
    "Arguments": 
    {
        "QueryId": 0,
        "Path": "C:\Test.uno",
        "Text": "using Uno;",
        "Type": "Uno",
        "CaretPosition": { "Line": 1, "Character": 4 }
    }
}

Before a JSON serialized command is sent, the size of the JSON data is sent as an UTF-8 encoded string with newline.

Protocol spec:

length - string (size is num bytes from start to first newline)
JSON_Data - string (size is length in num bytes)

Example of a 186 bytes long command:

186
{
    "Command": "SetFeatures",
    "Arguments": 
    {
        "Features":
        [
            {"Name": "Console"},
            {"Name": "CodeCompletion"},
            {"Name": "BuildEvent"},
            {"Name": "ShortcutFeature"}
        ]
    }
}

Handshake

The first expected command sent is “SetFeatures”. This command is used to setup the services that are required for the specific features.

List of features:

  • CodeCompletion
  • Console
  • BuildEvent
  • ShortcutFeature

Commands

Example of commands.

Error

{
    "Command": "Error",
    "Arguments": 
    {
        "ErrorString": "Index was out of range",
        "ErrorCode": "InvalidArgument"
    }
}

ErrorCodes:

  • InvalidId = 0
  • InvalidCommand = 1
  • InvalidJSON = 2
  • InvalidArgument = 3
  • FailedToCreateSuggestions = 4
  • InvalidOperation = 5

SetFeatures

{
    "Command": "SetFeatures",
    "Arguments": 
    {
        "Features":
        [
            {"Name": "Console"},
            {"Name": "CodeCompletion"},
            {"Name": "BuildEvent"},
            {"Name": "ShortcutFeature"}
        ]
    }
}

RequestCodeCompletion (Requires CodeCompletion feature)

{
    "Command": "RequestCodeCompletion",
    "Arguments": 
    {
        "QueryId": 2, 
        "Path": "C:\Test.uno",
        "Text": "using Uno;",
        "Type": "uno",
        "CaretPosition": { "Line": 1, "Character": 4 }
    }
}

SetCodeSuggestions (Requires CodeCompletion feature, and is the response of RequestCodeCompletion command)

{
    "Command": "SetCodeSuggestions",
    "Arguments": 
    {
        "QueryId": 2,
        "IsUpdatingCache": true,
        "CodeSuggestions":
        [
            {
                "Suggestion": "Add", 
                "Type": "Method", 
                "ReturnType": "float",
                "AccessModifiers": ["public","static"],
                "FieldModifiers": ["readonly"],
                "MethodArguments": ["float","a","int","b"],
                "PreText": "",
                "PostText": ""
            }
        ]
    }
}

GotoDefinition (Requires CodeCompletion feature)

{
    "Command": "GotoDefinition",
    "Arguments": 
    {
        "QueryId": 2, 
        "Path": "C:\Test.uno",
        "Text": "using Uno;",
        "Type": "uno",
        "CaretPosition": { "Line": 1, "Character": 4 }
    }
}

GotoDefinitionResponse (Requires CodeCompletion feature, and is the response to GotoDefintion command)

{
    "Command": "GotoDefinitionResponse",
    "Arguments": 
    {
        "QueryId": 2, 
        "FoundDefinition": "true",
        "Path": "C:\Test.uno",        "CaretPosition": { "Line": 1, "Character": 4 }
    }
}

WriteToConsole (Requires Console feature)

{
    "Command": "WriteToConsole",
    "Arguments": 
    {
        "Text": "Foo",
        "Type": "DebugLog"
    }
}

Type can be either DebugLog or BuildLog.

NewBuild (Requires BuildEvent feature)

{
    "Command": "NewBuild"
}

Sent when a new build is started. Useful to know, if you want to clear the last build result for example.

BuildEventRaised (Requires BuildEvent feature)

{
    "Command": "BuildEventRaised",
    "Arguments": 
    {
        "Path": "C:\Test.uno",
        "Type": "Error",
        "StartPosition": { "Line": 1, "Character": 4 },
        "EndPosition": { "Line": 1, "Character": 8 },
        "ErrorCode": 0,
        "Message": "Unexpected semicolon after ..."
    }
}

Type can be:

  • Unknown
  • FatalError
  • Error
  • Warning
  • Message

NOTE: EndPosition is optional

BuildAndRun(Requires ShortcutFeature)

{
    "Command": "BuildAndRun"
}

Recompile(Requires ShortcutFeature)

{
    "Command": "Recompile"
}