Skip to content

Commit

Permalink
stylua and fix check
Browse files Browse the repository at this point in the history
  • Loading branch information
adalessa committed Apr 16, 2024
1 parent 4e2a832 commit 8013f73
Show file tree
Hide file tree
Showing 34 changed files with 381 additions and 413 deletions.
4 changes: 3 additions & 1 deletion lua/laravel/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function M.async(program, args, onSuccess, onFailure)
if response:successful() then
onSuccess(response)
else
if onFailure then onFailure(response) end
if onFailure then
onFailure(response)
end
end
end),
}):start()
Expand Down
2 changes: 1 addition & 1 deletion lua/laravel/api/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
---@return table|nil
function ApiResponse:json()
return vim.json.decode(self:prettyContent(), {
luanil = { object = true, array = true }
luanil = { object = true, array = true },
})
end

Expand Down
12 changes: 6 additions & 6 deletions lua/laravel/db.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local sqlite = require "sqlite.db"
local tbl = require "sqlite.tbl"

local uri = vim.fn.stdpath("cache") .. '/laravel_db.sqlite'
local uri = vim.fn.stdpath "cache" .. "/laravel_db.sqlite"

---@class CacheTable: sqlite_tbl
---@class HistoryTable: sqlite_tbl
Expand All @@ -26,15 +26,15 @@ local history = tbl("history", {
name = "text",
args = "luatable",
opts = "luatable",
created_on = { "timestampt", default = sqlite.lib.strftime("%s", "now") }
created_on = { "timestampt", default = sqlite.lib.strftime("%s", "now") },
})

-- TODO: define fields for the environment
-- commands ? sail have a general prefix
local environment = tbl("environments", {
id = true,
path = "text",
})
-- local environment = tbl("environments", {
-- id = true,
-- path = "text",
-- })

---@type LaravelDatabase
local DB = sqlite {
Expand Down
4 changes: 2 additions & 2 deletions lua/laravel/extensions/null_ls/completion/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ return function(done, should_quote)
kind = vim.lsp.protocol.CompletionItemKind["Value"],
}
end, vim.tbl_keys(config)),
isIncomplete = false
}
isIncomplete = false,
},
}
end)
end
4 changes: 2 additions & 2 deletions lua/laravel/extensions/null_ls/completion/route.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ return function(done, should_quote)
documentation = string.format("[%s] %s", route.method, route.uri),
}
end, routes),
isIncomplete = false
}
isIncomplete = false,
},
}
end)
end
4 changes: 2 additions & 2 deletions lua/laravel/extensions/null_ls/completion/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ return function(done, should_quote)
documentation = view.path,
}
end, views),
isIncomplete = false
}
isIncomplete = false,
},
}
end)
end
30 changes: 15 additions & 15 deletions lua/laravel/extensions/route_info/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ local function generate_virtual_text_options(route)
if options.position == "right" then
return {
virt_text = {
{ "[", "comment" },
{ "Method: ", "comment" },
{ route.method, "@enum" },
{ " Uri: ", "comment" },
{ route.uri, "@enum" },
{ " Middleware: ", "comment" },
{ "[", "comment" },
{ "Method: ", "comment" },
{ route.method, "@enum" },
{ " Uri: ", "comment" },
{ route.uri, "@enum" },
{ " Middleware: ", "comment" },
{ vim.fn.join(route.middleware or { "None" }, ","), "@enum" },
{ "]", "comment" },
{ "]", "comment" },
},
}
end
if options.position == "top" then
return {
virt_lines = {
{
{ " ", "" },
{ "[", "comment" },
{ "Method: ", "comment" },
{ route.method, "@enum" },
{ " Uri: ", "comment" },
{ route.uri, "@enum" },
{ " Middleware: ", "comment" },
{ " ", "" },
{ "[", "comment" },
{ "Method: ", "comment" },
{ route.method, "@enum" },
{ " Uri: ", "comment" },
{ route.uri, "@enum" },
{ " Middleware: ", "comment" },
{ vim.fn.join(route.middleware or { "None" }, ","), "@enum" },
{ "]", "comment" },
{ "]", "comment" },
},
},
virt_lines_above = true,
Expand Down
4 changes: 3 additions & 1 deletion lua/laravel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ end

return {
setup = setup,
cleanCache = function() require("laravel.services.cache_service"):flush() end,
cleanCache = function()
require("laravel.services.cache_service"):flush()
end,
routes = require("telescope").extensions.laravel.routes,
artisan = require("telescope").extensions.laravel.artisan,
history = require("telescope").extensions.laravel.history,
Expand Down
14 changes: 7 additions & 7 deletions lua/laravel/listeners/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ function listeners:register()
pattern = { "LaravelViewCreated" },
group = group,
callback = vim.schedule_wrap(function()
cacheService:forget('views')
end)
cacheService:forget "views"
end),
})

vim.api.nvim_create_autocmd("User", {
pattern = {
"LaravelCommandCreated",
"LaravelComposerRunned"
"LaravelComposerRunned",
},
group = group,
callback = vim.schedule_wrap(function()
cacheService:forget('commands')
end)
cacheService:forget "commands"
end),
})

vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = { "routes/*.php" },
group = group,
callback = vim.schedule_wrap(function()
cacheService:forget('routes')
end)
cacheService:forget "routes"
end),
})
end

Expand Down
2 changes: 1 addition & 1 deletion lua/laravel/recipes/ide-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end

local function installIdeHelperAndWrite()
api.async("composer", { "require", "--dev", "barryvdh/laravel-ide-helper" }, function()
vim.cmd([[doautocmd User LaravelComposerRunned]])
vim.cmd [[doautocmd User LaravelComposerRunned]]
writeModels()
end, function(errResponse)
vim.notify("Cant install ide-helper\n\r" .. errResponse:prettyErrors(), vim.log.levels.ERROR)
Expand Down
8 changes: 4 additions & 4 deletions lua/laravel/repositories/cache_repository.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local table = require "laravel.db".cache
local table = require("laravel.db").cache

---@class CacheRepository
local CacheRepository = {}
Expand Down Expand Up @@ -33,7 +33,7 @@ end
---@return CacheRecord[]
function CacheRepository:findBy(condition)
---@diagnostic disable-next-line: missing-fields
return table:get({ where = condition })
return table:get { where = condition }
end

---@param record CacheRecord
Expand All @@ -60,7 +60,7 @@ end
---@return boolean
function CacheRepository:delete(id)
---@diagnostic disable-next-line: assign-type-mismatch
return table:remove({ id = id })
return table:remove { id = id }
end

---@return number
Expand All @@ -72,7 +72,7 @@ end
---@return boolean
function CacheRepository:exists(condition)
---@diagnostic disable-next-line: missing-fields
local records = table:get({ where = condition })
local records = table:get { where = condition }

return #records > 0
end
Expand Down
2 changes: 1 addition & 1 deletion lua/laravel/repositories/history_repository.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local table = require "laravel.db".history
local table = require("laravel.db").history

---@class HistoryRepository
local HistoryRepository = {}
Expand Down
80 changes: 32 additions & 48 deletions lua/laravel/resolvers/cache/init.lua
Original file line number Diff line number Diff line change
@@ -1,82 +1,66 @@
local cache_decorator = require 'laravel.resolvers.cache.decorator'
local cache_decorator = require "laravel.resolvers.cache.decorator"

return {
routes = {
---@param onSuccess fun(routes: Route[])|nil
---@param onFailure fun(errorMessage: string)|nil
resolve = function(
onSuccess,
onFailure
)
return cache_decorator({
decorated = require 'laravel.resolvers.routes_resolver',
key = 'routes',
resolve = function(onSuccess, onFailure)
return cache_decorator {
decorated = require "laravel.resolvers.routes_resolver",
key = "routes",
onSuccess = onSuccess,
onFailure = onFailure,
})
end
}
end,
},
commands = {
---@param onSuccess fun(commands: Command[])|nil
---@param onFailure fun(errorMessage: string)|nil
resolve = function(
onSuccess,
onFailure
)
return cache_decorator({
decorated = require 'laravel.resolvers.commands_resolver',
key = 'commands',
resolve = function(onSuccess, onFailure)
return cache_decorator {
decorated = require "laravel.resolvers.commands_resolver",
key = "commands",
onSuccess = onSuccess,
onFailure = onFailure,
})
end
}
end,
},
views = {
---@param onSuccess fun(views: View[])|nil
---@param onFailure fun(errorMessage: string)|nil
resolve = function(
onSuccess,
onFailure
)
return cache_decorator({
decorated = require 'laravel.resolvers.views_resolver',
key = 'views',
resolve = function(onSuccess, onFailure)
return cache_decorator {
decorated = require "laravel.resolvers.views_resolver",
key = "views",
onSuccess = onSuccess,
onFailure = onFailure,
})
end
}
end,
},
configs = {
---@param onSuccess fun(config: Config)|nil
---@param onFailure fun(errorMessage: string)|nil
resolve = function(
onSuccess,
onFailure
)
return cache_decorator({
decorated = require 'laravel.resolvers.configs_resolver',
key = 'configs',
resolve = function(onSuccess, onFailure)
return cache_decorator {
decorated = require "laravel.resolvers.configs_resolver",
key = "configs",
onSuccess = onSuccess,
onFailure = onFailure,
})
end
}
end,
},
paths = {
---@param resource string
---@param onSuccess fun(path: string)|nil
---@param onFailure fun(errorMessage: string)|nil
resolve = function(
resource,
onSuccess,
onFailure
)
return cache_decorator({
decorated = require 'laravel.resolvers.resource_path_resolver',
key = 'paths_' .. resource,
resolve = function(resource, onSuccess, onFailure)
return cache_decorator {
decorated = require "laravel.resolvers.resource_path_resolver",
key = "paths_" .. resource,
onSuccess = onSuccess,
onFailure = onFailure,
args = {resource}
})
end
args = { resource },
}
end,
},
}
19 changes: 11 additions & 8 deletions lua/laravel/resolvers/commands_resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@ local api = require "laravel.api"
---@field name string
---@field shortcut string

local commands_resolver = {};
local commands_resolver = {}

---@param onSuccess fun(commands: Command[])|nil
---@param onFailure fun(errorMessage: string)|nil
function commands_resolver.resolve(
onSuccess,
onFailure
)
function commands_resolver.resolve(onSuccess, onFailure)
api.async("artisan", { "list", "--format=json" }, function(response)
local commands = response:json()

if not commands then
if onFailure then onFailure("no artisan commands found") end
if onFailure then
onFailure "no artisan commands found"
end
return
end

if onSuccess then onSuccess(commands.commands) end
if onSuccess then
onSuccess(commands.commands)
end
end, function(errResponse)
if onFailure then onFailure(errResponse:prettyErrors()) end
if onFailure then
onFailure(errResponse:prettyErrors())
end
end)
end

Expand Down
Loading

0 comments on commit 8013f73

Please sign in to comment.