@@ -180,13 +180,19 @@ be re-analysed during textDocument/didOpen handler.")))
180
180
(cl-defun elsa-lsp--list-completion-items (list &key transform kind )
181
181
(setq transform (or transform #'identity ))
182
182
(apply #'vector
183
- (mapcar (lambda (item )
184
- (lsp-make-completion-item
185
- :label (funcall transform item)
186
- :kind (or kind lsp/completion-item-kind-text)))
187
- list )))
188
-
189
- (defun elsa-lsp--completions ()
183
+ (mapcar
184
+ (lambda (item )
185
+ (let ((completion (funcall transform item)))
186
+ (lsp-make-completion-item
187
+ :label (if (listp completion)
188
+ (plist-get completion :label )
189
+ completion)
190
+ :kind (if (listp completion)
191
+ (plist-get completion :kind )
192
+ (or kind lsp/completion-item-kind-text)))))
193
+ list )))
194
+
195
+ (defun elsa-lsp--function-completions ()
190
196
; ; only used to extract start and end... we can reimplement it later
191
197
(-when-let ((beg end) (elsa-lsp--completions-bounds))
192
198
(message " bounds %s %s " beg end)
@@ -199,10 +205,10 @@ be re-analysed during textDocument/didOpen handler.")))
199
205
(maphash
200
206
(lambda (k v )
201
207
(when (string-prefix-p prefix (symbol-name k))
202
- (push k candidates)))
208
+ (push v candidates)))
203
209
(oref elsa-global-state defuns))
204
210
(message " has %d functions for prefix %s " (length candidates) prefix)))
205
- ( mapcar # 'symbol-name candidates) )))
211
+ candidates)))
206
212
207
213
(defun elsa-lsp--capf-completions ()
208
214
" Fallback completions engine is the `elisp-completion-at-point' ."
@@ -236,7 +242,7 @@ be re-analysed during textDocument/didOpen handler.")))
236
242
:line (1- (oref form end-line))
237
243
:character (oref form end-column))))
238
244
239
- (defun elsa-lsp--analyze-textDocument/hover (form state method params )
245
+ (defun elsa-lsp--analyze-textDocument/hover (form _state _method params )
240
246
(-let* (((&HoverParams :position (&Position :line :character ))
241
247
params))
242
248
(when (and (= (oref form line) (1+ line))
@@ -275,9 +281,11 @@ be re-analysed during textDocument/didOpen handler.")))
275
281
(lsp--make-response id value)))))))
276
282
277
283
(defun elsa-lsp--analyze-textDocument/completion (form state method params )
278
- (-let* ((lgr (lgr-get-logger " elsa.lsp.analyzer" ))
279
- ((&CompletionParams :position (&Position :line :character ))
280
- params))
284
+ (-let ((lgr (lgr-get-logger " elsa.lsp.analyzer" ))
285
+ (scope (oref state scope))
286
+ ((&CompletionParams :position (&Position :line :character ))
287
+ params))
288
+ (lgr-debug lgr " form before %s" (elsa-tostring form))
281
289
(when (and (= (oref form line) (1+ line))
282
290
(<= (oref form column) character)
283
291
(or (< (1+ line) (oref form end-line))
@@ -290,25 +298,24 @@ be re-analysed during textDocument/didOpen handler.")))
290
298
(elsa-form-function-call-p (oref form parent))
291
299
(oref form parent)))))
292
300
; ; special completion inside a function call form
293
- (lgr-debug lgr " call-formadsadasdasdadx %s" (elsa-tostring call-form))
301
+ (lgr-debug lgr " call-form %s" (elsa-tostring call-form))
294
302
(cond
295
- ((eq (elsa-get-name call-form) 'oref )
296
- (lgr-debug lgr " call-form is oref" )
297
- (let* ((inst-form (elsa-cadr call-form))
298
- (inst-type (elsa-get-type inst-form)))
299
- (lgr-debug lgr " instance type is %s" (elsa-tostring inst-type))
303
+ ; ; complete the slot for oref or oset
304
+ ((memq (elsa-get-name call-form) '(oref oset))
305
+ (when-let* ((inst-form (elsa-cadr call-form))
306
+ (inst-type (elsa-get-type inst-form)))
300
307
(when (elsa-class-type-p inst-type)
301
- (lgr-debug lgr " is class type of name %s" (oref inst-type name))
302
308
(when-let* ((class (elsa-state-get-defclass state (oref inst-type name))))
303
- (lgr-debug lgr " has class" )
304
- (let ((slots (--map
305
- (oref it name)
306
- (elsa-get-slots class))))
309
+ (let ((slots (elsa-get-slots class)))
307
310
(throw 'lsp-response
308
311
(lsp-make-completion-list
309
312
:is-incomplete json-false
310
313
:items (elsa-lsp--list-completion-items
311
- slots :transform #'symbol-name ))))))))))
314
+ slots
315
+ :transform (lambda (x ) (symbol-name (elsa-get-name x)))
316
+ :kind lsp/completion-item-kind-field))))))))
317
+
318
+ ))
312
319
313
320
; ; Here we complete the function name if the point is at the
314
321
; ; first position in a list
@@ -318,11 +325,19 @@ be re-analysed during textDocument/didOpen handler.")))
318
325
(lgr-debug lgr " completing function name %s" (elsa-tostring form))
319
326
(save-excursion
320
327
(goto-char (1- (oref form end)))
321
- (when-let ((candidates (elsa-lsp--completions)))
328
+ (when-let ((candidates (elsa-lsp--function- completions)))
322
329
(throw 'lsp-response
323
330
(lsp-make-completion-list
324
331
:is-incomplete json-false
325
- :items (elsa-lsp--list-completion-items candidates))))))
332
+ :items (elsa-lsp--list-completion-items
333
+ candidates
334
+ :transform
335
+ (lambda (def )
336
+ (list :label (symbol-name (oref def name))
337
+ :kind (if (memq (oref def defun-type)
338
+ '(cl-defmethod cl-defgeneric))
339
+ lsp/completion-item-kind-method
340
+ lsp/completion-item-kind-function)))))))))
326
341
327
342
; ; regular symbol, we should use defvars and scope
328
343
; ; variables
0 commit comments