Skip to content

Commit

Permalink
Check that LSP detect absence of SonarLint
Browse files Browse the repository at this point in the history
  • Loading branch information
necto committed Jul 28, 2024
1 parent 587a74b commit 0f94a72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lsp-sonarlint.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 25 additions & 0 deletions test/lsp-sonarlint-integration-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0f94a72

Please sign in to comment.