[vimscript] Add lsp server support

This commit is contained in:
Maximilian Wolff 2020-07-09 22:03:55 +02:00
parent ce5f278a2a
commit 3985f0042b
No known key found for this signature in database
GPG key ID: 2DD07025BFDBD89A
5 changed files with 125 additions and 16 deletions

View file

@ -6,14 +6,64 @@
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#configuration][Configuration]]
- [[#choosing-a-backend][Choosing a backend]]
- [[#company-vimscript][Company-vimscript]]
- [[#lsp][LSP]]
* Description
This layer adds basic support for vimscript and pentadactyl config files.
This layer adds support for vimscript and pentadactyl config files.
** Features:
- Syntax highlighting
- Auto-completion (with LSP)
- Syntax-checking (with LSP)
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =vimscript= to the existing =dotspacemacs-configuration-layers= list in this
file.
* Configuration
All layer configurations can be done by setting layer variables in your dotfile.
No custom user config lines are necessary
** Choosing a backend
This layer provides two alternative backends to choose from.
*** Company-vimscript
This is the default choice if nothing is set and no lsp layer
is loaded in your dotfile. This mode only provides very
limited IDE capabilities. Used best if only small scripts
are edited. To set explicitly set the following in your
dotfile:
#+BEGIN_SRC emacs-lisp
(vimscript :variables vimscript-backend 'company-vimscript)
#+END_SRC
*** LSP
For proper IDE support this backend should be used. It is
based on an external server which will be started automatically
by emacs, once a vimscript file is opened. The keybindings are
the same for all lsp modes so if you are already familiar with
one you should be able to work the same in all modes.
To set explicitly do the following in your dotfile:
#+BEGIN_SRC emacs-lisp
(vimscript :variables
vimscript-backend 'lsp)
#+END_SRC
For this to work you will also need to install
the latest version of the lsp server with below command:
#+BEGIN_SRC sh
npm install -g vim-language-server
#+END_SRC
NOTE: Keybindings for LSP are defined in the
LSP layer. Also it is advisable to have a look
at the autocomplete layer for an optimal
intellisense config for LSP.

View file

@ -1,6 +1,6 @@
;;; config.el --- Vimscript Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
@ -12,3 +12,8 @@
;; variables
(spacemacs|define-jump-handlers vimrc-mode)
(defvar vimscript-backend nil
"The backend to use for IDE features.
Possible values are `lsp' and `company-vimscript'.
If `nil' then 'company-vimscript` is the default backend unless `lsp' layer is used")

View file

@ -0,0 +1,32 @@
;;; funcs.el --- vimscript Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Maximilian Wolff <smile13241324@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs//vimscript-backend ()
"Returns selected backend."
(if vimscript-backend
vimscript-backend
(cond
((configuration-layer/layer-used-p 'lsp) 'lsp)
(t 'company-vimscript))))
(defun spacemacs//vimscript-setup-company ()
"Conditionally setup company based on backend."
(pcase (spacemacs//vimscript-backend)
;; Activate lsp company explicitly to activate
;; standard backends as well
(`lsp (spacemacs|add-company-backends
:backends company-capf
:modes vimrc-mode))))
(defun spacemacs//vimscript-setup-backend ()
"Conditionally setup vimscript backend."
(pcase (spacemacs//vimscript-backend)
(`lsp (lsp))))

View file

@ -0,0 +1,14 @@
;;; layers.el --- vimscript Layer layers File for Spacemacs
;;
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Maximilian Wolff <smile13241324@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(when (and (boundp 'vimscript-backend)
(eq vimscript-backend 'lsp))
(configuration-layer/declare-layer-dependencies '(lsp)))

View file

@ -1,6 +1,6 @@
;;; packages.el --- vimscript Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
@ -9,14 +9,21 @@
;;
;;; License: GPLv3
(setq vimscript-packages
'(
vimrc-mode
ggtags
counsel-gtags
helm-gtags
dactyl-mode
))
(defconst vimscript-packages
'(
company
flycheck
vimrc-mode
ggtags
counsel-gtags
helm-gtags
dactyl-mode))
(defun vimscript/post-init-company ()
(spacemacs//vimscript-setup-company))
(defun vimscript/post-init-flycheck ()
(spacemacs/enable-flycheck 'vimrc-mode))
(defun vimscript/init-vimrc-mode ()
"Initialize vimrc package"
@ -26,11 +33,12 @@
:defer t
:init
(progn
(defun spacemacs//vimrc-mode-hook ()
"Hooked function for `vimrc-mode-hook'."
(highlight-numbers-mode -1)
(rainbow-delimiters-mode-disable))
(add-hook 'vimrc-mode-hook 'spacemacs//vimrc-mode-hook))))
(defun spacemacs//vimrc-mode-hook ()
"Hooked function for `vimrc-mode-hook'."
(highlight-numbers-mode -1)
(rainbow-delimiters-mode-disable)
(spacemacs//vimscript-setup-backend))
(add-hook 'vimrc-mode-hook 'spacemacs//vimrc-mode-hook))))
(defun vimscript/init-dactyl-mode ()
(use-package dactyl-mode