Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 63 additions & 62 deletions copilot.el
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ indentation offset."

(defconst copilot--server-executable
(if (eq system-type 'windows-nt)
(f-join copilot-install-dir "node_modules" "copilot-node-server" "copilot" "dist" "agent.js")
(f-join copilot-install-dir "node_modules" "copilot-node-server" "copilot"
"bin" "copilot-node-server")
(f-join copilot-install-dir "bin" "copilot-node-server"))
"The dist directory containing agent.js file.")

Expand Down Expand Up @@ -245,27 +246,27 @@ Please upgrade the server via `M-x copilot-reinstall-server`"))
"Login to Copilot."
(interactive)
(copilot--dbind
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest are indentation errors.

(:status :user :userCode user-code :verificationUri verification-uri)
(copilot--request 'signInInitiate '(:dummy "signInInitiate"))
(when (s-equals-p status "AlreadySignedIn")
(user-error "Already signed in as %s" user))
(if (display-graphic-p)
(progn
(gui-set-selection 'CLIPBOARD user-code)
(read-from-minibuffer (format "Your one-time code %s is copied. Press \
(:status :user :userCode user-code :verificationUri verification-uri)
(copilot--request 'signInInitiate '(:dummy "signInInitiate"))
(when (s-equals-p status "AlreadySignedIn")
(user-error "Already signed in as %s" user))
(if (display-graphic-p)
(progn
(gui-set-selection 'CLIPBOARD user-code)
(read-from-minibuffer (format "Your one-time code %s is copied. Press \
ENTER to open GitHub in your browser. If your browser does not open \
automatically, browse to %s." user-code verification-uri))
(browse-url verification-uri)
(read-from-minibuffer "Press ENTER if you finish authorizing."))
(read-from-minibuffer (format "First copy your one-time code: %s. Press ENTER to continue." user-code))
(read-from-minibuffer (format "Please open %s in your browser. Press ENTER if you finish authorizing." verification-uri)))
(message "Verifying...")
(condition-case err
(copilot--request 'signInConfirm (list :userCode user-code))
(jsonrpc-error
(user-error "Authentication failure: %s" (alist-get 'jsonrpc-error-message (cddr err)))))
(copilot--dbind (:user) (copilot--request 'checkStatus '(:dummy "checkStatus"))
(message "Authenticated as GitHub user %s." user))))
(browse-url verification-uri)
(read-from-minibuffer "Press ENTER if you finish authorizing."))
(read-from-minibuffer (format "First copy your one-time code: %s. Press ENTER to continue." user-code))
(read-from-minibuffer (format "Please open %s in your browser. Press ENTER if you finish authorizing." verification-uri)))
(message "Verifying...")
(condition-case err
(copilot--request 'signInConfirm (list :userCode user-code))
(jsonrpc-error
(user-error "Authentication failure: %s" (alist-get 'jsonrpc-error-message (cddr err)))))
(copilot--dbind (:user) (copilot--request 'checkStatus '(:dummy "checkStatus"))
(message "Authenticated as GitHub user %s." user))))

(defun copilot-logout ()
"Logout from Copilot."
Expand Down Expand Up @@ -489,20 +490,20 @@ automatically, browse to %s." user-code verification-uri))
"Handle MSG of type METHOD."
(when (eql method 'PanelSolution)
(copilot--dbind (:completionText completion-text :score completion-score) msg
(with-current-buffer "*copilot-panel*"
(unless (member (secure-hash 'sha256 completion-text)
(org-map-entries (lambda () (org-entry-get nil "SHA"))))
(save-excursion
(goto-char (point-max))
(insert "* Solution\n"
" :PROPERTIES:\n"
" :SCORE: " (number-to-string completion-score) "\n"
" :SHA: " (secure-hash 'sha256 completion-text) "\n"
" :END:\n"
"#+BEGIN_SRC " copilot--panel-lang "\n"
completion-text "\n#+END_SRC\n\n")
(mark-whole-buffer)
(org-sort-entries nil ?R nil nil "SCORE"))))))
(with-current-buffer "*copilot-panel*"
(unless (member (secure-hash 'sha256 completion-text)
(org-map-entries (lambda () (org-entry-get nil "SHA"))))
(save-excursion
(goto-char (point-max))
(insert "* Solution\n"
" :PROPERTIES:\n"
" :SCORE: " (number-to-string completion-score) "\n"
" :SHA: " (secure-hash 'sha256 completion-text) "\n"
" :END:\n"
"#+BEGIN_SRC " copilot--panel-lang "\n"
completion-text "\n#+END_SRC\n\n")
(mark-whole-buffer)
(org-sort-entries nil ?R nil nil "SCORE"))))))
(when (eql method 'PanelSolutionsDone)
(message "Copilot: Finish synthesizing solutions.")
(display-buffer "*copilot-panel*")
Expand Down Expand Up @@ -677,34 +678,34 @@ Use TRANSFORM-FN to transform completion if provided."
"Show COMPLETION-DATA."
(when (copilot--satisfy-display-predicates)
(copilot--dbind
(:text :uuid :docVersion doc-version
:range (:start (:line :character start-char)
:end (:character end-char)))
completion-data
(when (= doc-version copilot--doc-version)
(save-excursion
(save-restriction
(widen)
(let* ((p (point))
(goto-line! (lambda ()
(goto-char (point-min))
(forward-line (1- (+ line copilot--line-bias)))))
(start (progn
(funcall goto-line!)
(forward-char start-char)
(let* ((cur-line (buffer-substring-no-properties (point) (line-end-position)))
(common-prefix-len (length (s-shared-start text cur-line))))
(setq text (substring text common-prefix-len))
(forward-char common-prefix-len)
(point))))
(end (progn
(funcall goto-line!)
(forward-char end-char)
(point)))
(fixed-completion (copilot-balancer-fix-completion start end text)))
(goto-char p)
(pcase-let ((`(,start ,end ,balanced-text) fixed-completion))
(copilot--display-overlay-completion balanced-text uuid start end)))))))))
(:text :uuid :docVersion doc-version
:range (:start (:line :character start-char)
:end (:character end-char)))
completion-data
(when (= doc-version copilot--doc-version)
(save-excursion
(save-restriction
(widen)
(let* ((p (point))
(goto-line! (lambda ()
(goto-char (point-min))
(forward-line (1- (+ line copilot--line-bias)))))
(start (progn
(funcall goto-line!)
(forward-char start-char)
(let* ((cur-line (buffer-substring-no-properties (point) (line-end-position)))
(common-prefix-len (length (s-shared-start text cur-line))))
(setq text (substring text common-prefix-len))
(forward-char common-prefix-len)
(point))))
(end (progn
(funcall goto-line!)
(forward-char end-char)
(point)))
(fixed-completion (copilot-balancer-fix-completion start end text)))
(goto-char p)
(pcase-let ((`(,start ,end ,balanced-text) fixed-completion))
(copilot--display-overlay-completion balanced-text uuid start end)))))))))

(defun copilot--on-doc-focus (window)
"Notify that the document has been focussed or opened."
Expand Down