manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.42k stars 205 forks source link

Can't use copilot in temp buffer (such as fence-edit, or org-mode's src block editing) #844

Closed baohaojun closed 8 months ago

baohaojun commented 8 months ago

I believe it's because for these buffers, the copilot call has a nil (buffer-file-name):

(lsp-bridge-call-async "copilot_complete"
                             (lsp-bridge--position)
                             (symbol-name major-mode)
                             (buffer-file-name)
                             relative-path
                             tab-width
                             all-text
                             (not indent-tabs-mode))

I hade to work around this with the following advice:

(defun my/lsp-bridge-call-async-advice (orig-fun method &rest args)
  "Advice for `lsp-bridge-call-async' to modify args for `copilot_complete'."
  (when (and (string-equal method "copilot_complete")   ; Check if it's the desired method
             (or
              (null (nth 2 args))
              (string-equal "" (nth 2 args))))
    ;; Modify the fourth and fifth arguments
    (setf (nth 2 args) "/tmp/test.sh")
    (setf (nth 3 args) "test.sh"))
  ;; Call the original function with the possibly modified args
  (apply orig-fun method args))

(advice-add 'lsp-bridge-call-async :around #'my/lsp-bridge-call-async-advice)
manateelazycat commented 8 months ago

Please search org in lsp-bridge.el

lsp-bridge can provide code completion in org src block, I think this issue can fix.

But I don'g use org-mode, please research org in lsp-bridge.el, any patch are welcome. ;)

baohaojun commented 8 months ago

Thanks for the reply and the wonderful software.