Skip to content

Commit fe39577

Browse files
committed
Check whether a folder is under the root before importing
Fixes #79
1 parent f73d447 commit fe39577

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lsp-java-treemacs.el

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,17 @@ ADDED and REMOVED are pointing which are the changed folders."
215215
(-first (lambda (project) (f-equal? it (treemacs-project->path project))))
216216
treemacs-do-remove-project-from-workspace)))
217217

218-
(defun lsp-java-treemacs--is-root (dir-or-project)
219-
"Return whether DIR-OR-PROJECT is root of a project."
220-
(let ((dir (if (stringp dir-or-project)
221-
dir-or-project
222-
(treemacs-project->path dir-or-project))))
223-
(-some-> dir
224-
lsp-java--find-workspace
225-
lsp-java--get-project-uris
226-
(-contains? (lsp--path-to-uri dir)))))
227-
228218
(defun lsp-java-treemacs-register ()
229219
"Register `lsp-java' extension."
230220
(interactive)
231221
(treemacs-define-directory-extension
232222
:extension 'treemacs-EXTERNAL-LIBRARY-extension
233223
:position 'directory-start
234-
:predicate 'lsp-java-treemacs--is-root)
224+
:predicate 'lsp-java--is-root)
235225
(treemacs-define-project-extension
236226
:extension 'treemacs-EXTERNAL-LIBRARY-extension
237227
:position 'project-start
238-
:predicate 'lsp-java-treemacs--is-root)
228+
:predicate 'lsp-java--is-root)
239229

240230
(require 'treemacs)
241231
(unless (eq 'visible (treemacs-current-visibility))

lsp-java.el

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ FULL specify whether full or incremental build will be performed."
375375
,lsp-java-workspace-dir
376376
,@java-9-args)))
377377

378+
(defun lsp-java--is-root (dir-or-project)
379+
"Return whether DIR-OR-PROJECT is root of a project."
380+
(let ((dir (if (stringp dir-or-project)
381+
dir-or-project
382+
(treemacs-project->path dir-or-project))))
383+
(-some-> dir
384+
lsp-java--find-workspace
385+
lsp-java--get-project-uris
386+
(-contains? (lsp--path-to-uri dir)))))
387+
378388
(defun lsp-java--get-root ()
379389
"Retrieves the root directory of the java project root if available.
380390
@@ -417,10 +427,11 @@ ACTION is the action to execute."
417427
WORKSPACE is the currently active workspace.
418428
PARAMS the parameters for actionable notifications."
419429
(let* ((project-root (lsp-java--get-root))
420-
(classpath-incomplete-p (cl-find-if (lambda (command)
421-
(string= (gethash "command" command)
422-
"java.ignoreIncompleteClasspath.help"))
423-
(gethash "commands" params)))
430+
(classpath-incomplete-p (unless (lsp-java--is-root (lsp-java--get-root))
431+
(cl-find-if (lambda (command)
432+
(string= (gethash "command" command)
433+
"java.ignoreIncompleteClasspath.help"))
434+
(gethash "commands" params))))
424435
(choices (list (format "Import project \"%s.\"" project-root)
425436
"Import project by selecting root directory interactively."
426437
(format "Do not ask more for the current project(add \"%s\" to lsp-project-blacklist)" project-root)

0 commit comments

Comments
 (0)