Skip to content

Commit

Permalink
feat: show the matched lines as documentation for context
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Nov 4, 2024
1 parent 8d64505 commit 76676af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions integration-tests/cypress/e2e/cmp-rg/basic_spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ describe("the basics", () => {
cy.typeIntoTerminal("hip")

cy.contains("Hippopotamus123 (rg)")

// should show documentation with more details about the match
cy.contains("Hippopotamus123 is my password")
})
})
})
3 changes: 2 additions & 1 deletion integration-tests/test-environment/other-file.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
This file contains some text that can be matched in integration-tests.
Hippopotamus123
Hippopotamus123 is my password.
Hippopotamus234 was my previous password.
4 changes: 4 additions & 0 deletions integration-tests/test-environment/test-setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ local plugins = {
autocomplete = {
max_height = 25,
},
documentation = {
auto_show = true,
auto_show_delay_ms = 0,
},
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions lua/blink-cmp-rg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ function RgSource:get_completions(context, resolve)
item = ok and item or {}

if item.type == "match" then
assert(
item.data.lines.text,
"ripgrep output missing item.data.lines.text for item "
.. vim.inspect(item)
)
local documentation = item.data.lines.text or ""
for _, submatch in ipairs(item.data.submatches) do
---@diagnostic disable-next-line: missing-fields
items[submatch.match.text] = {
documentation = documentation,
source_id = "blink-cmp-rg",
label = submatch.match.text .. " (rg)",
insertText = submatch.match.text,
Expand Down

0 comments on commit 76676af

Please sign in to comment.