Can't get completions to work
I'm super new to Swift and Xcode and fairly inexperienced with programming.
But I'm trying to learn Swift, and since Playgrounds are unbearably slow on my old MacBook Air I'm experimenting with Swift in Sublime Text. Not to build anything, just to get the syntax straight.
I figured code completion would be nice to learn more about the available methods and came across SwiftKitten. However it offers no completions and upon investigating a bit I found that I can't seem to get completions to work via the command line tool. Running any kind of sourcekitten complete command:
sourcekitten complete --text "0." --offset 2
# returns: []
sourcekitten complete --text "let hello = 5;hell" --offset 14
# returns: []
sourcekitten complete --text "import UIKit ; UIColor." --offset 22 -- -target arm64-apple-ios13.1 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.1.sdk
# returns: []
.
.
.
just returns an empty list. This is probably due to my own stupidity, however I can't seem to get to the bottom of it.
I'm using Xcode Version 11.1 and running xcode-select -p returns /Applications/Xcode.app/Contents/Developer. I'd really appreciate any help 🤓
Hi Lucas, first off kudos to you for being ambitious and digging into low level details of your programming environment as someone who considers themselves fairly inexperienced with programming!
It looks like it's now necessary to explicitly specify the SDK, whereas previously maybe it was being inferred. This works for me:
$ sourcekitten complete --text "0." --offset 2 -- -sdk `xcrun --show-sdk-path`
[{
"associatedUSRs" : "s:Si23addingReportingOverflowySi12partialValue_Sb8overflowtSiF s:s17FixedWidthIntegerP23addingReportingOverflowyx12partialValue_Sb8overflowtxF",
"context" : "source.codecompletion.context.thisclass",
"descriptionKey" : "addingReportingOverflow(other: Int)",
"docBrief" : "Returns the sum of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.",
"kind" : "source.lang.swift.decl.function.method.instance",
"moduleName" : "Swift",
"name" : "addingReportingOverflow(:)",
"numBytesToErase" : 0,
"sourcetext" : "addingReportingOverflow(<#T##other: Int##Int#>)",
"typeName" : "(partialValue: Int, overflow: Bool)"
},
Truncated for brevity...
Hi Lucas, first off kudos to you for being ambitious and digging into low level details of your programming environment as someone who considers themselves fairly inexperienced with programming!
It looks like it's now necessary to explicitly specify the SDK, whereas previously maybe it was being inferred. This works for me:
$ sourcekitten complete --text "0." --offset 2 -- -sdk `xcrun --show-sdk-path` [{ "associatedUSRs" : "s:Si23addingReportingOverflowySi12partialValue_Sb8overflowtSiF s:s17FixedWidthIntegerP23addingReportingOverflowyx12partialValue_Sb8overflowtxF", "context" : "source.codecompletion.context.thisclass", "descriptionKey" : "addingReportingOverflow(other: Int)", "docBrief" : "Returns the sum of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.", "kind" : "source.lang.swift.decl.function.method.instance", "moduleName" : "Swift", "name" : "addingReportingOverflow(:)", "numBytesToErase" : 0, "sourcetext" : "addingReportingOverflow(<#T##other: Int##Int#>)", "typeName" : "(partialValue: Int, overflow: Bool)" }, Truncated for brevity...
sourcekitten complete --text "import UIKit ; UIColor." --offset 22 -- -sdk 'xcrun --sdk iphoneos --show-sdk-path' #returns: []
just returns an empty list.
I don't know what happened for reference system library.