Commit a458d45e authored by Fangrui Song's avatar Fangrui Song

Add cquery-preprocess-file

parent 3e1cc7bf
......@@ -43,6 +43,9 @@
(require 'cquery-inheritance-hierarchy)
(require 'cquery-member-hierarchy)
(require 'ht)
(require 'seq)
;; ---------------------------------------------------------------------
;; Customization
;; ---------------------------------------------------------------------
......@@ -120,6 +123,36 @@ root location or `nil' if another matcher should be used instead.
(lsp--make-request "$cquery/fileInfo"
`(:textDocument ,(lsp--text-document-identifier)))))
(defun cquery-preprocess-file (&optional output-buffer)
"Preprocess selected buffer."
(-when-let* ((mode major-mode)
(info (cquery-file-info))
(args (seq-into (ht-get info "args") 'vector))
(new-args (let ((i 0) ret)
(while (< i (length args))
(let ((arg (elt args i)))
((string= arg "-o") (cl-incf i))
((string-match-p "\\`-o.+" arg))
(t (push arg ret))))
(cl-incf i))
(nreverse ret))))
(with-current-buffer (or output-buffer
(format "*lsp-cquery preprocess %s*" (buffer-name))))
(pop-to-buffer (current-buffer))
(insert (format "// Generated by: %s"
(combine-and-quote-strings new-args)))
(insert (with-output-to-string
(with-current-buffer standard-output
(apply #'process-file (car new-args) nil t nil "-E" (cdr new-args)))))
(delay-mode-hooks (funcall mode))
(setq buffer-read-only t)))))
(defun cquery-freshen-index (&optional whitelist blacklist)
"Rebuild indexes for matched files.
`whitelist' and `blacklist' are ECMAScript regex used by std::regex_match
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