Skip to content

Commit

Permalink
stylua updates
Browse files Browse the repository at this point in the history
  • Loading branch information
softinio committed Oct 2, 2023
1 parent a2d2e97 commit 7c521a4
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 95 deletions.
7 changes: 2 additions & 5 deletions lua/scaladex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ M.search = function(query, target, scalaVersion)
v = v,
}

local url = string.gsub(
"https://index.scala-lang.org/api/search?q=$q&target=$t&scalaVersion=$v",
"$(%w+)",
parameters
)
local url =
string.gsub("https://index.scala-lang.org/api/search?q=$q&target=$t&scalaVersion=$v", "$(%w+)", parameters)

local response = curl.request({
url = url,
Expand Down
186 changes: 96 additions & 90 deletions lua/telescope/_extensions/scaladex/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,112 @@ local M = {}

M.search = function(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "scaladex search",
finder = finders.new_table({
results = {},
}),
layout_strategy = "bottom_pane",
layout_config = {
height = 1,
},
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_current_line()
local results = scaladex.search(selected)
if next(results) == nil then
vim.notify("No results for " .. selected)
else
M.package_search(opts, results)
end
end)
return true
end,
}):find()
pickers
.new(opts, {
prompt_title = "scaladex search",
finder = finders.new_table({
results = {},
}),
layout_strategy = "bottom_pane",
layout_config = {
height = 1,
},
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_current_line()
local results = scaladex.search(selected)
if next(results) == nil then
vim.notify("No results for " .. selected)
else
M.package_search(opts, results)
end
end)
return true
end,
})
:find()
end

M.package_search = function(opts, results)
opts = opts or {}
pickers.new(opts, {
prompt_title = "scaladex package selection",
sorter = conf.generic_sorter(opts),
layout_strategy = "vertical",
layout_config = {
height = 10,
width = 0.3,
prompt_position = "bottom",
},
finder = finders.new_table({
results = results,
entry_maker = function(entry)
return {
value = entry,
display = entry["repository"] .. " by " .. entry["organization"],
ordinal = entry["repository"],
}
pickers
.new(opts, {
prompt_title = "scaladex package selection",
sorter = conf.generic_sorter(opts),
layout_strategy = "vertical",
layout_config = {
height = 10,
width = 0.3,
prompt_position = "bottom",
},
finder = finders.new_table({
results = results,
entry_maker = function(entry)
return {
value = entry,
display = entry["repository"] .. " by " .. entry["organization"],
ordinal = entry["repository"],
}
end,
}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_selected_entry()
if next(selected) ~= nil then
local value = selected["value"]
local selection = scaladex.get_project(value["organization"], value["repository"])
M.artifacts(opts, selection, value["organization"], value["repository"])
end
end)
return true
end,
}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_selected_entry()
if next(selected) ~= nil then
local value = selected["value"]
local selection = scaladex.get_project(value["organization"], value["repository"])
M.artifacts(opts, selection, value["organization"], value["repository"])
end
end)
return true
end,
}):find()
})
:find()
end

M.artifacts = function(opts, results, organization, repository)
opts = opts or {}
pickers.new(opts, {
prompt_title = "scaladex artifact selection",
sorter = conf.generic_sorter(opts),
layout_strategy = "vertical",
layout_config = {
height = 10,
width = 0.3,
prompt_position = "bottom",
},
finder = finders.new_table({
results = results["artifacts"],
entry_maker = function(entry)
return {
value = entry,
display = entry,
ordinal = entry,
}
pickers
.new(opts, {
prompt_title = "scaladex artifact selection",
sorter = conf.generic_sorter(opts),
layout_strategy = "vertical",
layout_config = {
height = 10,
width = 0.3,
prompt_position = "bottom",
},
finder = finders.new_table({
results = results["artifacts"],
entry_maker = function(entry)
return {
value = entry,
display = entry,
ordinal = entry,
}
end,
}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_selected_entry()
if next(selected) ~= nil then
local value = selected["value"]
local dep = helpers.create_dependency_string(results, value)
helpers.copy_to_clipboard(dep)
end
end)
map("i", "<C-s>", function()
actions.close(prompt_bufnr)
local url = "https://index.scala-lang.org/" .. organization .. "/" .. repository
helpers.open_browser(url)
end)
return true
end,
}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selected = action_state.get_selected_entry()
if next(selected) ~= nil then
local value = selected["value"]
local dep = helpers.create_dependency_string(results, value)
helpers.copy_to_clipboard(dep)
end
end)
map("i", "<C-s>", function()
actions.close(prompt_bufnr)
local url = "https://index.scala-lang.org/" .. organization .. "/" .. repository
helpers.open_browser(url)
end)
return true
end,
}):find()
})
:find()
end

return M

0 comments on commit 7c521a4

Please sign in to comment.