Browse Source

Update opengrok-restful.el

opengrok server a readonly xref
pull/4/head
Ritesh Agarwal 7 months ago
committed by GitHub
parent
commit
7128f341ef
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 68
      opengrok-restful.el

68
opengrok-restful.el

@ -54,18 +54,39 @@
(defun opengrok-restful-current-line () (defun opengrok-restful-current-line ()
(buffer-substring-no-properties (line-beginning-position) (line-end-position))) (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
(defun opengrok-restful-get-file-content (path)
(let ((content nil)
(download-url (format "%s/raw%s"
(s-replace "/api/v1/search" "" opengrok-restful-url)
path)))
(request download-url
:type "GET"
:headers (list (cons "Authorization" (format "Bearer %s" opengrok-restful-token)))
:parser 'buffer-string
:sync t
:complete (cl-function (lambda (&key data &allow-other-keys)
(setq content data))))
content))
(defun opengrok-restful-jump-to-target (line-content) (defun opengrok-restful-jump-to-target (line-content)
(cl-multiple-value-bind (path linum) (cl-multiple-value-bind (path linum)
(save-match-data (save-match-data
(string-match "/.+:[0-9]+" line-content) (string-match "/.+:[0-9]+" line-content)
(split-string (match-string 0 line-content) ":")) (split-string (match-string 0 line-content) ":"))
(find-file (concat (let ((content (opengrok-restful-get-file-content path)))
(file-name-as-directory opengrok-restful-source-directory) (when content
(let* ((full-path (concat (file-name-as-directory opengrok-restful-source-directory)
(substring path 1))) (substring path 1)))
(buffer (generate-new-buffer (file-name-nondirectory full-path))))
(switch-to-buffer-other-window buffer)
(with-current-buffer buffer
(erase-buffer)
(insert content)
(setq buffer-file-name full-path)
(set-auto-mode)
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- (string-to-number linum))) (forward-line (1- (string-to-number linum))))
(kill-buffer opengrok-restful-buffer) )))))
))
(setq opengrok-restful-keymap (setq opengrok-restful-keymap
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
@ -79,11 +100,19 @@
(kill-buffer (current-buffer)))) (kill-buffer (current-buffer))))
map)) map))
(defun opengrok-restful-parse-response (data) (defun opengrok-restful-parse-response (data project value)
(with-current-buffer (get-buffer-create opengrok-restful-buffer) (with-current-buffer (get-buffer-create opengrok-restful-buffer)
(setq buffer-read-only nil) (setq buffer-read-only nil)
(erase-buffer) (goto-char (point-max))
(if (> (point) (point-min))
(insert "\n\n"))
(let ((start-of-new-results (point)))
(insert "--- New Search Results ---\n")
(insert (format "Project: %s\n" (or project "all")))
(insert (format "Search: %s\n\n" value))
(opengrok-restful-mode) (opengrok-restful-mode)
(mapcar (lambda (file) (mapcar (lambda (file)
(let ((file-name (symbol-name (car file))) (let ((file-name (symbol-name (car file)))
(file-lines (cdr file))) (file-lines (cdr file)))
@ -100,10 +129,12 @@
(when (< 0 (buffer-size)) (when (< 0 (buffer-size))
(progn (progn
(switch-to-buffer-other-window opengrok-restful-buffer) (switch-to-buffer-other-window opengrok-restful-buffer)
(goto-char (point-min)))) (goto-char start-of-new-results))))))
))
(defun opengrok-restful-project-lookup (request-params) (defun opengrok-restful-project-lookup (request-params)
(let* ((project (cdr (assoc "projects" request-params)))
(search-pair (car (remove (assoc "projects" request-params) request-params)))
(value (cdr search-pair)))
(request opengrok-restful-url (request opengrok-restful-url
:type "GET" :type "GET"
:params request-params :params request-params
@ -111,13 +142,23 @@
:parser 'json-read :parser 'json-read
:sync t :sync t
:complete (cl-function (lambda (&key data &allow-other-keys) :complete (cl-function (lambda (&key data &allow-other-keys)
(opengrok-restful-parse-response data))))) (opengrok-restful-parse-response data project value))))))
(defvar opengrok-restful-current-project nil
"The current project name to use for OpenGrok searches.")
(defun opengrok-restful-set-current-project (project-name)
"Set the current OpenGrok project name."
(interactive "sProject name: ")
(setq opengrok-restful-current-project project-name)
(message "OpenGrok project set to: %s" project-name))
(defun opengrok-restful-current-project-name () (defun opengrok-restful-current-project-name ()
(file-name-nondirectory (directory-file-name (projectile-project-root)))) "Return the current OpenGrok project name."
opengrok-restful-current-project)
(defun opengrok-restful-make-params (project type value) (defun opengrok-restful-make-params (project type value)
(let ((params `((,type ,value)))) (let ((params `((,type . ,value))))
(if (not (string= "" project)) (if (not (string= "" project))
(cons `("projects" . ,(if (string= "c" project) (cons `("projects" . ,(if (string= "c" project)
(opengrok-restful-current-project-name) (opengrok-restful-current-project-name)
@ -135,8 +176,7 @@
(opengrok-restful-make-params (opengrok-restful-make-params
(read-string "Project> ") (read-string "Project> ")
,(symbol-name type) ,(symbol-name type)
(read-string (format "Symbol (%s)> " default-symbol) nil nil default-symbol))) (read-string (format "Symbol (%s)> " default-symbol) nil nil default-symbol)))))))
))))
(opengrok-restful-define-lookup full) (opengrok-restful-define-lookup full)
(opengrok-restful-define-lookup def) (opengrok-restful-define-lookup def)

Loading…
Cancel
Save