Skip to content

Commit

Permalink
fixed some problems with the treesitter search
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyshear committed Nov 19, 2024
1 parent b5d7d16 commit 41fd1ec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
drash-drash.nvim drash.txt /*drash-drash.nvim*
drash-drash.nvim-development drash.txt /*drash-drash.nvim-development*
drash-drash.nvim-installation drash.txt /*drash-drash.nvim-installation*
drash-links drash.txt /*drash-links*
drash-table-of-contents drash.txt /*drash-table-of-contents*
drash.txt drash.txt /*drash.txt*
40 changes: 26 additions & 14 deletions lua/drash/sefaria.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local plenary_curl = require('plenary.curl')
local drash_util = require('drash.util')
local drash_utils = require('drash.util')

local M = {}

Expand All @@ -14,7 +14,6 @@ M.get_calendar = function()

local body = response.body
local data = vim.json.decode(body)

return data
end

Expand All @@ -25,38 +24,51 @@ M.post_search = function(query)
local url = 'https://www.sefaria.org/api/search-wrapper'

local response = plenary_curl.post(url, {
body = '{ "query":"' .. query .. '" }',
body = '{ "query":"' .. query .. '", "source_proj":true }',
headers = {
['Content-Type'] = 'application/json',
accept = 'application/json',
},
})

if response.status ~= 200 then
return nil
end

local body = response.body
local data = vim.fn.json_decode(response.body)
return data
end

local data = vim.json.decode(body)
M.post_find_refs = function(title, body)
local url = 'https://www.sefaria.org/api/find-refs'
local response = plenary_curl.post(url, {
body = '{ "text": {"title":"' .. title .. '", "body":"' .. body .. '"}, "lang":"en" }',
headers = {
['Content-Type'] = 'application/json',
},
})

if response.status ~= 200 then
return nil
end

local data = vim.fn.json_decode(response.body)
return data
end

M.get_text = function(id)
id = drash_util.url_encode(id)
local url = 'https://www.sefaria.org/api/v3/texts/'
.. id
.. '?version=english&return_format=text_only'
print(url)
id = drash_utils.url_encode(id)
local url = 'https://www.sefaria.org/api/v3/texts/' .. id

local response = plenary_curl.get(url)
local response = plenary_curl.get(url, {
query = { version = 'english', return_format = 'text_only' },
})

if response.status ~= 200 then
return nil
end

local body = response.body
local data = vim.json.decode(body)

local data = vim.fn.json_decode(response.body)
return data
end

Expand Down
26 changes: 13 additions & 13 deletions lua/telescope/_extensions/drash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ local finders = require('telescope.finders')
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local previewers = require('telescope.previewers')
local make_entry = require('telescope.make_entry')
local conf = require('telescope.config').values

local M = {}

M.search_sefaria = function(opts)
opts = opts or { prompt = '' }
opts.entry_maker = make_entry.gen_from_string(opts)
print(opts.prompt)

local searcher = function(prompt)
if not prompt or prompt == '' then
Expand All @@ -25,31 +22,33 @@ M.search_sefaria = function(opts)
return {}
end

local hits = search_list.hits.hits
for i, hit in ipairs(search_list.hits.hits) do
hits[i] = hit._id
end

return hits
return search_list.hits.hits
end

pickers
.new(opts, {
prompt_title = 'Search Sefaria',
finder = finders.new_table({
results = searcher(opts.prompt),
entry_maker = opts.entry_maker,
entry_maker = function(entry)
return {
value = entry,
display = entry._id or entry.id,
ordinal = entry._id or entry.id,
}
end,
}),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selected = action_state.get_selected_entry()
print(vim.inspect(selected))
actions.close(prompt_bufnr)
if selected == nil then
return
end

local response = require('drash.sefaria').get_text(selected[1])
local response = require('drash.sefaria').get_text(
selected.value._source.ref or selected.value.source.ref
)
local text = {}
if response == nil then
text = { 'Error fetching text' }
Expand All @@ -68,7 +67,8 @@ M.search_sefaria = function(opts)
end,
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry)
local response = require('drash.sefaria').get_text(entry[1])
local response =
require('drash.sefaria').get_text(entry.value._source.ref or entry.value.source.ref)
local text = {}
if response == nil then
text = { 'Error fetching text' }
Expand Down

0 comments on commit 41fd1ec

Please sign in to comment.