Skip to content

Commit

Permalink
Merge pull request #372 from ptrv/json-array-type-list
Browse files Browse the repository at this point in the history
Use list as json-array-type
  • Loading branch information
abingham committed Oct 27, 2016
2 parents b7f26dc + ffb4323 commit 831e09a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
6 changes: 3 additions & 3 deletions company-ycmd.el
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ with spaces."
"Generic function to construct completion string from a CANDIDATE."
(company-ycmd--with-destructured-candidate candidate .insertion_text))

(defun company-ycmd--construct-candidates (completion-vector
(defun company-ycmd--construct-candidates (completions
prefix
start-col
construct-candidate-fn)
"Construct candidates list from COMPLETION-VECTOR.
"Construct candidates list from COMPLETIONS.
PREFIX is the prefix we calculated for doing the completion, and
START-COL is the column on which ycmd indicates we should place
Expand All @@ -407,7 +407,7 @@ candidates list."
(prefix-size (- start-col prefix-start-col))
(prefix-diff (substring-no-properties prefix 0 prefix-size))
candidates)
(dolist (candidate (append completion-vector nil) (nreverse candidates))
(dolist (candidate completions (nreverse candidates))
(when (s-present? prefix-diff)
(let ((it (assq 'insertion_text candidate)))
(setcdr it (concat prefix-diff
Expand Down
27 changes: 16 additions & 11 deletions test/ycmd-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ response."
:line 9 :column 10
(let ((response (ycmd-get-completions :sync)))
(let-alist response
(let ((c (nth 0 (append .completions nil))))
(let ((c (nth 0 .completions)))
(should (string= "Logger" (cdr (assq 'insertion_text c))))
(should (= .completion_start_column 6))))))

Expand All @@ -219,19 +219,19 @@ response."
.completions)))))

(ert-deftest ycmd-test-fixit-same-location-false ()
(let ((data '(((chunks . [((replacement_text . "foo"))])
(let ((data '(((chunks . (((replacement_text . "foo"))))
(location (filepath . "test.cpp")
(column_num . 1) (line_num . 2)))
((chunks . [((replacement_text . "bar"))])
((chunks . (((replacement_text . "bar"))))
(location (filepath . "test.cpp")
(column_num . 3) (line_num . 4))))))
(should-not (ycmd--fixits-have-same-location-p data))))

(ert-deftest ycmd-test-fixit-same-location-true ()
(let ((data '(((chunks . [((replacement_text . "foo"))])
(let ((data '(((chunks . (((replacement_text . "foo"))))
(location (filepath . "test.cpp")
(column_num . 1) (line_num . 2)))
((chunks . [((replacement_text . "bar"))])
((chunks . (((replacement_text . "bar"))))
(location (filepath . "test.cpp")
(column_num . 1) (line_num . 2))))))
(should (ycmd--fixits-have-same-location-p data))))
Expand Down Expand Up @@ -321,7 +321,7 @@ response."

(ert-deftest ycmd-test-refactor-rename-simple ()
(let* ((file-path (f-join ycmd-test-resources-location "simple_test.js"))
(data `((fixits . [((chunks . [((range
(data `((fixits . (((chunks . (((range
(start (filepath . ,file-path) (column_num . 5) (line_num . 1))
(end (filepath . ,file-path) (column_num . 22) (line_num . 1)))
(replacement_text . "test"))
Expand All @@ -344,17 +344,17 @@ response."
((range
(start (filepath . ,file-path) (column_num . 28) (line_num . 21))
(end (filepath . ,file-path) (column_num . 45) (line_num . 21)))
(replacement_text . "test"))])
(replacement_text . "test"))))
(text . "")
(location (filepath . ,file-path) (column_num . 34) (line_num . 15)))]))))
(location (filepath . ,file-path) (column_num . 34) (line_num . 15))))))))
(should (ycmd-test-refactor-rename-handler
data '(("simple_test.js" . "simple_test-expected.js"))))))

(ert-deftest ycmd-test-refactor-rename-multiple-files ()
(let* ((file-path-1 (f-join ycmd-test-resources-location "file1.js"))
(file-path-2 (f-join ycmd-test-resources-location "file2.js"))
(file-path-3 (f-join ycmd-test-resources-location "file3.js"))
(data `((fixits . [((chunks . [((range
(data `((fixits . (((chunks . (((range
(start (filepath . ,file-path-1) (column_num . 5) (line_num . 1))
(end (filepath . ,file-path-1) (column_num . 11) (line_num . 1)))
(replacement_text . "test"))
Expand All @@ -369,9 +369,9 @@ response."
((range
(start (filepath . ,file-path-3) (column_num . 12) (line_num . 3))
(end (filepath . ,file-path-3) (column_num . 18) (line_num . 3)))
(replacement_text . "test"))])
(replacement_text . "test"))))
(text . "")
(location (filepath . ,file-path-1) (column_num . 5) (line_num . 1)))]))))
(location (filepath . ,file-path-1) (column_num . 5) (line_num . 1))))))))
(should (ycmd-test-refactor-rename-handler
data '(("file1.js" . "file1-expected.js")
("file2.js" . "file2-expected.js")
Expand Down Expand Up @@ -749,6 +749,11 @@ response."
(should (string= (ycmd--json-encode data)
"{\"foo\":{}}"))))

(ert-deftest ycmd-test-location-data-predicate ()
(let ((data '((filepath . ,file-path) (column_num . 34) (line_num . 15))))
(should (ycmd--location-data? data))
(should-not (ycmd--location-data? (list data)))))

(defun flycheck-ycmd-test-mode ()
(flycheck-ycmd-setup)
(ycmd-test-mode))
Expand Down
3 changes: 1 addition & 2 deletions ycmd-eldoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ foo(bar, |baz); -> foo|(bar, baz);"
(not (-contains?
'("[ID]" "[File]" "[Dir]" "[File&Dir]")
.extra_menu_info))))))
;; Convert vector to list
(append result nil)))
result))
(item (car filtered-list))
(msg (or (cdr (assq 'detailed_info item))
(cdr (assq 'extra_menu_info item)))))
Expand Down
36 changes: 20 additions & 16 deletions ycmd.el
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ it might be interesting for some users."
(put-text-property
0 1 'anno (substring anno (match-end 0)) text))
text)
(append candidates nil))))
candidates)))

(defun ycmd-complete-at-point ()
"Complete symbol at point."
Expand Down Expand Up @@ -1074,7 +1074,7 @@ This function handles `UnknownExtraConf', `ValueError' and

(defun ycmd--exception? (response)
"Check whether RESPONSE is an exception."
(and (not (vectorp response)) (assq 'exception response)))
(assq 'exception response))

(defun ycmd--send-request (subcommand success-handler)
"Send SUBCOMMAND to the `ycmd' server.
Expand Down Expand Up @@ -1154,16 +1154,18 @@ Useful in case compile-time is considerable."
(with-no-warnings
(ring-insert find-tag-marker-ring (point-marker)))))

(defun ycmd--location-data? (response)
"Return t if RESPONSE is a GoTo location."
(and (assq 'filepath response)
(assq 'line_num response)
(assq 'column_num response)))

(defun ycmd--handle-goto-success (response)
"Handle a successfull GoTo RESPONSE."
(let* ((is-vector (vectorp response))
(num-items (if is-vector (length response) 1)))
(ycmd--save-marker)
(when is-vector
(setq response (append response nil)))
(if (eq 1 num-items)
(ycmd--goto-location response 'find-file)
(ycmd--view response major-mode))))
(ycmd--save-marker)
(if (ycmd--location-data? response)
(ycmd--goto-location response 'find-file)
(ycmd--view response major-mode)))

(defun ycmd--goto (type)
"Implementation of GoTo according to the request TYPE."
Expand Down Expand Up @@ -1303,7 +1305,7 @@ If optional ARG is non-nil, get type without reparsing buffer."
(defun ycmd--apply-fixit (button)
"Apply BUTTON's FixIt chunk."
(-when-let* ((chunk (button-get button 'fixit)))
(ycmd--replace-chunk-list (append chunk nil))
(ycmd--replace-chunk-list chunk)
(quit-window t (get-buffer-window "*ycmd-fixits*"))))

(define-derived-mode ycmd-fixit-mode ycmd-view-mode "ycmd-fixits"
Expand Down Expand Up @@ -1400,13 +1402,12 @@ buffer."

(defun ycmd--handle-fixit-success (response)
"Handle a successful FixIt RESPONSE."
(-if-let* ((fixits (cdr (assq 'fixits response)))
(fixits (append fixits nil)))
(-if-let (fixits (cdr (assq 'fixits response)))
(if (and (not ycmd-confirm-fixit)
(not (ycmd--fixits-have-same-location-p fixits)))
(dolist (fixit fixits)
(--when-let (cdr (assq 'chunks fixit))
(ycmd--replace-chunk-list (append it nil))))
(ycmd--replace-chunk-list it)))
(save-current-buffer
(ycmd--show-fixits fixits)))
(message "No FixIts available")))
Expand All @@ -1425,7 +1426,7 @@ If NO-CONFIRM is non-nil, don't ask the user to confirm the rename."
(-when-let (chunks (cdr (assq 'chunks fixit)))
(let ((chunks-by-filepath
(--group-by (let-alist it .range.start.filepath)
(append chunks nil))))
chunks)))
(when (or no-confirm
(y-or-n-p (format "Apply %d renames in %d files? "
(length chunks)
Expand Down Expand Up @@ -2089,8 +2090,11 @@ anything like that.)
(let ((data (request-response-data response)))
(ycmd--log-content "HTTP RESPONSE CONTENT" data)
data)))
(parser (lambda ()
(let ((json-array-type 'list))
(json-read))))
(request-args (list :type type :params params :data content
:parser 'json-read :headers headers
:parser parser :headers headers
:timeout timeout)))
(ycmd--log-content "HTTP REQUEST CONTENT" content)

Expand Down

0 comments on commit 831e09a

Please sign in to comment.