-
Notifications
You must be signed in to change notification settings - Fork 3
/
rsense.el
55 lines (43 loc) · 1.65 KB
/
rsense.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
(require 'find-file-in-project)
(require 'auto-complete)
(require 'json)
(defconst rsense-version "0.0.2"
"The version of `rsense'.")
;; (defvar rsense-executable
;; (executable-find "rsense"))
(defvar rsense-endpoint-uri
"http://localhost:47367")
;;(setq rsense-endpoint-uri "http://localhost:47367")
;;(setq rsense-endpoint-uri "http://localhost:47368")
;;(setq rsense-endpoint-uri "http://localhost:4567")
;; (defun rsense-start-command ()
;; (concat rsense-executable " start --path " default-directory))
;; (defun rsense-start ()
;; (call-process-shell-command (rsense-start-command)))
(defun rsense/code-completion-request-body ()
(json-encode `((command . code_completion)
(project . ,(ffip-project-root))
(file . ,buffer-file-name)
(code . ,(buffer-string))
;;(code . "")
(location . ((row . ,(line-number-at-pos))
(column . ,(1+ (current-column))))))))
(defun rsense/completions ()
(let* ((response (rsense-http/post (rsense/code-completion-request-body)))
(status-hash (car response))
(body (cadr response))
(parsed (json-read-from-string body))
(completions (cdr (assoc 'completions parsed))))
;;(prin1 completions)
(mapcar (lambda (el) (cdr (assoc 'name el))) completions)))
(ac-define-source rsense
'((candidates . rsense/completions)
(prefix . "\\(?:\\.\\|::\\)\\(.*\\)")
;;(prefix . "\\.\\(.*\\)")
(requires . 0)
;;(document . ac-rsense-documentation)
(cache)))
(defun rsense/ac-complete ()
(interactive)
(setq ac-sources '(ac-source-rsense)))
(provide 'rsense)