-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathautoload.el
More file actions
104 lines (89 loc) · 3.85 KB
/
autoload.el
File metadata and controls
104 lines (89 loc) · 3.85 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;;; private/my-cc/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defvar +ccls-path-mappings [])
;;;###autoload
(defvar +ccls-initial-blacklist [])
;;;###autoload
(defvar +lsp-blacklist nil)
;;;###autoload
(defun +ccls|enable ()
(when (and buffer-file-name (--all? (not (string-match-p it buffer-file-name)) +lsp-blacklist))
(require 'ccls)
(require 'lsp-completion)
(require 'lsp-headerline)
(require 'lsp-modeline)
(setq-local lsp-ui-sideline-show-symbol nil)
(when (string-match-p "/llvm" buffer-file-name)
(setq-local lsp-enable-file-watchers nil))
(if +my-use-eglot (call-interactively #'eglot) (lsp))))
(defun ccls/callee ()
(interactive)
(lsp-ui-peek-find-custom "$ccls/call" '(:callee t)))
(defun ccls/caller ()
(interactive)
(lsp-ui-peek-find-custom "$ccls/call"))
(defun ccls/vars (kind)
(lsp-ui-peek-find-custom "$ccls/vars" `(:kind ,kind)))
(defun ccls/base (levels)
(lsp-ui-peek-find-custom "$ccls/inheritance" `(:levels ,levels)))
(defun ccls/derived (levels)
(lsp-ui-peek-find-custom "$ccls/inheritance" `(:levels ,levels :derived t)))
(defun ccls/member (kind)
(lsp-ui-peek-find-custom "$ccls/member" `(:kind ,kind)))
;; The meaning of :role corresponds to https://github.com/maskray/ccls/blob/master/src/symbol.h
;; References w/ Role::Address bit (e.g. variables explicitly being taken addresses)
(defun ccls/references-address ()
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 128)))
;; References w/ Role::Dynamic bit (macro expansions)
(defun ccls/references-macro ()
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 64)))
;; References w/o Role::Call bit (e.g. where functions are taken addresses)
(defun ccls/references-not-call ()
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :excludeRole 32)))
;; References w/ Role::Read
(defun ccls/references-read ()
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 8)))
;; References w/ Role::Write
(defun ccls/references-write ()
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 16)))
;; xref-find-apropos (workspace/symbol)
(defun my/highlight-pattern-in-text (pattern line)
(when (> (length pattern) 0)
(let ((i 0))
(while (string-match pattern line i)
(setq i (match-end 0))
(add-face-text-property (match-beginning 0) (match-end 0) 'isearch t line)
)
line)))
(with-eval-after-load 'lsp-methods
;;; Override
;; This deviated from the original in that it highlights pattern appeared in symbol
(defun lsp--symbol-information-to-xref (pattern symbol)
"Return a `xref-item' from SYMBOL information."
(let* ((location (gethash "location" symbol))
(uri (gethash "uri" location))
(range (gethash "range" location))
(start (gethash "start" range))
(name (gethash "name" symbol)))
(xref-make (format "[%s] %s"
(alist-get (gethash "kind" symbol) lsp--symbol-kind)
(my/highlight-pattern-in-text (regexp-quote pattern) name))
(xref-make-file-location (string-remove-prefix "file://" uri)
(1+ (gethash "line" start))
(gethash "character" start)))))
(cl-defmethod xref-backend-apropos ((_backend (eql xref-lsp)) pattern)
(let ((symbols (lsp--send-request (lsp--make-request
"workspace/symbol"
`(:query ,pattern)))))
(mapcar (lambda (x) (lsp--symbol-information-to-xref pattern x)) symbols)))
)