Skip to content

Commit 3a42468

Browse files
authored
feat: Add Postgres LS (#4755)
* feat: Add Postgres LS * lower priority
1 parent 1fb656e commit 3a42468

File tree

7 files changed

+110
-5
lines changed

7 files changed

+110
-5
lines changed

CHANGELOG.org

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* Add Roc support
3434
* Add support for environment variables in rust analyzer runnables. Allowing the new ~Update Tests (Expect)~ code lens to work as expected.
3535
* Add support for [[https://github.com/mathworks/MATLAB-language-server][MATLAB language server]] (requires [[https://github.com/MathWorks/Emacs-MATLAB-Mode][matlab-mode]]).
36-
* Add support for [[https://github.com/c3lang/c3c][c3 language]] (requires [[https://github.com/c3lang/c3-ts-mode][c3-ts-mode]] and [[https://github.com/pherrymason/c3-lsp][c3lsp]]).
36+
* Add support for [[https://github.com/c3lang/c3c][c3 language]] (requires [[https://github.com/c3lang/c3-ts-mode][c3-ts-mode]] and [[https://github.com/pherrymason/c3-lsp][c3lsp]]).
3737
* Drop support for emacs 27.1 and 27.2
3838
* Add ~lsp-nix-nixd-server-arguments~ to allow passing arguments to the ~nixd~ LSP.
3939
* Improve the lsp-ocaml client (see [[https://github.com/emacs-lsp/lsp-mode/issues/4731][#4731]] for the follow-up issue. MRs: [[https://github.com/emacs-lsp/lsp-mode/pull/4741][#4741]], [[https://github.com/emacs-lsp/lsp-mode/pull/4732][#4732]])
@@ -156,6 +156,7 @@
156156
* Add COBOL support.
157157
* Add Common Lisp support.
158158
* Add YANG support using TypeFox/yang-lsp Server.
159+
* Add Postgres langauge server support.
159160

160161
** Release 8.0.0
161162
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.

clients/lsp-postgres.el

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
;;; lsp-postgres.el --- Postgres client settings. -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2025 Shen, Jen-Chieh
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software: you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
;;
22+
;; LSP client for Postgres language server.
23+
;;
24+
25+
;;; Code:
26+
27+
(require 'lsp-mode)
28+
29+
(defgroup lsp-postgres nil
30+
"LSP support for SQL, using Postgres language server."
31+
:group 'lsp-mode
32+
:link '(url-link "https://github.com/supabase-community/postgres-language-server")
33+
:package-version `(lsp-mode . "9.0.1"))
34+
35+
(defcustom lsp-postgres-server-path nil
36+
"Path points for Postgres language server.
37+
38+
This is only for development use."
39+
:type 'string
40+
:group 'lsp-postgres)
41+
42+
(defcustom lsp-postgres-server-store-path
43+
(expand-file-name "postgres-ls/" lsp-server-install-dir)
44+
"The path to the file in which Postgres ls will be stored."
45+
:type 'file
46+
:group 'lsp-postgres)
47+
48+
(defconst lsp-postgres-download-url-format
49+
"https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools_%s-%s"
50+
"Format to the download url link.")
51+
52+
(defun lsp-postgres--postgres-ls-url ()
53+
"Return Url points to the zls' zip/tar file."
54+
(let* ((x86 (string-prefix-p "x86_64" system-configuration))
55+
(arch (if x86 "x86_64" "aarch64")))
56+
(cl-case system-type
57+
((cygwin windows-nt ms-dos)
58+
(format lsp-postgres-download-url-format arch "pc-windows-msvc"))
59+
(darwin
60+
(format lsp-postgres-download-url-format arch "apple-darwin"))
61+
(gnu/linux
62+
(format lsp-postgres-download-url-format arch "unknown-linux-gnu")))))
63+
64+
(defun lsp-postgres--server-command ()
65+
"Generate startup command for Postgres language server."
66+
(list (or lsp-postgres-server-path
67+
(lsp-package-path 'postgres-ls))
68+
"lsp-proxy"))
69+
70+
(lsp-dependency
71+
'postgres-ls
72+
'(:system "postgres-ls")
73+
`(:download :url ,(lsp-postgres--postgres-ls-url)
74+
:store-path ,(f-join lsp-postgres-server-store-path
75+
(pcase system-type
76+
('windows-nt "postgrestools.exe")
77+
(_ "postgrestools")))
78+
:set-executable? t))
79+
80+
(lsp-register-client
81+
(make-lsp-client
82+
:new-connection (lsp-stdio-connection #'lsp-postgres--server-command)
83+
:major-modes '(sql-mode)
84+
:priority -2
85+
:multi-root t
86+
:server-id 'postgres-ls
87+
:download-server-fn (lambda (_client callback error-callback _update?)
88+
(lsp-package-ensure 'postgres-ls callback error-callback))))
89+
90+
(lsp-consistency-check lsp-postgres)
91+
92+
(provide 'lsp-postgres)
93+
;;; lsp-postgres.el ends here

clients/lsp-sql.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This is only for development use."
5555
:new-connection (lsp-stdio-connection #'lsp-sql--server-command)
5656
:major-modes '(sql-mode)
5757
:priority -1
58+
:multi-root t
5859
:server-id 'sql-ls
5960
:download-server-fn (lambda (_client callback error-callback _update?)
6061
(lsp-package-ensure 'sql-ls callback error-callback))))

clients/lsp-sqls.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ use the current region if set, otherwise the entire buffer."
188188
("switchDatabase" #'lsp-sql-switch-database)
189189
("switchConnections" #'lsp-sql-switch-connection))
190190
:server-id 'sqls
191+
:multi-root t
191192
:initialized-fn (lambda (workspace)
192193
(-> workspace
193194
(lsp--workspace-server-capabilities)

docs/lsp-clients.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,14 @@
11181118
"installation": "go install github.com/sqls-server/sqls@latest",
11191119
"debugger": "Not available"
11201120
},
1121+
{
1122+
"name": "postgres-ls",
1123+
"full-name": "SQL (postgres-ls)",
1124+
"server-name": "postgres-language-server",
1125+
"server-url": "https://github.com/supabase-community/postgres-language-server",
1126+
"installation-url": "https://pgtools.dev/#installation",
1127+
"debugger": "Not available"
1128+
},
11211129
{
11221130
"name": "steep",
11231131
"full-name": "Ruby (Steep)",

lsp-mode.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ As defined by the Language Server Protocol 3.16."
185185
lsp-ltex-plus lsp-lua lsp-fennel lsp-magik lsp-markdown lsp-marksman
186186
lsp-matlab lsp-mdx lsp-meson lsp-metals lsp-mint lsp-mojo lsp-move lsp-mssql
187187
lsp-nextflow lsp-nginx lsp-nim lsp-nix lsp-nushell lsp-ocaml lsp-openscad
188-
lsp-pascal lsp-perl lsp-perlnavigator lsp-php lsp-pls lsp-purescript
189-
lsp-pwsh lsp-pyls lsp-pylsp lsp-pyright lsp-python-ms lsp-qml lsp-r
190-
lsp-racket lsp-remark lsp-rf lsp-roc lsp-roslyn lsp-rubocop lsp-ruby-lsp
191-
lsp-ruby-syntax-tree lsp-ruff lsp-rust lsp-semgrep lsp-shader
188+
lsp-pascal lsp-perl lsp-perlnavigator lsp-php lsp-pls lsp-postgres
189+
lsp-purescript lsp-pwsh lsp-pyls lsp-pylsp lsp-pyright lsp-python-ms
190+
lsp-qml lsp-r lsp-racket lsp-remark lsp-rf lsp-roc lsp-roslyn lsp-rubocop
191+
lsp-ruby-lsp lsp-ruby-syntax-tree lsp-ruff lsp-rust lsp-semgrep lsp-shader
192192
lsp-solargraph lsp-solidity lsp-sonarlint lsp-sorbet lsp-sourcekit
193193
lsp-sql lsp-sqls lsp-steep lsp-svelte lsp-tailwindcss lsp-terraform
194194
lsp-tex lsp-tilt lsp-toml lsp-trunk lsp-ts-query lsp-ttcn3 lsp-typeprof

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ nav:
169169
- ShaderLab: page/lsp-shader.md
170170
- SQL (sql): page/lsp-sql.md
171171
- SQL (sqls): page/lsp-sqls.md
172+
- SQL (postgres-ls): page/lsp-postgres.md
172173
- Standard ML (Millet): page/lsp-sml.md
173174
- Svelte: page/lsp-svelte.md
174175
- Swift: https://emacs-lsp.github.io/lsp-sourcekit

0 commit comments

Comments
 (0)