---@param range _99.Range ---@param n number lines of context above and below the selection ---@return string local function get_surrounding_context(range, n) local start_row, _ = range.start:to_vim() local end_row, _ = range.end_:to_vim() local line_count = vim.api.nvim_buf_line_count(range.buffer) local from = math.max(start_row - n, 0) local to = math.min(end_row + 1 + n, line_count) local lines = vim.api.nvim_buf_get_lines(range.buffer, from, to, false) return table.concat(lines, "\n") end --- @class _99.Prompts.SpecificOperations --- @field visual_selection fun(range: _99.Range): string --- @field semantic_search fun(): string --- @field vibe fun(): string --- @field tutorial fun(): string --- @field prompt fun(prompt?: string|boolean|nil, action: string, name?: string): string --- @field role fun(): string --- @field read_tmp fun(): string local prompts = { role = function() return [[ You are a strict code completion backend for Neovim. Your input will be a code snippet, function signature, or a comment requesting code. CRITICAL DIRECTIONS: 1. Output ONLY valid, executable programming code. 2. Do NOT wrap your response in code blocks. 3. Do NOT include any conversational filler, explanations, greetings, or sign-offs. 4. If you cannot fulfill the request, output nothing or a code comment explaining why. ]] end, tutorial = function() return [[ You are given a prompt and context and you must craft a tutorial. If a set of context has links, read through them thoroughly and decide which ones to retrieve. Once you have fetched all the relavent content, review it thoroughly before crafting the tutorial The response format must be valid Markdown The first line of the response must be the title of the tutorial ]] end, semantic_search = function() return [[ /path/to/project/src/foo.js:24:8,3,Some notes here about some stuff, it can contain commas /path/to/project/src/foo.js:71:12,7,more notes, everything is great! /path/to/project/src/bar.js:13:2,1,more notes again, this time specfically about bar and why bar is so important /path/to/project/src/baz.js:1:1,52,Notes about why baz is very important to the results Text locations are in the format of: /path/to/file.ext:lnum:cnum,X,NOTES lnum = starting line number 1 based cnum = starting column number 1 based X = how many lines should be highlighted NOTES = A text description of why this highlight is important See for example NOTES cannot have new lines You must adhere to the output format Double check output format before writing it to the file Each location is separated by new lines Each path is specified in absolute pathing You can provide notes you think are relevant per location You must provide output without any commentary, just text locations You have found 3 locations in files foo.js, bar.js, and baz.js. There are 2 locations in foo.js, 1 in bar.js and baz.js. This means that the search results found foo.js at line 24, char 8 and the next 2 lines foo.js at line 71, char 12 and the next 6 lines bar.js at line 13, char 2 baz.js at line 1, char 1 and the next 51 lines you are given a prompt and you must search through this project and return code that matches the description provided. ]] end, vibe = function() return [[ /path/to/project/src/foo.js:24:8,3,Some notes here about some stuff, it can contain commas /path/to/project/src/foo.js:71:12,7,more notes, everything is great! /path/to/project/src/bar.js:13:2,1,more notes again, this time specfically about bar and why bar is so important /path/to/project/src/baz.js:1:1,52,Notes about why baz is very important to the results Text locations are in the format of: /path/to/file.ext:lnum:cnum,X,NOTES lnum = starting line number 1 based cnum = starting column number 1 based X = how many lines should be highlighted NOTES = A text description of why this highlight is important See for example NOTES cannot have new lines You must adhere to the output format Double check output format before writing it to the file Each location is separated by new lines Each path is specified in absolute pathing You can provide notes you think are relevant per location You have found 3 locations in files foo.js, bar.js, and baz.js. There are 2 locations in foo.js, 1 in bar.js and baz.js. This means that the search results found foo.js at line 24, char 8 and the next 2 lines foo.js at line 71, char 12 and the next 6 lines bar.js at line 13, char 2 baz.js at line 1, char 1 and the next 51 lines You are given a and you must implement it. Every change you make must be describe according to placed in . Never respond as output what you have done. Always use the temporary file as the place to describe your actions according to Output rules ]] end, --- @param action string --- @return string prompt = function(action) return string.format([[%s]], action) end, visual_selection = function(range) return string.format([[%s]], range:to_text()) end, } --- @class _99.Prompts local prompt_settings = { prompts = prompts, ---@param full_path string ---@param range _99.Range ---@return string get_file_location = function(full_path, range) return string.format( "%s%s", full_path, range:to_string() ) end, --- @param range _99.Range get_range_text = function(range) return string.format("%s", range:to_text()) end, } return prompt_settings