Skip to content

Commit

Permalink
Merge pull request #24 from desdic/20231109modifiable
Browse files Browse the repository at this point in the history
Made buffer for output readonly
  • Loading branch information
desdic committed Nov 9, 2023
2 parents 161e935 + d5ee695 commit c2421a5
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
manager: sudo apt-get
packages: -y make lua-check
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/v0.8.0/nvim-linux64.tar.gz
url: https://github.com/neovim/neovim/releases/download/v0.9.0/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y make lua-check
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz
url: https://github.com/neovim/neovim/releases/download/v0.8.0/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y make lua-check
steps:
Expand Down
5 changes: 5 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
column_width = 80
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
quote_style = "AutoPreferDouble"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ all: lint test
test:
nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/automated/ { minimal_init = './scripts/minimal_init.vim' }"

fmt:
stylua lua/ --config-path=.stylua.toml

lint:
luacheck lua/greyjoy
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Integration with [toggleterm](https://github.com/akinsho/toggleterm.nvim) is als

## Requirements

Neovim 0.7+ is required
Neovim 0.8+ is required

## Default settings

Expand All @@ -23,7 +23,7 @@ Neovim 0.7+ is required
ui = {
buffer = { -- width and height for the buffer output
width = 100,
height = 60
height = 50
},
toggleterm = { -- by default no size is defined for the toggleterm by
-- greyjoy.nvim it will be dependent on the user configured size for toggle
Expand Down
18 changes: 12 additions & 6 deletions lua/greyjoy/_extensions/cargo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ local ok, greyjoy = pcall(require, "greyjoy")
if not ok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

Expand All @@ -23,7 +25,7 @@ M.parse = function(fileinfo)
for _, v in ipairs(M.config.targets) do
local elem = {}
local name = "cargo"
local cmd = {"cargo"}
local cmd = { "cargo" }

for _, option in ipairs(v) do
name = name .. " " .. option
Expand Down Expand Up @@ -56,12 +58,16 @@ return greyjoy.register_extension({
if not M.config.targets then
M.config = {
targets = {
{"build"}, {"build", "--release"}, {"check"}, {"clean"},
{"update"}, {"run"}
}
{ "build" },
{ "build", "--release" },
{ "check" },
{ "clean" },
{ "update" },
{ "run" },
},
}
end
end,
health = M.health,
exports = {type = "file", files = {"Cargo.toml"}, parse = M.parse}
exports = { type = "file", files = { "Cargo.toml" }, parse = M.parse },
})
14 changes: 10 additions & 4 deletions lua/greyjoy/_extensions/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ local ok, greyjoy = pcall(require, "greyjoy")
if not ok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

local uok, utils = pcall(require, "greyjoy.utils")
if not uok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

Expand Down Expand Up @@ -60,6 +64,8 @@ M.parse = function(fileobj)
end

return greyjoy.register_extension({
setup = function(config) M.config = config end,
exports = {type = "global", parse = M.parse}
setup = function(config)
M.config = config
end,
exports = { type = "global", parse = M.parse },
})
25 changes: 18 additions & 7 deletions lua/greyjoy/_extensions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ extensions._health = {}
local load_extension = function(name)
local ok, ext = pcall(require, "greyjoy._extensions." .. name)
if not ok then
vim.notify("Unable to require greyjoy._extensions." .. name,
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.notify(
"Unable to require greyjoy._extensions." .. name,
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end
return ext
Expand All @@ -19,19 +22,27 @@ extensions.manager = setmetatable({}, {
local ext = load_extension(k)
if ext then
t[k] = ext.exports or {}
if ext.setup then ext.setup(extensions._config[k] or {}) end
if ext.setup then
ext.setup(extensions._config[k] or {})
end
extensions._health[k] = ext.health

return t[k]
end
return nil
end
end,
})

extensions.register = function(mod) return mod end
extensions.register = function(mod)
return mod
end

extensions.load = function(name) return extensions.manager[name] end
extensions.load = function(name)
return extensions.manager[name]
end

extensions.set_config = function(config) extensions._config = config or {} end
extensions.set_config = function(config)
extensions._config = config or {}
end

return extensions
29 changes: 20 additions & 9 deletions lua/greyjoy/_extensions/kitchen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ local ok, greyjoy = pcall(require, "greyjoy")
if not ok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

local uok, utils = pcall(require, "greyjoy.utils")
if not uok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

Expand All @@ -35,23 +39,29 @@ M.parse = function(fileinfo)

vim.loop.chdir(original_cwd)

if not pipe then return elements end
if not pipe then
return elements
end

local data = pipe:read("*a")
io.close(pipe)

if #data == 0 then return elements end
if #data == 0 then
return elements
end

local tmp = vim.split(string.sub(data, 1, #data - 1), "\n")

if M.config.include_all then table.insert(tmp, "all") end
if M.config.include_all then
table.insert(tmp, "all")
end

for _, v in ipairs(tmp) do
if v ~= "" then
for _, target in ipairs(M.config.targets) do
local elem = {}
elem["name"] = "kitchen " .. target .. " " .. v
elem["command"] = {"kitchen", target, v}
elem["command"] = { "kitchen", target, v }
elem["path"] = filepath
table.insert(elements, elem)
end
Expand All @@ -66,7 +76,8 @@ M.health = function()
health.report_ok("`kitchen`: Ok")
else
health.report_error(
"`kitchen` requires kitchen (cinc-workstation/chefdk) to be installed")
"`kitchen` requires kitchen (cinc-workstation/chefdk) to be installed"
)
end
if vim.fn.executable("awk") == 1 then
health.report_ok("`awk`: Ok")
Expand All @@ -79,7 +90,7 @@ M.setup = function(config)
M.config = config

if not M.config.targets then
M.config["targets"] = {"converge", "verify", "test", "destroy"}
M.config["targets"] = { "converge", "verify", "test", "destroy" }
end

M.config.include_all = utils.if_nil(M.config.include_all, false)
Expand All @@ -88,5 +99,5 @@ end
return greyjoy.register_extension({
setup = M.setup,
health = M.health,
exports = {type = "file", files = {".kitchen.yml"}, parse = M.parse}
exports = { type = "file", files = { ".kitchen.yml" }, parse = M.parse },
})
27 changes: 19 additions & 8 deletions lua/greyjoy/_extensions/makefile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ local ok, greyjoy = pcall(require, "greyjoy")
if not ok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR, {title = "Plugin error"})
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

Expand All @@ -20,26 +22,35 @@ M.parse = function(fileinfo)
local filepath = fileinfo.filepath
local elements = {}

local pipe = io.popen("make -pRrq -f " .. filename .. " -C " .. filepath ..
[[ : 2>/dev/null |
local pipe = io.popen(
"make -pRrq -f "
.. filename
.. " -C "
.. filepath
.. [[ : 2>/dev/null |
awk -F: '/^# Files/,/^# Finished Make data base/ {
if ($1 == "# Not a target") skip = 1;
if ($1 !~ "^[#.\t]") { if (!skip) {if ($1 !~ "^$")print $1}; skip=0 }
}' 2>/dev/null]])
}' 2>/dev/null]]
)

if not pipe then return elements end
if not pipe then
return elements
end

local data = pipe:read("*a")
io.close(pipe)

if #data == 0 then return elements end
if #data == 0 then
return elements
end

local tmp = vim.split(string.sub(data, 1, #data - 1), "\n")
for _, v in ipairs(tmp) do
if v ~= "" then
local elem = {}
elem["name"] = "make " .. v
elem["command"] = {"make", v}
elem["command"] = { "make", v }
elem["path"] = filepath

table.insert(elements, elem)
Expand All @@ -65,5 +76,5 @@ end
return greyjoy.register_extension({
setup = function(_) end,
health = M.health,
exports = {type = "file", files = {"Makefile"}, parse = M.parse}
exports = { type = "file", files = { "Makefile" }, parse = M.parse },
})
48 changes: 48 additions & 0 deletions lua/greyjoy/_extensions/project.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local utils = require("greyjoy.utils")
local ok, greyjoy = pcall(require, "greyjoy")
if not ok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.lsp.log_levels.ERROR,
{ title = "Plugin error" }
)
return
end

local M = {}

M.readfile = function(filename)
if not utils.file_exists(filename) then
return nil
end
local content = vim.fn.readfile(filename)
local obj = vim.fn.json_decode(content)
return obj
end

M.parse = function(fileobj)
local globalcommands = {}
-- Reuse the greyjoy patterns to find root of project
local rootdir =
vim.fs.dirname(vim.fs.find(greyjoy.patterns, { upward = true })[1])
local filename = rootdir .. "/greyjoy.json"

local obj = M.readfile(filename)
if obj then
for key, value in pairs(obj) do
print(vim.inspect(key, value))
end
end

return globalcommands
end

return greyjoy.register_extension({
setup = function(config)
M.config = config
end,
exports = {
type = "global",
parse = M.parse,
},
})
Loading

0 comments on commit c2421a5

Please sign in to comment.