From b2a099230fc9cca5e208c4c84caf62a560a2655c Mon Sep 17 00:00:00 2001 From: Tyler Stromberg Date: Mon, 12 Sep 2016 16:11:15 -0700 Subject: [PATCH] [SourceKit] Document source.request.mangle_simple_class --- tools/SourceKit/docs/Protocol.md | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tools/SourceKit/docs/Protocol.md b/tools/SourceKit/docs/Protocol.md index 506dd48aa2ae2..40b9afaf82391 100644 --- a/tools/SourceKit/docs/Protocol.md +++ b/tools/SourceKit/docs/Protocol.md @@ -23,6 +23,7 @@ The protocol is documented in the following format: | [Code Completion](#code-completion) | source.request.codecomplete | | [Cursor Info](#cursor-info) | source.request.cursorinfo | | [Demangling](#demangling) | source.request.demangle | +| [Mangling](#simple-class-mangling) | source.request.mangle_simple_class | | [Documentation](#documentation) | source.request.docinfo | | [Module interface generation](#module-interface-generation) | source.request.editor.open.interface | | [Indexing](#indexing) | source.request.indexsource | @@ -506,6 +507,77 @@ Welcome to SourceKit. Type ':help' for assistance. } ``` +## Simple Class Mangling + +SourceKit is capable of "mangling" Swift class names. In other words, +it's capable of taking the human-readable `UIKit.ViewController` as input and returning the symbol `_TtC5UIKit14ViewController`. + +### Request + +``` +{ + : (UID) , + : [mangle-request*] // An array of requests to mangle. +} +``` + +``` +mangle-request ::= +{ + : (string) // The Swift module name + : (string) // The class name +} +``` + +### Response + +``` +{ + : (array) [mangle-result+] // The results for each + // mangling, in the order in + // which they were requested. +} +``` + +``` +mangle-result ::= +{ + : (string) // The mangled name. +} +``` + +### Testing + +``` +$ sourcekitd-test -req=mangle [] +``` + +For example, to mangle the name `UIKit.ViewController`: + +``` +$ sourcekitd-test -req=mangle UIKit.ViewController +``` + +Note that when using `sourcekitd-test`, the output is output in an ad hoc text +format, not JSON. + +You could also issue the following request in the `sourcekitd-repl`, which +produces JSON: + +``` +$ sourcekitd-repl +Welcome to SourceKit. Type ':help' for assistance. +(SourceKit) { + key.request: source.request.mangle_simple_class, + key.names: [ + { + key.modulename: "UIKit", + key.name: "ViewController" + } + ] +} +``` + ## Protocol Version SourceKit can provide information about the version of the protocol that is being used.