This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolargraph.el
57 lines (47 loc) · 1.53 KB
/
solargraph.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;; package ---- solargraph
;;; Commentary:
;;;
;;; Code:
(require 'request)
(defvar solargraph:port 7657)
(defvar solargraph:active-callback nil)
(defvar solargraph:complete-callback-function 'solargraph:complete-callback)
(defun solargraph:complete-callback (collection)
"Solargraph complette callback (COLLECTION)."
(let* ((bounds (bounds-of-thing-at-point 'symbol))
(start (or (car bounds) (point)))
(stop (or (cdr bounds) (point))))
(completion-in-region start stop collection)
))
(defun solargraph:complete-request (callback)
"Get completions (CALLBACK)."
(let ((text (buffer-substring (point-min) (point-max)))
(filename buffer-file-name)
(line (- (count-lines 1 (point)) 1))
(column (current-column))
(callback callback)
)
(setq solargraph:active-callback callback)
(request
(format "http://localhost:%s/suggest" solargraph:port)
:type "POST"
:data `(
("text" . ,text)
("filename" . ,filename)
("line" . ,line)
("column" . ,column)
("workspace" . "solargraph")
)
:parser 'json-read
:success (cl-function
(lambda (&key data &allow-other-keys)
(let* ((sugg-data (assoc-default 'suggestions data))
(cmpls (mapcar (lambda (x) (cdr (elt x 2))) sugg-data))) ;
(funcall solargraph:active-callback cmpls)
))))))
(defun solargraph:complete ()
"Show completions."
(interactive)
(solargraph:complete-request solargraph:complete-callback-function))
(provide 'solargraph)
;;; solargraph.el ends here