Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yasnippet compatible? #29

Open
Pitometsu opened this issue May 4, 2017 · 6 comments
Open

yasnippet compatible? #29

Pitometsu opened this issue May 4, 2017 · 6 comments

Comments

@Pitometsu
Copy link

Pitometsu commented May 4, 2017

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.

@Pitometsu
Copy link
Author

Pitometsu commented May 4, 2017

UPD: in case of

import Foundation

var 

Where ⬛ is point,
it show all the completions for yasnippet. But. Without var it do nothing.

@nathankot
Copy link
Owner

Hmm what's the output of M-x describe-variable <RET> company-backends <RET>?

@Pitometsu
Copy link
Author

Pitometsu commented May 5, 2017

company-backends is a variable defined in ‘company.el’.
Its value is shown below.

This variable is safe as a file local variable if its value
satisfies the predicate ‘company-safe-backends-p’.

Documentation:
TL;TD

Value:

(company-sourcekit company-files company-keywords company-capf company-yasnippet company-abbrev company-dabbrev company-dabbrev-code)

Original value was

(company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Local in buffer the-buffer-name.swift; global value is

(company-files company-keywords company-capf company-yasnippet company-abbrev company-dabbrev company-dabbrev-code)

-U:%%- *Help* Top (1,0) (Help) ---------------------------------------------------------

@nathankot
Copy link
Owner

@Pitometsu try putting company-sourcekit at the end of that list :) In general most source-specific completers will work better at the tail of the stack

@Pitometsu
Copy link
Author

@nathankot, thank you for explanation, it works now!

@Pitometsu
Copy link
Author

Pitometsu commented May 8, 2017

@nathankot one more question here:

This solution works with yasnippet backend. So, when it have to snippets to complete, sourcekit backend will start as fallback.


But when I add also company-keywoards or company-dabbrew-code, they are usually have too much completions and will newer loose. So sourcekit will never start.
On the other hand, if I put sourcekit before, it will never release completion for other backends.

You see, where is the problem? If there's even no candidates, sourcekit do not let company-completion fallback to other backens. If previous backends have too much variants, it even don't start to make requests.


My current configuration:

(setq company-echo-delay 0)
(setq company-backends
      '((company-yasnippet
         company-etags
         company-keywords
         company-capf
         company-dabbrev-code
         company-files
         company-abbrev
         company-dabbrev)))
(defun company-sourcekit-init ()
  "Enable sourcekit backend for company."
  (eval-after-load 'company
    '(add-to-list
      ;    vvvvv
      ;    if uncomment, it will not even start
      ;; (last (make-local-variable 'company-backends))
      ;    now it mute other backends even if have no variants
      (make-local-variable 'company-backends)
      ;    ^^^^^
      'company-sourcekit t))
  (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"))))
(add-hook 'swift-mode-hook 'company-sourcekit-init)

@Pitometsu Pitometsu reopened this May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants