From e0f1e4ae4bb8762b7c51c3a514ca19664fad9c3b Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 16 Sep 2025 18:14:14 -0500 Subject: [PATCH] opencode: add module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seamlessly integrate the opencode AI assistant with Neovim — convenient and editor-aware research, reviews, and requests. --- plugins/by-name/opencode/default.nix | 36 +++++++ .../plugins/by-name/opencode/default.nix | 95 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 plugins/by-name/opencode/default.nix create mode 100644 tests/test-sources/plugins/by-name/opencode/default.nix diff --git a/plugins/by-name/opencode/default.nix b/plugins/by-name/opencode/default.nix new file mode 100644 index 00000000..d4dca1dc --- /dev/null +++ b/plugins/by-name/opencode/default.nix @@ -0,0 +1,36 @@ +{ lib, ... }: +lib.nixvim.plugins.mkNeovimPlugin { + name = "opencode"; + packPathName = "opencode.nvim"; + package = "opencode-nvim"; + + maintainers = [ lib.maintainers.khaneliman ]; + + description = '' + OpenCode.nvim provides seamless integration with Claude Code for AI-assisted development. + + > [!NOTE] + > Recommended: `snacks.enable` with `settings.input.enabled = true` for better prompt input + > Required: `snacks.enable` to use opencode.nvim's embedded terminal + + > [!TIP] + > Set `opts.autoread = true` if using the `auto_reload` option. + ''; + + callSetup = false; + hasLuaConfig = false; + extraConfig = cfg: { + globals.opencode_opts = cfg.settings; + }; + + settingsExample = { + port = 8080; + auto_reload = false; + prompts = { + example = { + description = "An example prompt configuration"; + prompt = "Write a function that returns the factorial of a number"; + }; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/opencode/default.nix b/tests/test-sources/plugins/by-name/opencode/default.nix new file mode 100644 index 00000000..24df0800 --- /dev/null +++ b/tests/test-sources/plugins/by-name/opencode/default.nix @@ -0,0 +1,95 @@ +{ + empty = { + plugins.opencode.enable = true; + }; + + defaults = { + plugins.opencode = { + enable = true; + settings = { + port = null; + auto_reload = true; + auto_register_cmp_sources = [ + "opencode" + "buffer" + ]; + contexts = { + "@buffer" = { + description = "Current buffer"; + value.__raw = ''require("opencode.context").buffer''; + }; + "@buffers" = { + description = "Open buffers"; + value.__raw = ''require("opencode.context").buffers''; + }; + "@cursor" = { + description = "Cursor position"; + value.__raw = ''require("opencode.context").cursor_position''; + }; + "@selection" = { + description = "Selected text"; + value.__raw = ''require("opencode.context").visual_selection''; + }; + "@visible" = { + description = "Visible text"; + value.__raw = ''require("opencode.context").visible_text''; + }; + "@diagnostic" = { + description = "Current line diagnostics"; + value.__raw = '' + function() + return require("opencode.context").diagnostics(true) + end + ''; + }; + "@diagnostics" = { + description = "Current buffer diagnostics"; + value.__raw = ''require("opencode.context").diagnostics''; + }; + "@quickfix" = { + description = "Quickfix list"; + value.__raw = ''require("opencode.context").quickfix ''; + }; + "@diff" = { + description = "Git diff"; + value.__raw = ''require("opencode.context").git_diff ''; + }; + "@grapple" = { + description = "Grapple tags"; + value.__raw = ''require("opencode.context").grapple_tags ''; + }; + }; + prompts = { + explain = { + description = "Explain code near cursor"; + prompt = "Explain @cursor and its context"; + }; + fix = { + description = "Fix diagnostics"; + prompt = "Fix these @diagnostics"; + }; + optimize = { + description = "Optimize selection"; + prompt = "Optimize @selection for performance and readability"; + }; + document = { + description = "Document selection"; + prompt = "Add documentation comments for @selection"; + }; + test = { + description = "Add tests for selection"; + prompt = "Add tests for @selection"; + }; + review_buffer = { + description = "Review buffer"; + prompt = "Review @buffer for correctness and readability"; + }; + review_diff = { + description = "Review git diff"; + prompt = "Review the following git diff for correctness and readability:\n@diff"; + }; + }; + }; + }; + }; +}