nathankot / company-sourcekit Goto Github PK
View Code? Open in Web Editor NEWCompletion for Swift projects via SourceKit with the help of SourceKitten
Completion for Swift projects via SourceKit with the help of SourceKitten
As per swift-emacs/swift-mode#5 (comment) sourcekittendaemon returns a huge amount of never-ending output
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
NSOBjec
return true
}
Typing NSObject doesn't trigger completion until NSObject<---
Anything before NSObjec <-- won't show completion but will show that there was a file written too.
There already exist backends for swift auto-completion on Linux, such as:
https://github.com/oblitum/swift-ycm-core
And sourceKitten have Linux support already:
jpsim/SourceKitten#179
Is it possible to use it (sourceKitten directly or any small wrapper around it) as fallback - if, or when SourceKittenDaemon unavailable (which not support Linux yet)?
Workspace support on sourcekittendaemon would be required first
I'm hitting an odd error with the offset being off by the beginning of the word. For instance,
import AVFoundation|
^
is reported as
[company-sourcekit] prefix: `AVFoundation`, file: /var/folders/8b/5vz4t2yd5x7116mq280krw4r0000gn/T/sourcekitten56925ebh, offset: 7
It seems that it is subtracting the prefix? I wrote a tiny lisp function to test this:
(defun foo-bar (&optional prefix)
(interactive)
(message "FOOBAR: %d" (- (point) (length prefix) (point-min))))
And it reports the position as FOOBAR: 19
. This causes problems for things such as:
let r = GCR|
^
because this will sent the X-Offset
as 29
(as my other issue shows) causing a 400k+ buffer to fill up with JSON.
Should the length of the prefix be added to current offset (or rather not subtracted as is currently)?
Example:
self.doSome // Doesn't complete me here
self. // If I ask to complete me here, it will show "doSomething" completion
Hey,
First of all I really appreciate the work you're doing on this. Would love to be able to use Emacs for all my Swift dev :)
Just had a quick question about compatibility inside workspaces. The autocompletion works for me inside simple projects but as soon as I'm in a project relying on a workspace I get no completion at all, even for built-in types. Just wondering if that's normal or is my configuration broken somewhere?
Cheers!
Will need to derive and send the correct flags to sourcekitten. It's best that this happens automatically simply by inspecting the .xcodeproj
or .xcworkspace
.
Here is what XCode sends to sourcekit when doing completion in a project:
I don't think everything is required but we should try to emulate the important bits:
key.compilerargs: [
"-module-name",
"Rumuki",
"-O",
"-DAPI_NATHAN",
"-DDEBUG",
"-sdk",
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk",
"-target",
"x86_64-apple-ios8.0",
"-g",
"-module-cache-path",
"/Users/nathan/Library/Developer/Xcode/DerivedData/ModuleCache",
"-Xfrontend",
"-serialize-debugging-options",
"-I",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Products/Nathan-iphonesimulator",
"-F",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Products/Nathan-iphonesimulator",
"-F",
"/Users/nathan/Development/Apps/rumuki/ios/Carthage/Build/iOS",
"-c",
"-j4",
"/Users/nathan/Development/Apps/rumuki/ios/Rumuki/Cryptography/CryptHelpers.swift",
"/Users/nathan/Development/Apps/rumuki/ios/Rumuki/HTTP/Api.swift",
"/Users/nathan/Development/Apps/rumuki/ios/Rumuki/UserInterface/Components/RecordingListEmptyBackgroundComponent.swift",
"/Users/nathan/Development/Apps/rumuki/ios/Rumuki/AudioVideo/Library/AVCNALHelpers.swift",
"/* ... long list of source files */",
"-emit-module",
"-emit-module-path",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Objects-normal/x86_64/Rumuki.swiftmodule",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/swift-overrides.hmap",
"-Xcc",
"-iquote",
"-Xcc",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Rumuki-generated-files.hmap",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Rumuki-own-target-headers.hmap",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Rumuki-all-non-framework-target-headers.hmap",
"-Xcc",
"-ivfsoverlay",
"-Xcc",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/all-product-headers.yaml",
"-Xcc",
"-iquote",
"-Xcc",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Rumuki-project-headers.hmap",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Products/Nathan-iphonesimulator/include",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/DerivedSources/x86_64",
"-Xcc",
"-I/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/DerivedSources",
"-Xcc",
"-DDEBUG=1",
"-Xcc",
"-DDEBUG=1",
"-emit-objc-header",
"-emit-objc-header-path",
"/Users/nathan/Library/Developer/Xcode/DerivedData/Rumuki-famrqdkrtmqhvkawkbxggtwiipsp/Build/Intermediates/Rumuki.build/Nathan-iphonesimulator/Rumuki.build/Objects-normal/x86_64/Rumuki-Swift.h",
"-import-objc-header",
"/Users/nathan/Development/Apps/rumuki/ios/Rumuki/BridgingHeader.h",
"-Xcc",
"-working-directory/Users/nathan/Development/Apps/rumuki/ios"
]
I import ZipZap in my workspace
If i type
entry.
can't complete.
import Foundation
import ZipZap
let filename = "test.zip"
if (FileManager.default.fileExists(atPath: filename)) {
var url = URL(fileURLWithPath: filename)
do
{
var archive = try ZZArchive(url: url)
for entry in archive.entries
{
let fileName = entry.fileName
entry. // error here, Can't complete
print(fileName)
}
}
catch
{
debugPrint("Error")
}
}
@terhechte as per #1, here's a list of things I think need to be done. Feel free to edit at will.
-project
and -workspace
flags, via #3--compilerargs
, see #4For project support we can simply check for common cocoapods/carthage framework paths and add them with -F
. -sdk
and -target
detection might be more involving...
Wrote /var/folders/k2/y7hdq90906d_5pgbt3_pt9jw0000gn/T/sourcekitten37241uWD [11 times]
Saving file /Users//messagebottle/AppDelegate.swift...
Wrote /Users//AppDelegate.swift
Wrote /var/folders/k2/y7hdq90906d_5pgbt3_pt9jw0000gn/T/sourcekitten37241uWD [15 times]
Saving file /Users//AppDelegate.swift...
Wrote /Users//AppDelegate.swift
Wrote /var/folders/k2/y7hdq90906d_5pgbt3_pt9jw0000gn/T/sourcekitten37241uWD [18 times]
(setq company-sourcekit-verbose nil)
(setq sourcekit-verbose nil)
are nil.
Seems to be writing to a file after every (single) character is typed.
I don't know if the development of this package is stopped. The last commit date on master branch was 7 months ago (Jun 5, 2016). Is there a change to improve the performance and accuracy?
There is a NeoVim plugin called Autocomplete-swift, which just uses SourceKitten as its back-end. When I tried to code with company-sourcekit(latest) in emacs(25.1.1) like the gif screenshot in its README, it went to totally mass.
As the above picture shows, when type var|
, the completion list appeared, then type SPACE, it got completed like this:
Going on, type String|
,
then type SPACE, got this
... ...
I use the latest SourceKittenDaemon code compiled with Sourcekitten 0.15.0 and Xcode 8.2 a few days ago.
It seems that SourceKittenDaemon is not actively developed either, will it improve the performance and accuracy by just using SourceKitten as the back-end?
Or could we port Autocomplete-swift into emacs?
Thanks.
import Foundation
let x = "Hello"
func test(x: String) -> String {
return x + " World"
}
let y = te // Completion doesn't work
But if we write
let y = Temp.te // Completion works perfectly
where Temp
is module name
[sourcekit] process message: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance[sourcekit] process message: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
how can i fix this? bros.
We can improve company integration by adding swift
keywords:
(eval-after-load 'company-keywords
'(add-to-list 'company-keywords-alist
'(swift-mode "true" "false" "nil" "available" "column" "elseif" "else" "endif" "file" "function" "if" "line" "selector" "associatedtype" "class" "deinit" "enum" "extension" "fileprivate" "func" "import" "init" "inout" "internal" "let" "open" "operator" "private" "protocol" "public" "static" "struct" "subscript" "typealias" "var" "break" "case" "continue" "default" "defer" "do" "else" "fallthrough" "for" "guard" "if" "in" "repeat" "return" "switch" "where" "while" "as" "catch" "dynamicType" "is" "rethrows" "super" "self" "Self" "throws" "throw" "try" "Protocol" "Type" "and" "assignment" "associativity" "convenience" "didSet" "dynamic" "final" "get" "higherThan" "indirect" "infix" "lazy" "left" "lowerThan" "mutating" "none" "nonmutating" "optional" "override" "postfix" "precedence" "precedencegroup" "prefix" "required" "right" "set" "unowned" "weak" "willSet")))
Surely, will be better to get that list from swift-mode
, but currently there's no plain list of keywords there.
Please, prompt the right upstream, where it should be added: here, in company-mode
or in swift-mode
?
Sorry,
but how could I achieve the code completion speed the gif demo showed? It is so slow as to be pretty much unusable.
The sourcekit-output-buffer
has been kept on filling with too much JSON output (tens of thousands of lines), the completion work is endured endless waiting.
Hey guys.
I'm supper new to emacs and I don't know how to make this package work.
I've installed SourceKitten, SourceKittenDaemon and the company-sourcekit package, but I don't know to to make it work.
Is there any possibility to provide a step by step o how to configure it properly?
I would really appreciate that because I really would like to use emacs as an iOS development IDE.
Thanks.
Is it possible to implement inspecting symbol's type just like we do in Xcode with โฅ-click
?
Company mode not being automatically enable company-sourcekitten, instead it turn on some kind of "general" mode, when it's trying to complete me based not on sourcekitten.
When I type a few chars, I got:
And only when I run company-sourcekit
, the real completion is showing up:
Could you please point me at what I am doing wrong?
I have
(setq company-backends
'(company-files
company-keywords
company-capf
company-yasnippet
company-abbrev
company-dabbrev
company-dabbrev-code))
and
(defun company-sourcekit-init ()
"Enable sourcekit backend for company."
(eval-after-load 'company
'(add-to-list
(make-local-variable 'company-backends)
'company-sourcekit)))
(add-hook 'swift-mode-hook 'company-sourcekit-init)
so, company-sourcekit
mostly works for now. But company-yasnippet
work only when I manually call M-x company-yasnippet
. General company-complete
or show sourcekit variants only, or do just nothing at all.
I havent successfully configured company-sourcekit to work with other backends. It will always swallow their result. If I set company-sourcekit at the end of my list it wont start.
Any example how to get this working with either :separate or :with
https://company-mode.github.io/manual/Backends.html
I want to use company-keywords, company-debbrev-code company-tabnine and company-sourcekit.
Getting same offsets (and same completions) while adding extra characters to the prefix.
Added a dropbox video.
https://dl.dropboxusercontent.com/u/11400324/Untitled.mov
import UIKit
class SentBottlesController: UIViewController {
override func loadView() {
self.view = SentBottlesView.init()
self.[view] <-- every letter in view returns the same completions (incorrect candidates)
}
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Sent"
}
}
When
'(request-backend (quote url-retrieve))
it not work with localhost
, but work with 0.0.0.0
.
Hi, @nathankot
I've seen the latest two commits (6c0c783 and 0c3ccf9) by you trying to silent the writing message and then reverted. Maybe the code (write-region (point-min) (point-max) tmpfile 'silent)
in 6c0c783 was wrong:
The arguments for write-region
:
(write-region START END FILENAME &optional APPEND VISIT LOCKNAME MUSTBENEW)
The optional fourth argument APPEND
should be set to nil
. The right code should be:
(write-region (point-min) (point-max) tmpfile nil 'silent)
.
Could we turn off the writing message which is really annoying?
Thanks and happy new year :)
Hello, I have set up company-sorcekit and now if I type "CGRect(" after a fraction of second it appears a list of suggestion, as in your demo video.
soft question: is it possible to make that fraction of second smaller? For instance with company I use
(setq company-idle-delay 0.01)
(setq company-dabbrev-downcase 0.01)
in order to cut the time that I have to wait before seeing the suggestions, but this does not seem to affect company-sourcekit.
But the real problem is the following: If I type (inside a method of a class) "self.", the suggestions are showed after 5 seconds! It is an eternity!
This happen also with various other variables.
Is this the default behaviour, is it a known bug or maybe I am not using company-sourcekit correctly?
I would like to cut down that time or to bind a key, for instance S-TAB, to the function that shows the suggestions. In other word I would like that typing "self." (or maybe typing "self." S-TAB) emacs would show me the suggestions immediately.
Is it possible?
Thank you in advance!
Luca.
Should be able to access documentation by using company-mode's doc-buffer
. sourcekitten complete
doesn't actual return documentation information so maybe sourcekitten doc
?
Currently it just resets the completion.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.