From 0f94a72d0f5b92e9c0e3bf8e42c027e5f6775493 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh Date: Sun, 28 Jul 2024 17:59:42 +0200 Subject: [PATCH] Check that LSP detect absence of SonarLint --- lsp-sonarlint.el | 3 +++ test/lsp-sonarlint-integration-test.el | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lsp-sonarlint.el b/lsp-sonarlint.el index 5a0659e..a222b49 100644 --- a/lsp-sonarlint.el +++ b/lsp-sonarlint.el @@ -259,6 +259,9 @@ See `lsp-sonarlint-available-analyzers' and `lsp-sonarlint-enabled-analyzers'" (defun lsp-sonarlint-server-start-fun() "Start lsp-sonarlint in stdio mode." + ;; This will signal an error if `lsp-sonarlint-download-dir' is not a dir + ;; or if the java executable is not found there. + ;; Thus, it also serves as a check for the presence of SonarLint LSP server. (let* ((root-dir lsp-sonarlint-download-dir) (bundled-java-path (car (directory-files-recursively root-dir "java\\(.exe\\)?$"))) (java-path (if lsp-sonarlint-use-system-jre "java" bundled-java-path)) diff --git a/test/lsp-sonarlint-integration-test.el b/test/lsp-sonarlint-integration-test.el index b34992e..fe45c15 100644 --- a/test/lsp-sonarlint-integration-test.el +++ b/test/lsp-sonarlint-integration-test.el @@ -134,6 +134,31 @@ If nil, use python-mode by default." (lsp-sonarlint--get-codes-of-issues diags)) (if major-mode major-mode 'python-mode))) +(ert-deftest lsp-sonarlint-lsp-mode-detects-abscent-plugin () + "Check that LSP mode detects the absence of the SonarLint plugin." + (let ((lsp-sonarlint-download-dir (lsp-sonarlint--sample-file "")) + (lsp-sonarlint-use-system-jre t) + (filename (lsp-sonarlint--sample-file "sample.py")) + (exec-path (cons (lsp-sonarlint--sample-file "mock-java-bin/") + exec-path))) + (should (null (lsp-sonarlint--any-alive-workspaces-p))) + (let ((lsp-enabled-clients '(sonarlint)) + (lsp-keep-workspace-alive nil) + (dir (file-name-directory filename)) + (lsp-enable-snippet nil)) + (let ((buf (find-file-noselect filename))) + (unwind-protect + (progn + (lsp-workspace-folders-add dir) + (with-current-buffer buf + (python-mode) + (should (string-match-p + "do not have automatic installation: sonarlint" + (lsp))))) + (kill-buffer buf) + (lsp-workspace-folders-remove dir) + (lsp-sonarlint--wait-for-workspaces-to-die 10)))))) + (ert-deftest lsp-sonarlint-python-reports-issues () "Check that LSP can get Python SonarLint issues for a Python file." (should (equal (lsp-sonarlint--get-all-issue-codes "sample.py")