Skip to content

Commit 9adbcf5

Browse files
committed
project.el support for codeql projects to make eglot happier
1 parent 9af1616 commit 9adbcf5

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

emacs-codeql.el

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,28 @@ Leave nil for default.")
310310
"Return any currently configured codeql cli search paths."
311311
(mapconcat #'identity codeql--search-paths-buffer-local ":"))
312312

313-
(defun codeql--find-project-root ()
314-
(cl-assert (eq major-mode 'ql-tree-sitter-mode))
313+
;; project.el integration for eglot
314+
315+
(defun codeql--find-project-root (path)
315316
(let ((root
316-
(or (locate-dominating-file (buffer-file-name) "qlpack.yml")
317-
(locate-dominating-file (buffer-file-name) "codeql-pack.yml"))))
317+
(or (locate-dominating-file path "qlpack.yml")
318+
(locate-dominating-file path "codeql-pack.yml"))))
318319
(when root (message "Found project root: %s" root)
319320
root)))
320321

322+
(defun project-codeql (dir)
323+
(let ((root (codeql--find-project-root dir)))
324+
(when root
325+
(list 'codeql root))))
326+
327+
(cl-defmethod project-root ((project (head codeql)))
328+
(nth 1 project))
329+
330+
(cl-defmethod project-external-roots ((project (head codeql)))
331+
codeql--search-paths-buffer-local)
332+
333+
(add-to-list 'project-find-functions #'project-codeql)
334+
321335
;; Eglot configuration
322336

323337
(when codeql-configure-eglot-lsp
@@ -401,7 +415,7 @@ Leave nil for default.")
401415

402416
;; this is the root of a new codeql project that we opened ourselves
403417
(setq default-directory
404-
(or (codeql--find-project-root)
418+
(or (codeql--find-project-root (buffer-file-name))
405419
;; if we can't find a project root, assume cwd is project root
406420
(file-name-directory (buffer-file-name))))
407421

@@ -435,6 +449,7 @@ Leave nil for default.")
435449
codeql--search-paths-buffer-local))))
436450

437451
;; now that we have all our search paths, let's try and start up our LSP server
452+
;; this will rely on our project.el integration to determine the workspace paths
438453
(condition-case nil
439454
(when (and codeql-configure-eglot-lsp
440455
(or (and (file-remote-p (buffer-file-name))

0 commit comments

Comments
 (0)