All Projects → tigersoldier → Company Lsp

tigersoldier / Company Lsp

Licence: gpl-3.0
Company completion backend for lsp-mode

Projects that are alternatives of or similar to Company Lsp

Lsp Mode
Emacs client/library for the Language Server Protocol
Stars: ✭ 3,691 (+1450.84%)
Mutual labels:  language-server-protocol, emacs
Lsp Javascript
Stars: ✭ 55 (-76.89%)
Mutual labels:  language-server-protocol, emacs
Fsautocomplete
F# language server using Language Server Protocol
Stars: ✭ 208 (-12.61%)
Mutual labels:  language-server-protocol, emacs
Haskell Ide Engine
The engine for haskell ide-integration. Not an IDE
Stars: ✭ 2,433 (+922.27%)
Mutual labels:  language-server-protocol
Languageserver.jl
An implementation of the Microsoft Language Server Protocol for the julia language.
Stars: ✭ 223 (-6.3%)
Mutual labels:  language-server-protocol
Emacs Rime
RIME ㄓ in Emacs
Stars: ✭ 229 (-3.78%)
Mutual labels:  emacs
Emacs Easy Hugo
Emacs major mode for managing hugo
Stars: ✭ 235 (-1.26%)
Mutual labels:  emacs
Awesome Elisp
A curated list of emacs-lisp development resources
Stars: ✭ 221 (-7.14%)
Mutual labels:  emacs
Vim Lsp Cxx Highlight
Vim plugin for C/C++/ObjC semantic highlighting using cquery, ccls, or clangd
Stars: ✭ 231 (-2.94%)
Mutual labels:  language-server-protocol
Theia
Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
Stars: ✭ 15,920 (+6589.08%)
Mutual labels:  language-server-protocol
Ide Java
Java language support for Atom-IDE
Stars: ✭ 226 (-5.04%)
Mutual labels:  language-server-protocol
Docker Emacs
Dockerized Emacs (GUI)
Stars: ✭ 224 (-5.88%)
Mutual labels:  emacs
Csharp Language Server Protocol
Language Server Protocol in C#
Stars: ✭ 230 (-3.36%)
Mutual labels:  language-server-protocol
Bufler.el
A butler for your buffers. Group buffers into workspaces with programmable rules, and easily switch to and manipulate them.
Stars: ✭ 222 (-6.72%)
Mutual labels:  emacs
Dotemacs
My Emacs configuration
Stars: ✭ 234 (-1.68%)
Mutual labels:  emacs
Live Py Plugin
Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
Stars: ✭ 222 (-6.72%)
Mutual labels:  emacs
Spaceline All The Icons.el
A Spaceline Mode Line theme using All The Icons for Emacs
Stars: ✭ 231 (-2.94%)
Mutual labels:  emacs
.emacs.d
My emacs configuration
Stars: ✭ 224 (-5.88%)
Mutual labels:  emacs
Engine Mode
Minor mode for defining and querying search engines through Emacs.
Stars: ✭ 225 (-5.46%)
Mutual labels:  emacs
Lazyblorg
Blogging with Org-mode for very lazy people
Stars: ✭ 226 (-5.04%)
Mutual labels:  emacs

MELPA Build Status

company-lsp

Company completion backend for lsp-mode.

Completion with snippet expansion.

It provides features that are not available by using company-capf + lsp-mode:

  • Support trigger characters. For example typing . will trigger completion for TypeScript.
  • Use completion item's label as completion labels and replace it with its insertText if available.
  • Fetch completion candidates asynchronously (Thanks @sebastiencs).
  • Apply text edits specified by completion candidates after completion.
  • Do not cache the completion candidates if they are incomplete.
  • Expand snippets on completion (requires yasnippet).

Usage

Company-lsp is available on MELPA. To install it, first setup MELPA, then M-x package-install <RET> company-lsp.

After installing company-lsp, simply add company-lsp to company-backends:

(require 'company-lsp)
(push 'company-lsp company-backends)

Customization

  • company-lsp-cache-candidates: Can be set to 'auto, t, or nil.

    When set to 'auto, company-lsp caches the completion. It sends incremental completion requests to the server if and only if the cached results are incomplete. The candidate list may not be sorted or filtered as the server would for cached completion results.

    When set to t, company-mode caches the completion. It won't send incremental completion requests to the server.

    When set to nil, results are not cached at all. The candidates are always sorted and filtered by the server. Use this option if the server handles caching for incremental completion or sorting/matching provided by the server is critical.

  • company-lsp-async: When set to non-nil, fetch completion candidates asynchronously.

  • company-lsp-enable-snippet: Set it to non-nil if you want to enable snippet expansion on completion. Set it to nil to disable this feature.

  • company-lsp-enable-recompletion: If set to non-nil, when company-lsp finishes completion, it checks if the current point is before any completion trigger characters. If yes, it re-triggers another completion request.

    This is useful in cases such as std is completed as std:: in C++."

Defining completion snippet for a certain language

If the language server for that language doesn't support returning snippets, you can customize the variable company-lsp--snippet-functions do define snippets for candidates. company-lsp--snippet-functions is an alist of (LANGUAGE-ID . SNIPPET-FUNCTION).

LANGUAGE-ID is the language ID defined by the lsp client. Currently there is no good way knowing it other than guessing or reading the code of the lsp client for the language. For example if you use lsp-rust, it's defined as following in lsp-rust.el:

(lsp-define-stdio-client lsp-rust "rust" #'lsp-rust--get-root nil
			 :command-fn #'lsp-rust--rls-command
			 :initialize #'lsp-rust--initialize-client)

The language ID is the second parameter, "rust".

SNIPPET-FUNCTION is a function that transforms a hash table representing the CompletionItem message to a snippet string or nil. Below is an example on how to extact a snippet for Rust function parameters:

(defun company-lsp--rust-completion-snippet (item)
  "Function providing snippet with the rust language.
It parses the function's signature in ITEM (a CompletionItem)
to expand its arguments."
  (-when-let* ((kind (gethash "kind" item))
               (is-function (= kind 3)))
    (let* ((detail (gethash "detail" item))
           (snippet (when (and detail (s-matches? "^\\(pub \\)?\\(unsafe \\)?fn " detail))
                      (-some--> (substring detail (1+ (s-index-of "(" detail)) (s-index-of ")" detail))
                                (replace-regexp-in-string "^[^,]*self\\(, \\)?" "" it)
                                (s-split ", " it)
                                (mapconcat (lambda (x) (format "${%s}" x)) it ", ")))))
      (concat "(" (or snippet "$1") ")$0"))))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].