Commit 7f0ad5d8 authored by Fangrui Song's avatar Fangrui Song

Simplify get-root

parent 1906dab7
......@@ -92,7 +92,6 @@
(defun ccls-call-hierarchy--request-init (callee)
"."
(ccls--ccls-buffer-check)
(lsp--send-request
(lsp--make-request "$ccls/call"
`(:textDocument (:uri ,(concat lsp--uri-file-prefix buffer-file-name))
......@@ -121,7 +120,6 @@
(defun ccls-call-hierarchy (callee)
(interactive "P")
(ccls--ccls-buffer-check)
(setq callee (if callee t :json-false))
(ccls-tree--open
(make-ccls-tree-client
......
......@@ -149,7 +149,7 @@
:lighter "Lens"
(cond
(ccls-code-lens-mode
(when (ccls--is-ccls-buffer)
(when lsp--cur-workspace
(ccls-request-code-lens)
(add-hook 'lsp-after-diagnostics-hook 'ccls-code-lens--request-when-idle t t)))
(t
......
......@@ -46,31 +46,10 @@
(cons (lsp--position-to-point (gethash "start" range))
(lsp--position-to-point (gethash "end" range))))
(defsubst ccls--root-from-file (file)
(-when-let (match (locate-dominating-file default-directory file))
(expand-file-name match)))
(defsubst ccls--root-from-func (func)
(and (fboundp func) (ignore-errors (funcall func))))
(cl-defun ccls--get-root ()
"Return the root directory of a ccls project."
(cl-loop for matcher in ccls-project-root-matchers do
(-when-let (root (cl-typecase matcher
(string (ccls--root-from-file matcher))
(function (ccls--root-from-func matcher))))
(cl-return-from ccls--get-root root)))
(user-error "Could not find ccls project root"))
(defun ccls--is-ccls-buffer (&optional buffer)
"Return non-nil if current buffer is using the ccls client"
(with-current-buffer (or buffer (current-buffer))
(and lsp--cur-workspace
(eq (lsp--client-get-root (lsp--workspace-client lsp--cur-workspace)) 'ccls--get-root))))
(define-inline ccls--ccls-buffer-check ()
(inline-quote (cl-assert (ccls--is-ccls-buffer) nil
"ccls is not enabled in this buffer.")))
(-when-let (match (locate-dominating-file default-directory ".ccls-root"))
(expand-file-name match)))
(defun ccls--get-renderer ()
(thread-last lsp--cur-workspace
......@@ -98,27 +77,5 @@
and handler is a function invoked as (handler WORKSPACE PARAMS), where WORKSPACE is the current
lsp-workspace, and PARAMS is a hashmap of the params recieved with the notification.")
;; ---------------------------------------------------------------------
;; Commands
;; ---------------------------------------------------------------------
(defun ccls--execute-command (command arguments)
"Execute a ccls command."
(pcase command
;; Code actions
('"ccls.xref" ;; Used by code lenses
(xref--show-xrefs (lsp--locations-to-xref-items
(lsp--send-request (lsp--make-request "workspace/executeCommand") command arguments)) nil))
(_
(message "unknown command: %s" command))))
(defun ccls--apply-textedit (edit)
(let* ((range (gethash "range" edit))
(start (lsp--position-to-point (gethash "start" range)))
(end (lsp--position-to-point (gethash "end" range)))
(newText (gethash "newText" edit)))
(delete-region start end)
(goto-char start)
(insert newText)))
(provide 'ccls-common)
......@@ -80,7 +80,6 @@
(defun ccls-inheritance-hierarchy--request-init (derived)
"."
(ccls--ccls-buffer-check)
(lsp--send-request
(lsp--make-request "$ccls/inheritance"
`(
......@@ -103,7 +102,6 @@
(defun ccls-inheritance-hierarchy (derived)
(interactive "P")
(ccls--ccls-buffer-check)
(let ((json-derived (if derived t :json-false)))
(ccls-tree--open
(make-ccls-tree-client
......
......@@ -77,7 +77,6 @@
(defun ccls-member-hierarchy--request-init ()
"."
(ccls--ccls-buffer-check)
(lsp--send-request
(lsp--make-request "$ccls/member"
`(
......@@ -97,7 +96,6 @@
(defun ccls-member-hierarchy ()
(interactive)
(ccls--ccls-buffer-check)
(ccls-tree--open
(make-ccls-tree-client
:name "member hierarchy"
......
......@@ -63,8 +63,6 @@
:type '(repeat string)
:group 'ccls)
(defalias 'ccls-additional-arguments 'ccls-extra-args)
(defcustom ccls-cache-dir
".ccls-cache/"
"Directory in which ccls will store its index cache.
......@@ -78,23 +76,6 @@ Relative to the project root directory."
:type '(repeat string)
:group 'ccls)
(defcustom ccls-project-root-matchers
'(".ccls-root" projectile-project-root)
"List of matchers that are used to locate the ccls project roots.
Each matcher is run in order, and the first successful (non-nil) matcher
determines the project root.
A `string' entry defines a dominating file that exists in either the
current working directory or a parent directory. ccls will traverse
upwards through the project directory structure and return the first
matching file.
A `function' entry define a callable function that either returns workspace's
root location or `nil' if subsequent matchers should be used instead.
"
:type '(repeat (choice (file) (function)))
:group 'ccls)
;; ---------------------------------------------------------------------
;; Other ccls-specific methods
;; ---------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment