Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Add new client for V language support #4646

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions clients/lsp-v.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
;;; lsp-v.el --- lsp-mode V integration -*- lexical-binding: t; -*-

;; Copyright (C) 2021 remimimimi
niontrix marked this conversation as resolved.
Show resolved Hide resolved
;; Copyright (C) 2024 niontrix

;; Author: remimimimi
niontrix marked this conversation as resolved.
Show resolved Hide resolved
;; niontrix
;; Keywords: languages,tools

;; This program is free software; you can redistribute it and/or modify
Expand All @@ -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)

Expand Down
Loading