From c0daaa0dbba34f3f8375a93638b8a047cb9f7d2b Mon Sep 17 00:00:00 2001 From: Tobias Heinlein Date: Fri, 20 Dec 2024 11:26:11 +0100 Subject: [PATCH 1/2] [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 --- clients/lsp-v.el | 58 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/clients/lsp-v.el b/clients/lsp-v.el index a809a07e935..b39d31bc691 100644 --- a/clients/lsp-v.el +++ b/clients/lsp-v.el @@ -1,7 +1,9 @@ ;;; lsp-v.el --- lsp-mode V integration -*- lexical-binding: t; -*- +;; Copyright (C) 2024 niontrix ;; Copyright (C) 2021 remimimimi +;; Author: niontrix ;; Author: remimimimi ;; Keywords: languages,tools @@ -20,29 +22,67 @@ ;;; Commentary: -;; client for vls, the V language server +;; Basic configuration for V LSP support ;;; Code: (require 'lsp-mode) (defgroup lsp-v nil - "LSP support for V via vls." + "LSP support for V via vls. NOTICE!: `vls' is deprecated" :group 'lsp-mode :link '(url-link "https://github.com/vlang/vls/tree/master")) +(defgroup lsp-v-analyzer nil + "LSP support for V, using v-analyzer." + :group 'lsp-mode + :link '(url-link "https://github.com/vlang/v-analyzer")) + (defcustom lsp-v-vls-executable "vls" - "The vls executable to use. + "NOTICE!: vls is deprecated you should use `v-analyzer' instead. +The vls executable to use. Leave as just the executable name to use the default behavior of -finding the executable with variable `exec-path'." +finding the executable with variable `exec-path'. " :group 'lsp-v - :type 'string) + :type 'string + :package-version '(lsp-mode . "8.0.0")) + +(defcustom lsp-v-analyzer-path "v-analyzer" + "Path to `v-analyzer' +Leave as just the executable name to use the default behavior of +finding the executable with variable `exec-path'. " + :type 'number + :group 'lsp-nim + :package-version '(lsp-mode . "9.0.0")) (lsp-register-client - (make-lsp-client - :new-connection (lsp-stdio-connection (lambda () lsp-v-vls-executable)) - :activation-fn (lsp-activate-on "V") - :server-id 'v-ls)) + (make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-v-vls-executable)) + :activation-fn (lsp-activate-on "V") + :priority -1 + :server-id 'v-ls)) + +(lsp-register-client + (make-lsp-client :new-connection (lsp-stdio-connection + (lambda () lsp-v-analyzer-path)) + :activation-fn (lsp-activate-on "v") + :notification-handlers + (ht ("experimental/serverStatus" #'ignore)) + :language-id "v" + :priority 1 + :server-id 'v-analyzer)) + +(defun lsp-v-analyzer-init () + "Runs the `v-analyzer init' command in the root folder of the current project. +After this `v-analyzer' can be further configured through the file +`.v-analyzer/config.toml'." + (interactive) + (let* ((project-root (lsp--suggest-project-root)) + (default-directory project-root) + (v-analyzer-config ".v-analyzer/config.toml")) + (when (and project-root + (not (file-exists-p v-analyzer-config))) + (message + (shell-command-to-string (concat lsp-v-analyzer-path " init")))))) (lsp-consistency-check lsp-v) From 50633e0082864aada8a63f7e6bb54374340d1e43 Mon Sep 17 00:00:00 2001 From: Tobias Heinlein <46030637+niontrix@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:20:33 +0100 Subject: [PATCH 2/2] [doc]: Fix documentation Merge authors and switch order of copyrights. --- clients/lsp-v.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/lsp-v.el b/clients/lsp-v.el index b39d31bc691..24eff617ebb 100644 --- a/clients/lsp-v.el +++ b/clients/lsp-v.el @@ -1,10 +1,10 @@ ;;; lsp-v.el --- lsp-mode V integration -*- lexical-binding: t; -*- -;; Copyright (C) 2024 niontrix ;; Copyright (C) 2021 remimimimi +;; Copyright (C) 2024 niontrix -;; Author: niontrix ;; Author: remimimimi +;; niontrix ;; Keywords: languages,tools ;; This program is free software; you can redistribute it and/or modify