[perl5] Add lsp support
This commit is contained in:
parent
feaa63381c
commit
7bdef4109c
5 changed files with 129 additions and 27 deletions
|
@ -8,8 +8,11 @@
|
|||
- [[#description][Description]]
|
||||
- [[#features][Features:]]
|
||||
- [[#install][Install]]
|
||||
- [[#layer][Layer]]
|
||||
- [[#auto-completion-plsense][Auto-completion: PlSense]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#choosing-a-backend][Choosing a backend]]
|
||||
- [[#company-plsense][Company-plsense]]
|
||||
- [[#auto-completion-plsense][Auto-completion: PlSense]]
|
||||
- [[#lsp][LSP]]
|
||||
- [[#key-bindings][Key bindings]]
|
||||
- [[#perldoc][Perldoc]]
|
||||
- [[#pod-and-here-doc][POD and HERE doc]]
|
||||
|
@ -21,20 +24,66 @@ This layer adds support for the Perl5 language.
|
|||
|
||||
** Features:
|
||||
- Syntactic and semantic checking using [[https://github.com/flycheck/flycheck][flycheck]]
|
||||
- Auto-completion using [[https://github.com/CeleritasCelery/company-plsense][company-plsense]]
|
||||
- Auto-completion
|
||||
- Format code with =perltidy=
|
||||
- Jump to symbol definition
|
||||
- Interactive debug via [[https://github.com/realgud/realgud][realgud]] with [[http://search.cpan.org/~rocky/Devel-Trepan-0.73/lib/Devel/Trepan.pm][trepan.pl]]
|
||||
- LSP and DAP support
|
||||
|
||||
* Install
|
||||
** Layer
|
||||
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
||||
add =perl5= to the existing =dotspacemacs-configuration-layers= list in this
|
||||
file.
|
||||
|
||||
** Auto-completion: PlSense
|
||||
* 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-plsense
|
||||
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 files
|
||||
are edited. To set explicitly set the following in your
|
||||
dotfile:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(perl5 :variables perl5-backend 'company-plsense)
|
||||
#+END_SRC
|
||||
|
||||
**** Auto-completion: PlSense
|
||||
=company-plsense= requires installation of the =plsense= server from [[https://github.com/aki2o/plsense#install][here]].
|
||||
|
||||
*** 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 perl5 file is opened. The key bindings 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
|
||||
(perl5 :variables
|
||||
perl5-backend 'lsp)
|
||||
#+END_SRC
|
||||
|
||||
For this to work you will also need to obtain
|
||||
the latest version of the lsp server from [[https://github.com/richterger/Perl-LanguageServer][here]].
|
||||
|
||||
Alternatively the server can be installed with:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
cpan Perl::LanguageServer
|
||||
#+END_SRC
|
||||
|
||||
NOTE: Key bindings 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.
|
||||
|
||||
* Key bindings
|
||||
** Perldoc
|
||||
Browse formatted perldocs.
|
||||
|
|
|
@ -16,3 +16,8 @@
|
|||
|
||||
(defvar perl5-perltidy-options '()
|
||||
"Command line options to pass to perltidy")
|
||||
|
||||
(defvar perl5-backend nil
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `lsp' and `company-plsense'.
|
||||
If `nil' then 'company-plsense` is the default backend unless `lsp' layer is used")
|
||||
|
|
|
@ -9,6 +9,36 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(defun spacemacs//perl5-backend ()
|
||||
"Return selected backend."
|
||||
(if perl5-backend
|
||||
perl5-backend
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'company-plsense))))
|
||||
|
||||
(defun spacemacs//perl5-setup-company ()
|
||||
"Conditionally setup company based on backend."
|
||||
(pcase (spacemacs//perl5-backend)
|
||||
;; Activate lsp company explicitly to activate
|
||||
;; standard backends as well
|
||||
(`lsp (spacemacs|add-company-backends
|
||||
:backends company-capf
|
||||
:modes cperl-mode))
|
||||
(`company-plsense (spacemacs|add-company-backends)
|
||||
:backends company-plsense
|
||||
:modes cperl-mode)))
|
||||
|
||||
(defun spacemacs//perl5-setup-backend ()
|
||||
"Conditionally setup perl5 backend."
|
||||
(pcase (spacemacs//perl5-backend)
|
||||
(`lsp (lsp))))
|
||||
|
||||
(defun spacemacs//perl5-setup-dap ()
|
||||
"Conditionally setup perl5 DAP integration."
|
||||
;; currently DAP is only available using LSP
|
||||
(pcase (spacemacs//perl5-backend)
|
||||
(`lsp (add-hook 'cperl-mode-hook #'dap-mode))))
|
||||
|
||||
(defun spacemacs//perl5-smartparens-enable ()
|
||||
(define-key cperl-mode-map "{" nil))
|
||||
|
|
14
layers/+lang/perl5/layers.el
Normal file
14
layers/+lang/perl5/layers.el
Normal file
|
@ -0,0 +1,14 @@
|
|||
;;; layers.el --- Perl5 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 'perl5-backend)
|
||||
(eq perl5-backend 'lsp))
|
||||
(configuration-layer/declare-layer-dependencies '(lsp)))
|
|
@ -9,23 +9,27 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(setq perl5-packages
|
||||
'(
|
||||
(company-plsense :requires company)
|
||||
(cperl-mode :location built-in)
|
||||
flycheck
|
||||
org
|
||||
realgud
|
||||
smartparens
|
||||
))
|
||||
(defconst perl5-packages
|
||||
'(
|
||||
(company-plsense :requires company)
|
||||
(cperl-mode :location built-in)
|
||||
flycheck
|
||||
org
|
||||
dap-mode
|
||||
realgud
|
||||
smartparens))
|
||||
|
||||
(defun perl5/pre-init-dap-mode ()
|
||||
(pcase (spacemacs//perl5-backend)
|
||||
(`lsp (add-to-list 'spacemacs--dap-supported-modes 'cperl-mode)
|
||||
(add-hook 'cperl-mode-hook #'dap-mode))))
|
||||
|
||||
(defun perl5/post-init-company ()
|
||||
(spacemacs//perl5-setup-company))
|
||||
|
||||
(defun perl5/init-company-plsense ()
|
||||
(use-package company-plsense
|
||||
:defer t
|
||||
:init
|
||||
(spacemacs|add-company-backends
|
||||
:backends company-plsense
|
||||
:modes cperl-mode)))
|
||||
:defer t))
|
||||
|
||||
(defun perl5/init-cperl-mode ()
|
||||
(use-package cperl-mode
|
||||
|
@ -33,7 +37,6 @@
|
|||
:mode "\\.\\(p[lm]x?\\|P[LM]X?\\)\\'"
|
||||
:interpreter "perl"
|
||||
:interpreter "perl5"
|
||||
|
||||
:init
|
||||
(progn
|
||||
(setq
|
||||
|
@ -42,8 +45,8 @@
|
|||
cperl-indent-level 4 ; 4 spaces is the standard indentation
|
||||
cperl-close-paren-offset -4 ; indent the closing paren back four spaces
|
||||
cperl-continued-statement-offset 4 ; if a statement continues indent it to four spaces
|
||||
cperl-indent-parens-as-block t)) ; parentheses are indented with the block and not with scope
|
||||
|
||||
cperl-indent-parens-as-block t) ; parentheses are indented with the block and not with scope
|
||||
(add-hook 'cperl-mode-hook #'spacemacs//perl5-setup-backend))
|
||||
:config
|
||||
(progn
|
||||
;; Don't highlight arrays and hashes in comments
|
||||
|
@ -106,19 +109,20 @@
|
|||
(add-hook 'cperl-mode-hook
|
||||
(lambda () (local-set-key (kbd "<tab>") 'indent-for-tab-command)))
|
||||
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "m=" "format")
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "mg" "find-symbol")
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "mh" "perldoc")
|
||||
(unless (eq (spacemacs//perl5-backend) 'lsp)
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "m=" "format")
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "mg" "find-symbol")
|
||||
(spacemacs/declare-prefix-for-mode 'cperl-mode "mh" "perldoc"))
|
||||
(spacemacs/set-leader-keys-for-major-mode 'cperl-mode
|
||||
"hh" 'cperl-perldoc-at-point
|
||||
"==" 'spacemacs/perltidy-format
|
||||
"=b" 'spacemacs/perltidy-format-buffer
|
||||
"=f" 'spacemacs/perltidy-format-function
|
||||
"hh" 'cperl-perldoc-at-point
|
||||
"hd" 'cperl-perldoc
|
||||
"v" 'cperl-select-this-pod-or-here-doc)
|
||||
|
||||
(font-lock-add-keywords 'cperl-mode
|
||||
'(("\\_<say\\_>" . cperl-nonoverridable-face))))))
|
||||
'(("\\_<say\\_>" . cperl-nonoverridable-face))))))
|
||||
|
||||
(defun perl5/post-init-flycheck ()
|
||||
(spacemacs/enable-flycheck 'cperl-mode))
|
||||
|
|
Reference in a new issue