Skip to content

Commit d28dd6b

Browse files
niontrixTobias Heinlein
and
Tobias Heinlein
authored
[feat]: Add new client for V language support (#4646)
* [feat]: Add new client for V language support Why?: `vls` is deprecated as an LSP server for V. Instead `v-analyzer` is the new and actively developed LSP server. This change addresses the need by: - Add LSP client registration and customization options for `v-analyzer` - Add functionality to initialize configuration for `v-analyzer` to work in a project * [doc]: Fix documentation Merge authors and switch order of copyrights. --------- Co-authored-by: Tobias Heinlein <[email protected]>
1 parent e9230e8 commit d28dd6b

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

clients/lsp-v.el

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
;;; lsp-v.el --- lsp-mode V integration -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2021 remimimimi
4+
;; Copyright (C) 2024 niontrix
45

56
;; Author: remimimimi
7+
;; niontrix
68
;; Keywords: languages,tools
79

810
;; This program is free software; you can redistribute it and/or modify
@@ -20,29 +22,67 @@
2022

2123
;;; Commentary:
2224

23-
;; client for vls, the V language server
25+
;; Basic configuration for V LSP support
2426

2527
;;; Code:
2628

2729
(require 'lsp-mode)
2830

2931
(defgroup lsp-v nil
30-
"LSP support for V via vls."
32+
"LSP support for V via vls. NOTICE!: `vls' is deprecated"
3133
:group 'lsp-mode
3234
:link '(url-link "https://github.com/vlang/vls/tree/master"))
3335

36+
(defgroup lsp-v-analyzer nil
37+
"LSP support for V, using v-analyzer."
38+
:group 'lsp-mode
39+
:link '(url-link "https://github.com/vlang/v-analyzer"))
40+
3441
(defcustom lsp-v-vls-executable "vls"
35-
"The vls executable to use.
42+
"NOTICE!: vls is deprecated you should use `v-analyzer' instead.
43+
The vls executable to use.
3644
Leave as just the executable name to use the default behavior of
37-
finding the executable with variable `exec-path'."
45+
finding the executable with variable `exec-path'. "
3846
:group 'lsp-v
39-
:type 'string)
47+
:type 'string
48+
:package-version '(lsp-mode . "8.0.0"))
49+
50+
(defcustom lsp-v-analyzer-path "v-analyzer"
51+
"Path to `v-analyzer'
52+
Leave as just the executable name to use the default behavior of
53+
finding the executable with variable `exec-path'. "
54+
:type 'number
55+
:group 'lsp-nim
56+
:package-version '(lsp-mode . "9.0.0"))
4057

4158
(lsp-register-client
42-
(make-lsp-client
43-
:new-connection (lsp-stdio-connection (lambda () lsp-v-vls-executable))
44-
:activation-fn (lsp-activate-on "V")
45-
:server-id 'v-ls))
59+
(make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-v-vls-executable))
60+
:activation-fn (lsp-activate-on "V")
61+
:priority -1
62+
:server-id 'v-ls))
63+
64+
(lsp-register-client
65+
(make-lsp-client :new-connection (lsp-stdio-connection
66+
(lambda () lsp-v-analyzer-path))
67+
:activation-fn (lsp-activate-on "v")
68+
:notification-handlers
69+
(ht ("experimental/serverStatus" #'ignore))
70+
:language-id "v"
71+
:priority 1
72+
:server-id 'v-analyzer))
73+
74+
(defun lsp-v-analyzer-init ()
75+
"Runs the `v-analyzer init' command in the root folder of the current project.
76+
After this `v-analyzer' can be further configured through the file
77+
`.v-analyzer/config.toml'."
78+
(interactive)
79+
(let* ((project-root (lsp--suggest-project-root))
80+
(default-directory project-root)
81+
(v-analyzer-config ".v-analyzer/config.toml"))
82+
(when (and project-root
83+
(not (file-exists-p v-analyzer-config)))
84+
(message
85+
(shell-command-to-string (concat lsp-v-analyzer-path " init"))))))
4686

4787
(lsp-consistency-check lsp-v)
4888

0 commit comments

Comments
 (0)