Giter VIP home page Giter VIP logo

emacs-cody's Introduction

cody.el: Sourcegraph Cody in Emacs

Do not use this yet; it is in development.

Status

  • Code autocompletions should be usable now.
  • Telemetry probably isn’t working; API has changed and it needs to be re-implemented for the new protocol.

Configuration

It uses a distributed copy of the Cody agent as compressed javascript, but you can override this by specifying the location of the agent binary, e.g.:

(setq cody--agent-binary
      "/path/to/eg/cody/agent/dist/agent-macos-arm64/agent-macos-arm64")

Fetches your access token via auth-source and hardcodes the instance and codebase. You can currently bypass this by setting your access token directly:

(setq cody--access-token "sgp_etc")

To try it out, evaluate the buffer and `M-x cody-login’.

Note: For now, if you are using the extension and want ripgrep support, you will want to add this to your `~/.bashrc` or equivalent:

export MOCK_RG_PATH="/opt/homebrew/bin/rg" # path to your rg binary

Sample Configuration

You can create a Sourcegraph access token at https://sourcegraph.com/users/yourname/settings/tokens.

;; Tell `use-package' where to find your clone of `cody.el'.
(add-to-list 'load-path (expand-file-name "~/my/path/to/emacs-cody"))

(use-package cody
  :straight nil
  :commands (cody-login cody-restart cody-chat cody-mode)
  ;; Some common key bindings.
  :bind (("C-M-n" . cody-completion-cycle-next-key-dispatch)
         ("C-M-p" . cody-completion-cycle-prev-key-dispatch)
         ("M-TAB" . cody-completion-accept-key-dispatch)
         ("C-M-g" . cody-quit-key-dispatch))
  :init
  (setq cody--sourcegraph-host "sourcegraph.com") ; for clarity; this is the default.
  (setq cody--access-token "sgp_asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf")
  (setopt cody-workspace-root "/your/path/to/some/project/dir") ; optional
  (setenv "MOCK_RG_PATH" "/opt/homebrew/bin/rg") ; ripgrep
  :config
  (defalias 'cody-start 'cody-login))

Available commands

`M-x cody` will start Cody and prompt you with available commands `M-x cody-chat` will pop you immediately into the Q&A command

Chat is just a stub for now.

Debugging

`M-x cody-login` to start and initialize the agent without doing a command `M-x cody-force-unload` to tear everything down

(load-file "cody.el")

(cody--request 'recipes/list)
(cody--request 'recipes/execute
               :id "code-question"
               :humanChatInput "Does cody work in emacs?")

You can view the output by switching to the *cody output* and *cody events* buffer. You can also see debugging messages in the *cody log* buffer.

You can shut down the connection with *M-x cody-shutdown*, or shut it down and remove all traces with *M-x cody-force-unload*.

Alternatively run list-processes and select the buffer. You can also shut down cody by hitting d on the cody process.

Attaching with a Debugger

Start by binding *cody-agent-command* to a list like this one, which points to the path of the agent that you have cloned.

(setq cody-agent-command
      (list "node"
            "/Users/stevey/src/sg/cody/agent/dist/index.js"
            ""))

This will allow you to rebuild and reattach in a tight dev loop.

Restart Cody, e.g. with *M-x cody-restart*, and then verify that Cody is running the version of the agent in *cody-agent-command*.

$ ps aux | grep node
yourself 31174Ss 4:08PM ~/.asdf/installs/nodejs/20.4.0/bin/node \
       ~/src/sg/cody/agent/dist/index.js 

To have it listen for the debugger to attach, you can either run the script *./bin/debug-cody*, or send the sigusr1 to the pid of the node process yourself like so:

$ kill -USR1 31174

Either way, your Agent should now be listening for a debugger.

Now you can attach with *chrome://inspect* or with VSCode’s debugger. VSCode is recommended, as it seems to connect more reliably - use the built-in configuration =*Debug: Attach to Node Process=*.

You should also *(setq jsonrpc-default-request-timeout 500)* to ensure that the jsonrpc calls don’t time out while you’re paused at breakpoints.

N.B. Everything stops when the debugger is stopped at a breakpoint, as Emacs concurrency is cooperative.

emacs-cody's People

Contributors

steveyegge avatar keegancsmith avatar dominiccooney avatar renovate[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.