-
Notifications
You must be signed in to change notification settings - Fork 0
/
piglet-company.el
39 lines (31 loc) · 1.41 KB
/
piglet-company.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
;;; piglet-company.el --- Piglet Dev Protocol, interactive programming over websocket -*- lexical-binding: t -*-
;; Author: Arne Brasseur <[email protected]>
;; Filename: piglet-company.el
;; Package-Requires: ((company pdp))
;; Keywords: piglet languages completion
;;; Commentary:
;;; Code:
(require 'cl-lib)
(require 'pdp)
(defun piglet-company-backend (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'piglet-company-backend))
(prefix (let ((node (treesit-node-at (- (point) 1))))
(when (and (eq (point) (treesit-node-end node))
(equal "symbol" (treesit-node-type node)))
(treesit-node-text node))))
(candidates
`(:async . ,(lambda (callback)
(pdp-send
(pdp-add-handler
(pdp-msg `((:op . "completion-candidates")
(:prefix . ,arg)))
(lambda (reply)
(let ((cands (seq-into (pdp--msg-get reply :candidates)
'list)))
(funcall callback cands))))))))))
(add-hook 'piglet-mode-hook (lambda () (setq-local company-backends '(piglet-company-backend))))
(provide 'piglet-company)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; piglet-company.el ends here