From a195d47404d79f6686a5f67f74a405bb7aeb2c97 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 30 Oct 2024 20:51:04 +0200 Subject: [PATCH 1/5] Introduce lsp-completion-passthrough-try-completion for lsp-passthrough (#4544) This makes is less "passthrough", but it checks that the string proposed by completion-basic-try-completion is actually a proper prefix of all the available completions. Otherwise no expansion. Which makes it more conservative. --- lsp-completion.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lsp-completion.el b/lsp-completion.el index e2c336fd4b..57604f58b5 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -755,6 +755,20 @@ The CLEANUP-FN will be called to cleanup." "Disable LSP completion support." (lsp-completion-mode -1)) +(defun lsp-completion-passthrough-try-completion (string table pred point) + (let* ((completion-ignore-case t) + (try (completion-basic-try-completion string table pred point)) + (newstr (car try)) + (newpoint (cdr try)) + (beforepoint (and try (substring newstr 0 newpoint)))) + (if (and beforepoint + (string-prefix-p + beforepoint + (try-completion "" table pred) + t)) + try + (cons string point)))) + (defun lsp-completion-passthrough-all-completions (_string table pred _point) "Passthrough all completions from TABLE with PRED." (defvar completion-lazy-hilit-fn) @@ -790,7 +804,7 @@ The CLEANUP-FN will be called to cleanup." (setf (alist-get 'lsp-capf completion-category-defaults) '((styles . (lsp-passthrough)))) (make-local-variable 'completion-styles-alist) (setf (alist-get 'lsp-passthrough completion-styles-alist) - '(completion-basic-try-completion + '(lsp-completion-passthrough-try-completion lsp-completion-passthrough-all-completions "Passthrough completion.")) From 7e2701db204e22989911a22aa35c094568a9c680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9na=C3=AFc=20Huard?= Date: Thu, 31 Oct 2024 03:58:10 +0100 Subject: [PATCH 2/5] Fix infinite recursion in `all-watchable-directories` (#4598) Fixes #4597 --- lsp-mode.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index eec8027ddf..e820bdc39a 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -1986,21 +1986,29 @@ want to watch." (not (lsp--string-match-any ignored-directories full-path))))) -(defun lsp--all-watchable-directories (dir ignored-directories) +(defun lsp--all-watchable-directories (dir ignored-directories &optional visited) "Traverse DIR recursively returning a list of paths that should have watchers. -IGNORED-DIRECTORIES will be used for exclusions" +IGNORED-DIRECTORIES will be used for exclusions. +VISITED is used to track already-visited directories to avoid infinite loops." (let* ((dir (if (f-symlink? dir) (file-truename dir) - dir))) - (apply #'nconc - ;; the directory itself is assumed to be part of the set - (list dir) - ;; collect all subdirectories that are watchable - (-map - (lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories)) - ;; but only look at subdirectories that are watchable - (-filter (lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) - (directory-files dir)))))) + dir)) + ;; Initialize visited directories if not provided + (visited (or visited (make-hash-table :test 'equal)))) + (if (gethash dir visited) + ;; If the directory has already been visited, skip it + nil + ;; Mark the current directory as visited + (puthash dir t visited) + (apply #'nconc + ;; the directory itself is assumed to be part of the set + (list dir) + ;; collect all subdirectories that are watchable + (-map + (lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories visited)) + ;; but only look at subdirectories that are watchable + (-filter (lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) + (directory-files dir))))))) (defun lsp-watch-root-folder (dir callback ignored-files ignored-directories &optional watch warn-big-repo?) "Create recursive file notification watch in DIR. From 9b104105adecf637188f4e3bf5cc228bda12374a Mon Sep 17 00:00:00 2001 From: kiennq Date: Wed, 30 Oct 2024 21:15:56 -0700 Subject: [PATCH 3/5] lsp-start-plain: fix path that can contain spaces (#4601) --- lsp-mode.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index e820bdc39a..f5c700dbf3 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -9925,12 +9925,10 @@ In case the major-mode that you are using for " (let ((start-plain (make-temp-file "plain" nil ".el"))) (url-copy-file "https://raw.githubusercontent.com/emacs-lsp/lsp-mode/master/scripts/lsp-start-plain.el" start-plain t) - (async-shell-command - (format "%s -q -l %s %s" - (expand-file-name invocation-name invocation-directory) - start-plain - (or (buffer-file-name) "")) - (generate-new-buffer " *lsp-start-plain*")))) + (start-process "lsp-start-plain" + (generate-new-buffer " *lsp-start-plain*") + (expand-file-name invocation-name invocation-directory) + "-q" "-l" start-plain (or (buffer-file-name) "")))) From 4f987cb9841d1bd80d2c71c604103d78685b7acd Mon Sep 17 00:00:00 2001 From: Edmund Miller <20095261+edmundmiller@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:51:53 -0600 Subject: [PATCH 4/5] Add Nextflow Support (#4606) * feat: Copy lsp-groovy to lsp-nextflow * chore(nextflow): groovy => nextflow * chore(nextflow): Run lsp-generate-settings * fix(nextflow): Rework install logic * fix(nextflow): Update Nextflow language server installation logic * Add lsp-nextflow-test * chore: Try to start over with actionscript as a template * refactor: Use Nextflow lsp instead of vsix * fix: Add Nextflow-mode to lsp-clients and lsp-mode * fix: It's working? * fix: Reorder client creation and settings * feat: Add initialization function * chore: Bump lsp-mode version * fix: Enable multi-root Idk what this does, but it makes it work * chore: Add TODO * chore: Update formatting * chore: Update Changelog * style: Fix docstring wider than 80 characters * style(nextflow): Fix Summary line --- CHANGELOG.org | 1 + clients/lsp-nextflow.el | 139 ++++++++++++++++++++++++++++++++++++++++ docs/lsp-clients.json | 8 +++ lsp-mode.el | 3 +- mkdocs.yml | 1 + 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 clients/lsp-nextflow.el diff --git a/CHANGELOG.org b/CHANGELOG.org index 45cf126449..2682f60321 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -22,6 +22,7 @@ * Fix zls wrong bin path * Add support for buf CLI ([[https://github.com/bufbuild/buf/releases/tag/v1.43.0][beta]]) * Add fennel support + * Add support for [[https://github.com/nextflow-io/language-server][Nextflow]] ** 9.0.0 * Add language server config for QML (Qt Modeling Language) using qmlls. diff --git a/clients/lsp-nextflow.el b/clients/lsp-nextflow.el new file mode 100644 index 0000000000..917af21543 --- /dev/null +++ b/clients/lsp-nextflow.el @@ -0,0 +1,139 @@ +;;; lsp-nextflow.el --- lsp-mode nextflow integration -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Edmund Miller + +;; Author: Edmund Miller +;; Keywords: lsp, nextflow, groovy + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; LSP Clients for the Nextflow Programming Language. + +;;; Code: + +(require 'lsp-mode) +(require 'f) + +(defgroup lsp-nextflow nil + "LSP support for nextflow, using nextflow-language-server." + :group 'lsp-mode + :link '(url-link "https://github.com/nextflow-io/language-server")) + +(defcustom lsp-nextflow-java-path "java" + "Path of the java executable." + :group 'lsp-nextflow + :type 'string) + +(defcustom lsp-nextflow-version "1.0.0" + "Version of Nextflow language server." + :type 'string + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0")) + +(defcustom lsp-nextflow-server-download-url + (format "https://github.com/nextflow-io/language-server/releases/download/v%s/language-server-all.jar" + lsp-nextflow-version) + "Automatic download url for lsp-nextflow." + :type 'string + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0")) + +(defcustom lsp-nextflow-server-file + (f-join lsp-server-install-dir "nextflow-language-server.jar") + "The path to the file in which `lsp-nextflow' will be stored." + :group 'lsp-nextflow + :risky t + :type 'file + :package-version '(lsp-mode . "9.0.0")) + +(defun lsp-nextflow-server-command () + "Startup command for Nextflow language server." + `("java" "-jar" ,(expand-file-name lsp-nextflow-server-file))) + +(lsp-dependency 'nextflow-lsp + '(:system lsp-nextflow-server-file) + `(:download :url lsp-nextflow-server-download-url + :store-path lsp-nextflow-server-file)) + +;; +;;; Settings + +;; (lsp-generate-settings "~/src/nf-core/vscode-language-nextflow/package.json" 'lsp-nextflow) + +(lsp-defcustom lsp-nextflow-debug nil + "Enable debug logging and debug information in hover hints." + :type 'boolean + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0") + :lsp-path "nextflow.debug") + +(lsp-defcustom lsp-nextflow-files-exclude [".git" ".nf-test" "work"] + "Configure glob patterns for excluding folders from being searched for +Nextflow scripts and configuration files." + :type 'lsp-string-vector + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0") + :lsp-path "nextflow.files.exclude") + +(lsp-defcustom lsp-nextflow-formatting-harshil-alignment nil + "Use the [Harshil Alignment™️](https://nf-co.re/docs/contributing/code_editors_and_styling/harshil_alignment) when formatting Nextflow scripts and config files. + +*Note: not all rules are supported yet*" + :type 'boolean + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0") + :lsp-path "nextflow.formatting.harshilAlignment") + +(lsp-defcustom lsp-nextflow-java-home nil + "Specifies the folder path to the JDK. Use this setting if the extension cannot +find Java automatically." + :type '(choice (const :tag "Auto" nil) + (directory :tag "Custom JDK path")) + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0") + :lsp-path "nextflow.java.home") + +(lsp-defcustom lsp-nextflow-suppress-future-warnings t + "Hide warnings for future changes, deprecations, and removals." + :type 'boolean + :group 'lsp-nextflow + :package-version '(lsp-mode . "9.0.0") + :lsp-path "nextflow.suppressFutureWarnings") + +;; +;;; Client + +(lsp-register-client + (make-lsp-client + ;; FIXME + ;; :download-server-fn (lambda (_client callback error-callback _update?) + ;; (lsp-package-ensure 'nextflow-lsp callback error-callback)) + :new-connection (lsp-stdio-connection #'lsp-nextflow-server-command) + :major-modes '(nextflow-mode) + :multi-root t + :activation-fn (lsp-activate-on "nextflow") + :priority -1 + :initialized-fn (lambda (workspace) + (with-lsp-workspace workspace + (lsp--set-configuration + (lsp-configuration-section "nextflow")))) + ;; TODO Handle preview dag + :server-id 'nextflow-lsp)) + +(lsp-consistency-check lsp-nextflow) + +(provide 'lsp-nextflow) +;;; lsp-nextflow.el ends here diff --git a/docs/lsp-clients.json b/docs/lsp-clients.json index b0b17a587d..0b6c2f7f48 100644 --- a/docs/lsp-clients.json +++ b/docs/lsp-clients.json @@ -677,6 +677,14 @@ "installation": "npm install -g @mdx-js/language-server", "debugger": "Not available" }, + { + "name": "nextflow", + "full-name": "Nextflow", + "server-name": "nextflow-language-server", + "server-url": "https://github.com/nextflow-io/language-server", + "installation-url": "https://github.com/nextflow-io/language-server#build", + "debugger": "Not available" + }, { "name": "nginx", "full-name": "Nginx", diff --git a/lsp-mode.el b/lsp-mode.el index f5c700dbf3..1dad7b75a0 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -182,7 +182,7 @@ As defined by the Language Server Protocol 3.16." lsp-graphql lsp-groovy lsp-hack lsp-haskell lsp-haxe lsp-idris lsp-java lsp-javascript lsp-jq lsp-json lsp-kotlin lsp-latex lsp-lisp lsp-ltex lsp-lua lsp-fennel lsp-magik lsp-markdown lsp-marksman lsp-mdx lsp-meson lsp-metals lsp-mint - lsp-mojo lsp-move lsp-mssql lsp-nginx lsp-nim lsp-nix lsp-nushell lsp-ocaml + lsp-mojo lsp-move lsp-mssql lsp-nextflow lsp-nginx lsp-nim lsp-nix lsp-nushell lsp-ocaml lsp-openscad lsp-pascal lsp-perl lsp-perlnavigator lsp-php lsp-pls lsp-purescript lsp-pwsh lsp-pyls lsp-pylsp lsp-pyright lsp-python-ms lsp-qml lsp-r lsp-racket lsp-remark lsp-rf lsp-roslyn lsp-rubocop lsp-ruby-lsp @@ -835,6 +835,7 @@ Changes take effect only when a new session is started." (java-ts-mode . "java") (jdee-mode . "java") (groovy-mode . "groovy") + (nextflow-mode . "nextflow") (python-mode . "python") (python-ts-mode . "python") (cython-mode . "python") diff --git a/mkdocs.yml b/mkdocs.yml index 2c7912e033..51df17aa94 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -118,6 +118,7 @@ nav: - Move: page/lsp-move.md - MDX: page/lsp-mdx.md - MSSQL: https://emacs-lsp.github.io/lsp-mssql + - Nextflow: page/lsp-nextflow.md - Nginx: page/lsp-nginx.md - Nim: page/lsp-nim.md - Nix (nixd-lsp): page/lsp-nix-nixd.md From 2f72a48503a637f9596a5ee9cc6ba5cde957b59e Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Fri, 8 Nov 2024 09:18:20 +0000 Subject: [PATCH 5/5] Deal with 'workspace/diagnostic/refresh' message (#4600) --- lsp-mode.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lsp-mode.el b/lsp-mode.el index 1dad7b75a0..0ea51e9411 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -3716,6 +3716,7 @@ disappearing, unset all the variables related to it." :json-false)))))) ,@(when lsp-lens-enable '((codeLens . ((refreshSupport . t))))) ,@(when lsp-inlay-hint-enable '((inlayHint . ((refreshSupport . :json-false))))) + (diagnostics . ((refreshSupport . :json-false))) (fileOperations . ((didCreate . :json-false) (willCreate . :json-false) (didRename . t) @@ -6954,6 +6955,8 @@ server. WORKSPACE is the active workspace." (fboundp 'lsp--lens-on-refresh)) (lsp--lens-on-refresh workspace)) nil) + ((equal method "workspace/diagnostic/refresh") + nil) (t (lsp-warn "Unknown request method: %s" method) nil)))) ;; Send response to the server. (unless (eq response 'delay-response)