[SQL] Add lsp support
This commit is contained in:
parent
244b3f58a2
commit
403aef6fd4
|
@ -3278,6 +3278,8 @@ Other:
|
|||
- Use correct error list faces when defining error levels with custom bitmaps
|
||||
(thanks to Alexander Miller)
|
||||
- Fixed =goto-flycheck-error-list= (thanks to Thanh Vuong)
|
||||
- Added lsp support for sqls
|
||||
- Added layer variable =sql-lsp-sqls-workspace-config-path= to setting workspace configuration
|
||||
**** Swift
|
||||
- Update Swift REPL key bindings (thanks to Elliot Bulmer)
|
||||
**** Systemd
|
||||
|
|
|
@ -44,6 +44,7 @@ This layer adds support for a wide range of SQL dialects to Spacemacs.
|
|||
- Snippet insertion for the more general SQL constructs.
|
||||
- REPL support via =SQLi= buffer.
|
||||
- Automatic capitalization of keywords.
|
||||
- LSP support via [[https://github.com/lighttiger2505/sqls][sqls]].
|
||||
|
||||
* Install
|
||||
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
||||
|
@ -53,17 +54,42 @@ file.
|
|||
** External Dependencies
|
||||
Some functionality, like linting, rely on external binaries:
|
||||
- *Syntax Checking*: Install [[https://www.ruby-lang.org/en/about/][ruby]] and the =sqlint= gem.
|
||||
- *Formatting*: Install [[https://github.com/mjibson/sqlfmt][sqlfmt]] and move it into your =$PATH=
|
||||
|
||||
#+BEGIN_SRC ruby
|
||||
gem install sqlint
|
||||
#+END_SRC
|
||||
|
||||
- *Formatting*: Install [[https://github.com/mjibson/sqlfmt][sqlfmt]] and move it into your =$PATH=
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
# Download and extract the binary 0.4.0 for linux
|
||||
wget -q -O - https://github.com/mjibson/sqlfmt/releases/latest/download/sqlfmt_0.4.0_linux_amd64.tar.gz | tar -xpvzf - --directory "${installdir}/bin"
|
||||
#+END_SRC
|
||||
|
||||
- *LSP supporting (sqls)*:
|
||||
- Install [[https://golang.org/dl/][Go]]lang and [[https://github.com/lighttiger2505/sqls][sqls]], then setting the variable =sql-backend= to ='lsp=.
|
||||
- One of way to connect DB is setting variable =sql-lsp-sqls-workspace-config-path= to ='workspace= or ='root= and put json file at these directory.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq-default dotspacemacs-configuration-layers '(
|
||||
(sql :variables
|
||||
sql-backend 'lsp
|
||||
sql-lsp-sqls-workspace-config-path 'workspace)))
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC json
|
||||
{
|
||||
"sqls": {
|
||||
"connections": [
|
||||
{
|
||||
"driver": "mysql",
|
||||
"dataSourceName": "user1:password1@tcp(localhost:3306)/sample_db"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** SQL Keywords Capitalization
|
||||
SQL, by convention, uses upper-case keywords, although lower-case works just as
|
||||
well. As humans, the separation between upper-case and lower-case helps scan and
|
||||
|
|
|
@ -22,3 +22,13 @@
|
|||
|
||||
(defvar sql-auto-indent t
|
||||
"If non nil use sql-indent.")
|
||||
|
||||
(defvar sql-backend nil
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `lsp' and `company-sql'.
|
||||
If `nil' then 'company-sql` is the default backend unless `lsp' layer is used")
|
||||
|
||||
(defvar sql-lsp-sqls-workspace-config-path 'workspace
|
||||
"Setup workspace configuration with json file. Possible values are:
|
||||
`workspace': {workspace directory}/.sqls/config.json
|
||||
`root': {root directory of workspace}/.sqls/config.json")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; funcs.el --- SQL Layer functions 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
|
||||
|
@ -16,3 +16,28 @@
|
|||
spacemacs-sql-startable (remove-if-not
|
||||
(lambda (product) (sql-get-product-feature (car product) :sqli-program))
|
||||
sql-product-alist)))
|
||||
|
||||
(defun spacemacs//sql-backend ()
|
||||
"Returns selected backend."
|
||||
(if sql-backend
|
||||
sql-backend
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'company-sql))))
|
||||
|
||||
(defun spacemacs//sql-setup-company ()
|
||||
"Conditionally setup company based on backend."
|
||||
(pcase (spacemacs//sql-backend)
|
||||
('company-sql (spacemacs|add-company-backends
|
||||
:backends company-capf
|
||||
:modes sql-mode))
|
||||
;; Activate lsp company explicitly to activate
|
||||
;; standard backends as well
|
||||
(`lsp (spacemacs|add-company-backends
|
||||
:backends company-capf
|
||||
:modes sql-mode))))
|
||||
|
||||
(defun spacemacs//sql-setup-backend ()
|
||||
"Conditionally setup sql backend."
|
||||
(pcase (spacemacs//sql-backend)
|
||||
(`lsp (lsp))))
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
;;; layers.el --- SQL Layer declarations File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(when (and (boundp 'sql-backend)
|
||||
(eq sql-backend 'lsp))
|
||||
(configuration-layer/declare-layer-dependencies '(lsp)))
|
|
@ -14,6 +14,7 @@
|
|||
company
|
||||
org
|
||||
sql
|
||||
sql-mode
|
||||
;; This mode is more up-to-date than the MELPA one.
|
||||
;; Turns out that it is available in GNU ELPA but we cannot
|
||||
;; force Spacemacs to fetch from it for now, it will always
|
||||
|
@ -172,7 +173,20 @@
|
|||
"bS" 'sql-save-connection)
|
||||
|
||||
(add-hook 'sql-interactive-mode-hook
|
||||
(lambda () (toggle-truncate-lines t))))))
|
||||
(lambda () (toggle-truncate-lines t)))
|
||||
|
||||
;; lsp-sqls
|
||||
(let ((path-config (cond
|
||||
((equal sql-lsp-sqls-workspace-config-path 'workspace) "workspace")
|
||||
((equal sql-lsp-sqls-workspace-config-path 'root) "root")
|
||||
(t nil))))
|
||||
(setq lsp-sqls-workspace-config-path path-config)))))
|
||||
|
||||
(defun sql/init-sql-mode ()
|
||||
(use-package sql-mode
|
||||
:defer t
|
||||
:init (add-hook 'sql-mode-hook
|
||||
'spacemacs//sql-setup-backend)))
|
||||
|
||||
(defun sql/init-sql-indent ()
|
||||
(use-package sql-indent
|
||||
|
@ -207,9 +221,7 @@
|
|||
sql-capitalize-keywords-blacklist)))))
|
||||
|
||||
(defun sql/post-init-company ()
|
||||
(spacemacs|add-company-backends
|
||||
:backends company-capf
|
||||
:modes sql-mode))
|
||||
(spacemacs//sql-setup-company))
|
||||
|
||||
(defun sql/pre-init-org ()
|
||||
(spacemacs|use-package-add-hook org
|
||||
|
|
Loading…
Reference in New Issue