Swift autocompleter for Sublime Text, via the adorable SourceKitten framework

Related tags

Tools SwiftKitten
Overview

SwiftKitten

SwiftKitten is a Swift autocompleter for Sublime Text, via the adorable SourceKitten framework. Faster than XCode !

This package is new and still in beta! I welcome any suggestions. If you find a bug, please open an issue. If you want to contribute, feel free to fork and submit a pull request.

Installation

First, make sure to install SourceKitten !

SwiftKitten is available via Package Control.

To install manually, clone this repository into your packages directory:

git clone https://github.com/johncsnyder/SwiftKitten.git

In Sublime, run Preferences: Browse Packages from the command palette to find your packages directory.

Dependencies

The dependencies are included with the SwiftKitten package.

ijson

SwiftKitten uses ijson to parse completions results from SourceKitten. By default, SwiftKitten will use the pure python backend. If the faster yajl2_cffi backend is available, SwiftKitten will automatically load it. It is highly recommended that you build the cffi backend.

cffi [optional]

Navigate to [Packages]/SwiftKitten/cffi/ and run python setup.py build. This will build cffi in place. Maybe sure to run this command with python3.3. Must be compatible with Sublime. Next time you start Sublime, SwiftKitten will load the yajl2_cffi backend.

Caching

SwiftKitten uses pygments to parse autocomplete prefixes and caches the result for the next time you request it. There will be a slight delay the first time you autocomplete a function, but the next time, it will be instantaneous. For example

SwiftKitten will remember the autocomplete results for foo and cache them. The next time you type foo., SwiftKitten will return the cached results. Also, an autocomplete request will be sent if the cached results have timed out (See cache_timeout in package settings). If the results have changed, SwiftKitten will update the autocomplete window. A default cache timeout of one second ensures you will always be shown up-to-date results, while preventing a barrage of unnecessary requests to SourceKitten.

To clear the cache manually, run SwiftKitten: Clear Cache from the command palette (this clears the framework cache also).

Frameworks

SwiftKitten parses your file to find imported frameworks automatically. SwiftKitten requests and caches framework globals separately, since they are only needed once and requesting them via SourceKitten can take a while (e.g. 20-30 seconds for Foundation). It is possible to exclude specific frameworks from autocompletion results (See exclude_framework_globals in package settings).

The framework cache is persistant between sessions. It is saved to Sublime's cache folder on saving a view, and is loaded next time SwiftKitten is loaded.

External frameworks

Please provide a list of paths to external frameworks in settings under extra_framework_paths. These are passed to SourceKitten via compilerargs.

Documentation [experimental]

Running SwiftKitten: Display Documentation from the command palette, or by pressing ctrl+alt+d will search a docset (path specified in settings) via docsetutil and display the most relevant entry in an html popup.

Settings

See SwiftKitten.sublime-settings for more settings and information. Copy this file to [Packages]/User to customize the settings.

/*
    SwiftKitten default settings.

    All settings can be overriden in a sublime project file.
*/
{
	/* 
		Path to SourceKitten binary.
		See `https://github.com/jpsim/SourceKitten`.
	*/
	"sourcekitten_binary" : "/usr/local/bin/sourcekitten",

	/*
		sdk to link with. SourceKitten will find the 
		default sdk (OS X) if left blank.
	*/
	"sdk" : "",

	/*
		Extra framework search paths.

		To enable autocompletion for external frameworks, 
		add the path to the directory containing the 
		framework here.
	*/
	"extra_framework_paths" : [],

	/*
		Extra compiler arguments to SourceKitten.
	*/
	"extra_compilerargs" : "",

	/*
		Exclude globals from specific frameworks in auto-
		completion results. For example, `import Foundation`
		adds a lot of bloat to autocomplete results, and can 
		slow down typing.
	*/
	"exclude_framework_globals" : ["Foundation"],

	/*
		Timeout for cached completion data (in seconds).
	*/
	"cache_timeout" : 1.0,
	
	/*
		Limit to number of concurrent completion requests.
	*/
	"concurrent_request_limit" : 4,

	/*
		Enable linting. This will query structure info via
		SourceKitten, and underline any parse errors. Move 
		the cursor to the error position to see the error 
		description in the status bar.
	*/
	"linting" : true,

	/*
        Supress Sublime Text regular completions.
    */
	"suppress_word_completions" : true,
	"suppress_explicit_completions" : true,

	/*
		Path to docset.

		Running `ctrl+alt+d` will search the docset for the
		current word or selection and display the docs in
		a popup.
	*/
	"docsetutil_binary" : "/usr/local/bin/docsetutil",
	"docset" : "/Applications/Xcode.app/Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.OSX.docset"
}

Additionally, settings can be overridden in a sublime project file.

It is recommended to add the following to user or Swift syntax specific preferences:

"auto_complete_triggers": [ {"selector": "source.swift", "characters": "."} ]

Troubleshooting

If autocompletion is not working, pull up the Sublime python console (ctrl+` ) and see if any error messages are reported.

TO DO

  • Add support for multi-file projects/modules (e.g. specified in a sublime project file).

  • Parse Xcode project to get file list and embedded frameworks (similiar to SourceKittenDaemon).

  • Add Xcode build, run and debug commands. Build system is not flexible enough. Specify the xcode project in sublime project file. Or if xcode project in same folder as sublime project, use this one as default.

  • Build cffi automatically on sublime package install ? I'm not sure if sublime's python interpreter has the necessary tools to build it. Tried briefly but could not get it to work.

  • Add support for multiple docsets. Make documentation context aware. Add support for api links, so that documentation can be navigated.

License

SwiftKitten is MIT licensed.

You might also like...
Add validations to your text fields, Group them together and navigate through them via keyboard's return button and accessory view.
Add validations to your text fields, Group them together and navigate through them via keyboard's return button and accessory view.

TFManager Let's say you have multiple UITextFields to get data from users. You need to handle each field keyboard's return key and add an accessory vi

Aplikasi iReader adalah Aplikasi Pemindai Barcode dan Teks untuk iOS & MacOS dengan fitur Text Scanner via Kamera & Import Files.
Aplikasi iReader adalah Aplikasi Pemindai Barcode dan Teks untuk iOS & MacOS dengan fitur Text Scanner via Kamera & Import Files.

Aplikasi iReader adalah Aplikasi Pemindai Barcode dan Teks untuk iOS & MacOS dengan fitur Text Scanner via Kamera & Import Files. Aplikasi ini dibuat dengan SwiftUI, AVKit, dan VisionKit (On Device Machine Learning Processing).

A framework to validate inputs of text fields and text views in a convenient way.

FormValidatorSwift The FormValidatorSwift framework allows you to validate inputs of text fields and text views in a convenient way. It has been devel

Powerful text framework for iOS to display and edit rich text.
Powerful text framework for iOS to display and edit rich text.

YYText Powerful text framework for iOS to display and edit rich text. (It's a component of YYKit) Features UILabel and UITextView API compatible High

A framework to validate inputs of text fields and text views in a convenient way.

FormValidatorSwift The FormValidatorSwift framework allows you to validate inputs of text fields and text views in a convenient way. It has been devel

Text-cli - Command line tool for extracting text from images using Apple's Vision framework
Text-cli - Command line tool for extracting text from images using Apple's Vision framework

text-cli Command line tool for extracting text from images using Apple's Vision

add text(multiple line support) to imageView, edit, rotate or resize them as you want, then render the text on image
add text(multiple line support) to imageView, edit, rotate or resize them as you want, then render the text on image

StickerTextView is an subclass of UIImageView. You can add multiple text to it, edit, rotate, resize the text as you want with one finger, then render the text on Image.

An iOS application 📱 that extracts text real time using camera 📷 and play relevant video from the text
An iOS application 📱 that extracts text real time using camera 📷 and play relevant video from the text

CHARUSAT-SceW It is an iOS application 📱 that scans and extracts text real-time through camera 📷 , if it is detected. It will play relevent video fr

OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.
OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.

Text Chat Accelerator Pack iOS This project is deprecated The OpenTok Text Chat Accelerator Pack for iOS project is now a part of Accelerator Core iOS

An iOS app to turn typed text into images of handwritten text in your own handwriting style.
An iOS app to turn typed text into images of handwritten text in your own handwriting style.

Text-to-Handwritting © 2021 by Daniel Christopher Long An iOS app to turn typed text into images of handwritten text in your own handwriting style. ht

The app allows the user to change text color and text content when the displayed button is clicked
The app allows the user to change text color and text content when the displayed button is clicked

Hello World! App Description This application allows the user to change text color and text content when the displayed button is clicked. App Walk-tho

Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Detecting Text in Natural Image with Connectionist Text Proposal Network (ECCV'16)

Detecting Text in Natural Image with Connectionist Text Proposal Network The codes are used for implementing CTPN for scene text detection, described

SwiftUI-Text-Animation-Library - Text animation library for SwiftUI
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

DGFadingLabel - A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame
DGFadingLabel - A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame

A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame.

Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Framework for biometric authentication (via TouchID) in your application
Framework for biometric authentication (via TouchID) in your application

Features Requirements Communication Installation Usage Intro Biometric authentication availability Feature enabled/disabled for biometric authenticati

Represent and compare versions via semantic versioning (SemVer) in Swift

Version Version is a Swift Library, which enables to represent and compare semantic version numbers. It follows Semantic Versioning 2.0.0. The represe

Communicate via HTTP easily in Swift.

swift-http-client Communicate via HTTP easily in Swift. Table of Contents Installation How to use Contribution Installation Swift Package Manager (Rec

Comments
  • [fix] Fix autocompletion

    [fix] Fix autocompletion

    Fix autocompletion not working in more recent versions of SwiftKitten.

    This was due to the fact that the syntax --compilerargs is not supported anymore.

    opened by viteinfinite 0
  • Not sure how to get it working

    Not sure how to get it working

    Hey. Nice work on this. I'd absolutely love to use Sublime over Xcode.

    I'm not having luck here on getting this working...

    I see on the README it says

    SwiftKitten uses ijson to parse completions results from SourceKitten. By default, SwiftKitten will use the pure python backend. If the faster yajl2_cffi backend is available, SwiftKitten will automatically load it. It is highly recommended that you build the cffi backend.

    I've installed SourceKitten with homebrew but I'm unfamiliar with all things Python - is there anything I need to do for ijson or anything else?

    reloading plugin SwiftKitten.SwiftKitten
    WARNING:root:Failed to import yajl2_cffi backend for ijson.
    plugins loaded
    Package Control: Skipping automatic upgrade, last run at 2016-10-06 12:57:43, next run at 2016-10-06 13:57:43 or after
    Exception in thread Thread-4:
    Traceback (most recent call last):
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 125, in parse_value
        yield ('number', common.number(symbol))
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/common.py", line 158, in number
        number = decimal.Decimal(str_value)
      File "./python3.3/decimal.py", line 590, in __new__
      File "./python3.3/decimal.py", line 4045, in _raise_error
    decimal.InvalidOperation: Invalid literal for Decimal: 'U'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "./python3.3/threading.py", line 901, in _bootstrap_inner
      File "./python3.3/threading.py", line 858, in run
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 415, in _autocomplete
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 378, in _autocomplete_request
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 339, in _parse_completions
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/common.py", line 65, in parse
        for event, value in basic_events:
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 185, in basic_parse
        for value in parse_value(lexer):
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 127, in parse_value
        raise UnexpectedSymbol(symbol, pos)
    ijson.backends.python.UnexpectedSymbol: Unexpected symbol 'U' at 0
    
    Request denied: completion for "" already in progress.
    Request denied: completion for "" already in progress.
    Exception in thread Thread-7:
    Traceback (most recent call last):
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 125, in parse_value
        yield ('number', common.number(symbol))
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/common.py", line 158, in number
        number = decimal.Decimal(str_value)
      File "./python3.3/decimal.py", line 590, in __new__
      File "./python3.3/decimal.py", line 4045, in _raise_error
    decimal.InvalidOperation: Invalid literal for Decimal: 'U'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "./python3.3/threading.py", line 901, in _bootstrap_inner
      File "./python3.3/threading.py", line 858, in run
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 415, in _autocomplete
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 378, in _autocomplete_request
      File "SwiftKitten in /Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package", line 339, in _parse_completions
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/common.py", line 65, in parse
        for event, value in basic_events:
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 185, in basic_parse
        for value in parse_value(lexer):
      File "/Users/dan/Library/Application Support/Sublime Text 3/Installed Packages/SwiftKitten.sublime-package/ijson/ijson/backends/python.py", line 127, in parse_value
        raise UnexpectedSymbol(symbol, pos)
    ijson.backends.python.UnexpectedSymbol: Unexpected symbol 'U' at 0
    
    
    
    opened by Dan2552 7
  • Init functions don’t offer completion options

    Init functions don’t offer completion options

    Got SwiftKitten installed and running quite nicely with cffi. Super snappy, great work.

    The only issue I’ve encountered is that init functions don’t autocomplete correctly. So for instance, typing NSString( won’t offer data: Data, encoding: UInt (among others) as an option to produce the final result of NSString(data: Data, encoding: UInt).

    These functions all show up as autocomplete options if one types NSString. instead, so this feels like an issue with the triggering mechanism and hopefully simple to fix.

    If this were fixed, ST3 + SwiftKitten would be very close to an Xcode replacement for me! I’d love to be able to relegate Xcode to XIB+Storyboard duty. ST3’s build system isn’t 100% up to the task but that’s nothing a simple bash script can’t fix.

    opened by jwells89 0
  • Autocompletion not working on my project files

    Autocompletion not working on my project files

    By default, should SwiftKitten also autocomplete my own Swift files? At the moment it's not doing so.

    Is there something specific I need to setup (maybe in a config file) to get this to work?

    opened by dbarros 0
Owner
John Snyder
John Snyder
Swift CLI for strong-typing images, colors, storyboards, fonts and localizations

Shark Shark is a Swift command line tool that generates type safe enums for your images, colors, storyboards, fonts and localizations. Because Shark r

Kaan Dedeoglu 377 Dec 1, 2022
Strong typed, autocompleted resources like images, fonts and segues in Swift projects

R.swift Get strong typed, autocompleted resources like images, fonts and segues in Swift projects Why use this? It makes your code that uses resources

Mathijs Kadijk 8.9k Jan 6, 2023
SwiftGen is a tool to automatically generate Swift code for resources of your projects

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Jan 5, 2023
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 3, 2023
Laurine - Localization code generator written in Swift. Sweet!

Author's note: Thanks everyone for making Laurine the TOP trending Swift repository in the world - this is amazing and very heart-warming! But this is

Jiri Trecak 1.3k Dec 28, 2022
swiftenv allows you to easily install, and switch between multiple versions of Swift.

Swift Version Manager swiftenv allows you to easily install, and switch between multiple versions of Swift. This project was heavily inspired by pyenv

Kyle Fuller 1.9k Dec 27, 2022
Script to support easily using Xcode Asset Catalog in Swift.

Misen Misen is a script to support using Xcode Asset Catalog in Swift. Features Misen scans sub-directories in the specified Asset Catalog and creates

Kazunobu Tasaka 123 Jun 29, 2022
An Xcode Plugin to convert Objective-C to Swift

XCSwiftr Convert Objective-C code into Swift from within Xcode. This plugin uses the Java applet of objc2swift to do the conversion. Noticed that the

Ignacio Romero Zurbuchen 338 Nov 29, 2022
A modern Swift (5.6) syntax definition for Sublime Text 4

Swift for Sublime This is a WIP version of a modern Swift (5.6) syntax for Sublime Text 4. It uses the latest features of the Sublime Text syntax engi

Will Bond 13 Dec 5, 2022
An adorable little framework and command line tool for interacting with SourceKit.

SourceKitten An adorable little framework and command line tool for interacting with SourceKit. SourceKitten links and communicates with sourcekitd.fr

JP Simard 2.1k Jan 5, 2023