Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 34 additions & 17 deletions .nvim.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
-- .nvim.lua
-- Local dev helpers for the `sllm` plugin.
local function refresh_sllm()
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h")
local this_file = debug.getinfo(1, "S").source:sub(2)
local root = vim.fn.fnamemodify(this_file, ":h:h")

-- Ensure local plugin is on runtimepath (useful when hacking on it in-place).
vim.opt.rtp:prepend(root)
local m = dofile("lua/sllm/init.lua")
m.setup({
window_type = "vertical",

-- Unload any previously loaded sllm modules to force a clean reload.
for name in pairs(package.loaded) do
if name:match("^sllm") then
package.loaded[name] = nil
end
end

local ok, mod = pcall(dofile, root .. "/lua/sllm/init.lua")
if not ok then
vim.notify("Failed to load sllm: " .. tostring(mod), vim.log.levels.ERROR)
return
end

mod.setup({
window_type = "vertical",
debug = false,
pre_hooks = {
-- {command='ls', add_to_context=true},
-- {command='pwd', add_to_context=true},
-- {command='cat %', add_to_context=true},
}
-- function for item selection (like vim.ui.select)
-- tested alternatives: vim.ui.select, require("mini.pick").ui_select, require("snacks.picker").select
-- pick_func = require("snacks.picker").select,
-- function for notifications (like vim.notify)
-- tested alternatives: vim.notify, require("mini.notify").make_notify(), require("snacks.notifier").notify
-- notify_func = require("snacks.notifier").notify,
-- input_func = require("snacks.input").input,
-- { command = "ls", add_to_context = true },
-- { command = "pwd", add_to_context = true },
-- { command = "cat %", add_to_context = true },
},

-- pick_func = vim.ui.select,
-- notify_func = vim.notify,
-- input_func = vim.ui.input,
})
end

local function source_file()
vim.cmd("source %")
vim.cmd.source("%")
end

vim.keymap.set("n", "<leader>rr", refresh_sllm, { desc = "Reload local sllm plugin" })
vim.keymap.set("n", "<leader>rx", source_file, { desc = "Source current file" })

refresh_sllm()
vim.notify("nvim.lua loaded!", vim.log.levels.INFO)
vim.notify(".nvim.lua loaded!", vim.log.levels.INFO)
6 changes: 4 additions & 2 deletions doc/modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ Use cases:

### sllm_complete

Inline completion mode. Used internally by `<leader><Tab>` for code completion
at the cursor.
Inline completion mode. Used internally by `<leader><Tab>` / `complete_code()`
for code completion at the cursor. Uses the `sllm_complete` template to send the
buffer-around-cursor context (no markdown; raw code out) and runs synchronously
for clean insertion.

System prompt:

Expand Down
6 changes: 4 additions & 2 deletions doc/sllm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,10 @@ Note: Default mode is `sllm_chat`; switch with `<leader>sM` or `/template`.

sllm_complete

Inline completion mode. Used internally by `<leader><Tab>` for code completion
at the cursor.
Inline completion mode. Used internally by `<leader><Tab>` / `complete_code()`
for code completion at the cursor. Uses the `sllm_complete` template to send
the buffer-around-cursor context (no markdown; raw code out) and runs
synchronously for clean insertion.

System prompt:

Expand Down
24 changes: 22 additions & 2 deletions lua/sllm/backend/llm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,32 @@ end
---Build the llm CLI command string.
---@param config table Backend configuration with cmd field.
---@param options table Command options.
---@field options.prompt string Required prompt text.
---@field options.model string? Model name.
---@field options.template string? Template name.
---@field options.continue boolean|string? Continue conversation (true for -c, string for --cid).
---@field options.show_usage boolean? Show token usage.
---@field options.no_stream boolean? Disable streaming output.
---@field options.raw boolean? Skip tool flags (--td --cl) for simple prompts.
---@field options.ctx_files string[]? Context files to include.
---@field options.tools string[]? Tool names to use.
---@field options.functions string[]? Python functions to use.
---@field options.online boolean? Enable online mode.
---@field options.system_prompt string? System prompt.
---@field options.model_options table? Model-specific options.
---@field options.chain_limit integer? Chain limit for tools (default: 100).
---@return string The assembled shell command.
Llm.build_command = function(config, options)
local llm_cmd = config.cmd or 'llm'
local cmd = llm_cmd .. ' --td --cl ' .. (options.chain_limit or 100)
local cmd = llm_cmd

if not options.prompt then error('prompt is required') end

-- Add tool flags unless raw mode is requested
if not options.raw then cmd = cmd .. ' --td --cl ' .. (options.chain_limit or 100) end

if options.no_stream then cmd = cmd .. ' --no-stream' end

if type(options.continue) == 'string' then
cmd = cmd .. ' --cid ' .. vim.fn.shellescape(options.continue)
elseif options.continue then
Expand Down Expand Up @@ -161,7 +180,8 @@ Llm.build_command = function(config, options)

if options.template then cmd = cmd .. ' -t ' .. vim.fn.shellescape(options.template) end

cmd = cmd .. ' ' .. vim.fn.shellescape(options.prompt)
-- Use -- to end options parsing (prompt may start with dashes)
cmd = cmd .. ' -- ' .. vim.fn.shellescape(options.prompt)
return cmd
end

Expand Down
Loading