Compare commits
8
Commits
main
...
57e8eb0248
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57e8eb0248 | ||
|
|
0f542d56ef | ||
|
|
e2864159a8 | ||
|
|
380f295c93 | ||
|
|
06eb74e13f | ||
|
|
98bd619cfa | ||
|
|
6593db3829 | ||
|
|
4bcac5d09b |
@@ -1,201 +1,21 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
MIT License
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
Copyright (c) 2026 Andrew Haynes
|
||||
|
||||
1. Definitions.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2025 DarthMooMancer
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1 align="center">Polydev</h1>
|
||||
<h1 align="center">Vern.nvim</h1>
|
||||
|
||||
<p align="center"><em>A multi-language project managing plugin for file creation, building, and running code—all within neovim. Whether you're coding in C/C++ Java, Python, Lua, Rust, and more, Polydev provides seamless integration to boost your productivity inside Neovim.</em></p>
|
||||
<p align="center"><em>Vern.nvim or Vernacular.nvim is a multi lingual project manager. It creates new projects and files from templates, builds and runs code and can run language specific functions within Neovim</em></p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Lua-1e90ff?style=for-the-badge&logo=lua&logoColor=white" />
|
||||
@@ -10,29 +10,30 @@
|
||||
</p>
|
||||
|
||||
|
||||
NOTE: The plugin may not work well with lazy or any other package manager other than vim.pack. I dont understand enough about nvim api and lua to handle these other things right now
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
* Create and manage projects directly from Neovim
|
||||
* Create projects directly from Neovim
|
||||
* Generate new files quickly
|
||||
* Build your code with customizable build systems
|
||||
* Run programs without leaving the editor
|
||||
* Integrated terminal for flexible command execution
|
||||
* Lightweight, fast project manager UI
|
||||
* Minimal configuration with extensibility in mind
|
||||
* Built-in diagnostics with `:checkhealth Polydev`
|
||||
|
||||
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/polydev/wiki/Home$0) for setup, configuration, and usage details.
|
||||
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern.nvim/wiki/Home$0) for setup, configuration, and usage details.
|
||||
|
||||
## Supported Languages
|
||||
|
||||
Polydev currently supports the following languages:
|
||||
Vern.nvim currently supports the following languages:
|
||||
|
||||
* Java
|
||||
* Python
|
||||
* C / C++
|
||||
* Lua
|
||||
* Rust
|
||||
* HTML
|
||||
<!-- * Java -->
|
||||
<!-- * C / C++ -->
|
||||
<!-- * Lua -->
|
||||
<!-- * Rust -->
|
||||
<!-- * HTML -->
|
||||
|
||||
Additional language support is planned for future releases.
|
||||
|
||||
@@ -41,8 +42,6 @@ Additional language support is planned for future releases.
|
||||
|
||||
Current focus:
|
||||
* **Refactoring and internal cleanup.**
|
||||
* **Remaking it not in nui to make tabs, mainly for recent projects as the main page**
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -52,4 +51,4 @@ Contributions are welcome and appreciated.
|
||||
* Submit a pull request if you'd like to contribute directly.
|
||||
|
||||
If you have an idea or use case you'd like to see supported, let’s discuss it.
|
||||
Your feedback and contributions are key to making Polydev even better! Thank you for being part of the journey. 🙏
|
||||
Your feedback and contributions are key to making Vern.nvim even better! Thank you for being part of the journey. 🙏
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
DIR="$(pwd)"
|
||||
|
||||
while [[ ! -f "$DIR/CMakeLists.txt" && \
|
||||
! -f "$DIR/package.json" && \
|
||||
! -f "$DIR/venv" && \
|
||||
! -d "$DIR/.git" && \
|
||||
"$DIR" != "/" ]]; do
|
||||
DIR="$(dirname "$DIR")"
|
||||
done
|
||||
|
||||
if [[ "$DIR" == "/" ]]; then
|
||||
echo "❌ Project root not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$DIR"
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.user_config = {}
|
||||
|
||||
---@param user_opts table
|
||||
function M.setup(user_opts)
|
||||
user_opts = user_opts or {}
|
||||
local project_root = (user_opts.globals and user_opts.globals.project_root) or "~/personal/Projects"
|
||||
local defaults = {
|
||||
rust = {
|
||||
project_root = project_root .. "/Rust",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "RustRun",
|
||||
},
|
||||
},
|
||||
javascript = {
|
||||
project_root = project_root .. "/Javascript",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "JavascriptRun",
|
||||
},
|
||||
},
|
||||
java = {
|
||||
project_root = project_root .. "/Java",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "JavaRun",
|
||||
},
|
||||
},
|
||||
lua = {
|
||||
project_root = project_root .. "/Lua",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "LuaRun",
|
||||
},
|
||||
},
|
||||
c = {
|
||||
project_root = project_root .. "/C",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "CRun",
|
||||
},
|
||||
},
|
||||
cpp = {
|
||||
project_root = project_root .. "/CPP",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "CppRun",
|
||||
},
|
||||
},
|
||||
python = {
|
||||
project_root = project_root .. "/Python",
|
||||
keybinds = {
|
||||
["<leader>pr"] = "PythonRun",
|
||||
["<leader>pb"] = "PythonPip",
|
||||
},
|
||||
},
|
||||
html = {
|
||||
project_root = project_root .. "/Html",
|
||||
},
|
||||
globals = {
|
||||
project_root = project_root,
|
||||
keybinds = {
|
||||
["<leader>po"] = "PolydevOpen",
|
||||
},
|
||||
},
|
||||
terminal = {
|
||||
mode = "split",
|
||||
win = {
|
||||
type = "horizontal", anchor = "bottom", size = "20"
|
||||
},
|
||||
border = {
|
||||
enabled = true,
|
||||
type = "rounded",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
M.user_config = vim.tbl_deep_extend("force", defaults, user_opts)
|
||||
end
|
||||
|
||||
---@param lang string
|
||||
---@return table
|
||||
function M.get(lang)
|
||||
return M.user_config[lang] or {}
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,51 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
local config = require("Polydev.configs")
|
||||
if config == nil then
|
||||
return -1
|
||||
end
|
||||
config.setup(opts)
|
||||
require("Polydev.utils").setup(opts)
|
||||
|
||||
vim.api.nvim_create_user_command("PolydevOpen", function() require("Polydev.ui").manager(config.get("globals").project_root) end, {})
|
||||
|
||||
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
|
||||
for key, _ in pairs(keys) do
|
||||
vim.keymap.set("n", key, ":PolydevOpen<CR>")
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
local filetype = vim.bo.filetype
|
||||
require("Polydev.languages").load_language_module(filetype, opts)
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||
callback = function()
|
||||
local function define(name, o)
|
||||
if vim.fn.hlexists(name) == 0 then
|
||||
vim.api.nvim_set_hl(0, name, o)
|
||||
end
|
||||
end
|
||||
define("PolydevNormal", {
|
||||
fg = vim.api.nvim_get_hl(0, { name = "NormalFloat", link = true }).fg,
|
||||
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
|
||||
})
|
||||
|
||||
define("PolydevBorder", {
|
||||
fg = vim.api.nvim_get_hl(0, { name = "FloatBorder", link = true }).fg,
|
||||
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
|
||||
})
|
||||
|
||||
define("PolydevTitle", {
|
||||
fg = vim.api.nvim_get_hl(0, { name = "FloatTitle", link = true }).fg, bold = true,
|
||||
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,226 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local configs = require("Polydev.configs")
|
||||
local M = {}
|
||||
|
||||
local loaded_languages = {}
|
||||
|
||||
---@param lang string
|
||||
---@param opts? table
|
||||
---@return boolean
|
||||
function M.load_language_module(lang, opts)
|
||||
if loaded_languages[lang] then return true end
|
||||
|
||||
local ok, mod = pcall(require, "Polydev.languages")
|
||||
if not ok or type(mod.languages) ~= "table" then return false end
|
||||
|
||||
local lang_mod = mod.languages[lang]
|
||||
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then return false end
|
||||
|
||||
lang_mod:setup(opts and opts[lang] or {})
|
||||
loaded_languages[lang] = lang_mod
|
||||
return true
|
||||
end
|
||||
|
||||
M.languages = {
|
||||
javascript = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("javascript"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavascriptRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavascriptRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("node " .. root .. "/main.js")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "node " .. root .. "/main.js" })
|
||||
end
|
||||
end
|
||||
},
|
||||
java = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
end
|
||||
end
|
||||
},
|
||||
c = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
end
|
||||
end
|
||||
},
|
||||
cpp = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CppRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
end
|
||||
end
|
||||
},
|
||||
html = {
|
||||
setup = function(user_opts)
|
||||
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
|
||||
end
|
||||
},
|
||||
rust = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("RustRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
if not root then return print("Error: Project root not found.") end
|
||||
|
||||
local cmd = { "cargo build" }
|
||||
local output = vim.fn.system(table.concat(cmd))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "cargo run" })
|
||||
end
|
||||
end
|
||||
},
|
||||
python = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("PythonPip", function() self:install_dependency() end, {})
|
||||
vim.api.nvim_create_user_command("PythonRun", function() self:run() end, {})
|
||||
for key, command in pairs(opts.keybinds) do
|
||||
if command == "PythonRun" then
|
||||
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
||||
end
|
||||
if command == "PythonPip" then
|
||||
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
local root = utils.get_project_root()
|
||||
if root then
|
||||
local venv_path = root .. "/venv/bin/activate"
|
||||
if vim.fn.filereadable(venv_path) == 1 then
|
||||
vim.env.VIRTUAL_ENV = venv_path
|
||||
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
end,
|
||||
install_dependency = function()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or pip_module == "" then return print("Pip canceled") end
|
||||
utils.terminal({ "pip install " .. pip_module })
|
||||
end)
|
||||
end,
|
||||
run = function()
|
||||
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
end
|
||||
},
|
||||
lua = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("LuaRun", function() self:run() end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local init_lua_path = utils.get_project_root() ..
|
||||
"/lua/" .. utils.get_project_name() .. "/init.lua"
|
||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||
utils.terminal({ "lua " .. init_lua_path })
|
||||
end
|
||||
end
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,371 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function extras(guard, file_type, file_name)
|
||||
if not file_name then return print("Header file creation canceled") end
|
||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||
local content = string.format([[
|
||||
#ifndef %s
|
||||
#define %s
|
||||
|
||||
// Add code here
|
||||
|
||||
#endif
|
||||
]], guard_macro, guard_macro)
|
||||
utils.write_file({ utils.get_project_root(), "include", file_name .. file_type }, content)
|
||||
end
|
||||
|
||||
M.projects = {
|
||||
javascript = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root, "p")
|
||||
utils.write_file({ full_project_root, "main.js" }, [[
|
||||
console.log("Hello World!");
|
||||
]])
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.js")
|
||||
end
|
||||
},
|
||||
lua = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
|
||||
utils.write_file({ full_project_root, "lua", project_name, "init.lua" }, [[
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
]])
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua")
|
||||
end
|
||||
},
|
||||
java = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
||||
local content = [[
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
]]
|
||||
local gitignore = {
|
||||
"build/"
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
utils.write_file({ full_project_root, "src", "Main.java" }, content)
|
||||
end
|
||||
},
|
||||
python = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
utils.write_file({ full_project_root, "main.py" }, [[
|
||||
def main():
|
||||
print("Hello, World!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]])
|
||||
utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
utils.write_file({ full_project_root, "setup.py" }, string.format([[
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="%s",
|
||||
version="0.1.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
]], project_name))
|
||||
local gitignore = {
|
||||
"venv/"
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
local venv_path = full_project_root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
print("Virtual environment activated for " .. project_name)
|
||||
end
|
||||
},
|
||||
c = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(
|
||||
full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file({ full_project_root, ".clang-format" }, [[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]])
|
||||
utils.write_file({ full_project_root, "src/main.c" }, [[
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, ".clang-tidy" }, string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]]))
|
||||
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(include)
|
||||
project(%s LANGUAGES C)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]], project_name, project_name, project_name))
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root))
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||
end
|
||||
},
|
||||
cpp = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file({ full_project_root, ".clang-format" }, [[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, "src/main.cpp" }, [[
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World\n";
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, ".clang-tidy" }, string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]]))
|
||||
|
||||
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(%s LANGUAGES CXX)
|
||||
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]], project_name, project_name))
|
||||
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root))
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||
end
|
||||
},
|
||||
rust = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.system("cargo new " .. full_project_root)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.rs")
|
||||
end
|
||||
},
|
||||
html = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
if vim.fn.isdirectory(full_project_root) == 0 then
|
||||
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
|
||||
end
|
||||
local main_html_content = [[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]]
|
||||
utils.write_file({ full_project_root, "index.html" }, main_html_content)
|
||||
end
|
||||
},
|
||||
}
|
||||
|
||||
M.files = {
|
||||
lua = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "lua", utils.get_project_name(), file_name .. ".lua" }, "")
|
||||
end
|
||||
},
|
||||
java = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".java" }, string.format([[
|
||||
public class %s {
|
||||
// New File
|
||||
}
|
||||
]], file_name))
|
||||
end
|
||||
},
|
||||
python = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "include", file_name .. ".py" }, "")
|
||||
end
|
||||
},
|
||||
c = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".c" }, "")
|
||||
end
|
||||
|
||||
},
|
||||
cpp = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".cpp" }, "")
|
||||
end
|
||||
},
|
||||
rust = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".rs" }, "")
|
||||
end
|
||||
},
|
||||
html = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ ".", file_name .. ".html" }, string.format([[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]]))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
M.extras = {
|
||||
run = function(lang, file_name)
|
||||
if lang == "c" then
|
||||
extras("_H", ".h", file_name)
|
||||
print("Successful creation of " .. file_name .. ".h")
|
||||
elseif lang == "cpp" then
|
||||
extras("_HPP", ".hpp", file_name)
|
||||
print("Successful creation of " .. file_name .. ".hpp")
|
||||
else
|
||||
print("Extras language is not found: enter cpp or c")
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,189 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@param path string
|
||||
---@return table
|
||||
local function get_entries(path)
|
||||
local result = {}
|
||||
local handle = vim.uv.fs_scandir(path)
|
||||
if not handle then return result end
|
||||
while true do
|
||||
local name, type = vim.uv.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
table.insert(result, {
|
||||
name = name .. (type == "directory" and "/" or ""),
|
||||
type = type,
|
||||
full_path = path .. "/" .. name,
|
||||
})
|
||||
end
|
||||
table.sort(result, function(a, b)
|
||||
if a.type == "directory" and b.type ~= "directory" then return true end
|
||||
if b.type == "directory" and a.type ~= "directory" then return false end
|
||||
return a.name < b.name
|
||||
end)
|
||||
return result
|
||||
end
|
||||
|
||||
---@param project_root string
|
||||
function M.manager(project_root)
|
||||
local templates = require("Polydev.templates")
|
||||
local width, height = math.floor(vim.o.columns * 0.40), math.floor(vim.o.lines * 0.4)
|
||||
local row, col = math.floor((vim.o.lines - height) / 3), math.floor((vim.o.columns - width) / 2)
|
||||
local content_row = row + 2
|
||||
local content_height = height - 3
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
local current_view = {}
|
||||
|
||||
local content_buf = vim.api.nvim_create_buf(false, true)
|
||||
local content_win = vim.api.nvim_open_win(content_buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = content_height,
|
||||
row = content_row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
local function close_all_windows()
|
||||
if vim.api.nvim_win_is_valid(content_win) then
|
||||
pcall(vim.api.nvim_win_close, content_win, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function update_screen()
|
||||
local root = vim.fn.expand(project_root)
|
||||
if vim.fn.isdirectory(root) == 0 then
|
||||
vim.fn.mkdir(root, "p")
|
||||
end
|
||||
local entries = get_entries(cwd)
|
||||
if not cwd:find(root, 1, true) then
|
||||
cwd = root
|
||||
entries = get_entries(cwd)
|
||||
end
|
||||
if cwd ~= root then
|
||||
table.insert(entries, 1, {
|
||||
name = "../",
|
||||
type = "directory",
|
||||
full_path = vim.fn.fnamemodify(cwd, ":h"),
|
||||
is_up = true,
|
||||
})
|
||||
end
|
||||
current_view = vim.deepcopy(entries)
|
||||
|
||||
local lines = {}
|
||||
if #current_view == 0 then
|
||||
table.insert(lines, "No projects found in " .. cwd)
|
||||
table.insert(lines, "Press d to create a project, or a to add a folder.")
|
||||
else
|
||||
for i, item in ipairs(current_view) do
|
||||
table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
|
||||
end
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(content_buf, 0, -1, false, lines)
|
||||
end
|
||||
|
||||
local function get_selected_entry()
|
||||
local win = content_win
|
||||
if not win or not vim.api.nvim_win_is_valid(win) then return end
|
||||
local row = vim.api.nvim_win_get_cursor(win)[1]
|
||||
return current_view[row], row
|
||||
end
|
||||
|
||||
---@param type string
|
||||
---@param callback fun(lang: string, name: string)
|
||||
local function get_inputs(type, callback)
|
||||
vim.ui.input({ prompt = "Enter language for new " .. type .. ": " }, function(lang)
|
||||
if not lang or lang == "" then return end
|
||||
vim.ui.input({ prompt = "Enter " .. type .. " name: " }, function(name)
|
||||
if not name or name == "" then return end
|
||||
callback(lang, name)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
update_screen()
|
||||
|
||||
local buf = content_buf
|
||||
vim.keymap.set("n", "<ESC>", function()
|
||||
if vim.api.nvim_win_is_valid(content_win) then
|
||||
pcall(vim.api.nvim_win_close, content_win, true)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "a", function ()
|
||||
vim.ui.input({ prompt = "New folder name: " }, function(input)
|
||||
if input then
|
||||
vim.fn.mkdir(cwd .. "/" .. input, "p")
|
||||
update_screen()
|
||||
end
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "R", function ()
|
||||
local entry = get_selected_entry()
|
||||
if entry ~= nil and not entry.is_up then
|
||||
vim.ui.input({ prompt = "Rename: ", default = entry.name }, function(input)
|
||||
if input then
|
||||
local new_path = cwd .. "/" .. input
|
||||
vim.fn.rename(entry.full_path, new_path)
|
||||
update_screen()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "D", function()
|
||||
local entry = get_selected_entry()
|
||||
if entry ~= nil and not entry.is_up then
|
||||
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
|
||||
if input == "y" or input == "Y" then
|
||||
vim.fn.delete(entry.full_path, "rf")
|
||||
update_screen()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "%", function()
|
||||
get_inputs("file", function(lang, name)
|
||||
local file = templates.files[lang]
|
||||
if not file or not file.run then
|
||||
return print("Error: No file creation method for " .. lang)
|
||||
end
|
||||
close_all_windows()
|
||||
file.run(name)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "x", function()
|
||||
get_inputs("aux file", function(lang, name)
|
||||
close_all_windows()
|
||||
templates.extras.run(lang, name)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "d", function()
|
||||
get_inputs("project", function(lang, name)
|
||||
local project = templates.projects[lang]
|
||||
if not project or not project.run then
|
||||
return print("Error: No project creation method for " .. lang)
|
||||
end
|
||||
local opts = require("Polydev.configs").get(lang)
|
||||
local run_root = opts.project_root or project_root
|
||||
close_all_windows()
|
||||
project.run(name, run_root)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "<CR>", function()
|
||||
local entry = get_selected_entry()
|
||||
if not entry then return end
|
||||
|
||||
if entry.type == "file" then
|
||||
close_all_windows()
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||
elseif entry.type == "directory" then
|
||||
cwd = entry.full_path
|
||||
vim.cmd("cd " .. cwd)
|
||||
update_screen()
|
||||
else
|
||||
print("Error")
|
||||
end
|
||||
end, { buffer = buf })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,114 +0,0 @@
|
||||
local M = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||
end
|
||||
|
||||
function M.exists(path)
|
||||
return (io.open(path, "r") ~= nil)
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.get_project_root()
|
||||
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
||||
|
||||
local dir = vim.fn.system(plugin_dir .. "/bash_scripts/walkup.sh"):gsub("%s+$", "")
|
||||
return dir
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.get_project_name()
|
||||
return vim.fn.fnamemodify(M.get_project_root(), ":t")
|
||||
end
|
||||
|
||||
---@param path_segments table
|
||||
---@param content string
|
||||
function M.write_file(path_segments, content)
|
||||
local path = table.concat(path_segments, "/")
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
file:write(content)
|
||||
file:close()
|
||||
vim.cmd("edit " .. path)
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param gitignore_lines table
|
||||
function M.init_git(path, gitignore_lines)
|
||||
vim.fn.mkdir(path, "p")
|
||||
vim.fn.system({ "git", "-C", path, "init" })
|
||||
|
||||
if gitignore_lines and #gitignore_lines > 0 then
|
||||
local contents = table.concat(gitignore_lines, "\n")
|
||||
M.write_file({ path, ".gitignore" }, contents)
|
||||
end
|
||||
end
|
||||
|
||||
---@param cmd table
|
||||
---@return integer, integer?
|
||||
function M.terminal(cmd)
|
||||
if M.opts.mode == "floating" then
|
||||
local opts = require("Polydev.presets").getPresets(M.opts.win.anchor)
|
||||
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
local width, height, row, col
|
||||
|
||||
if opts ~= nil then
|
||||
width = math.max(1, math.floor(ui.width * 0.9) - opts.left - opts.right)
|
||||
height = math.max(1, math.floor(ui.height * 0.9) - opts.top - opts.bottom)
|
||||
row = math.floor((ui.height - height) / 2) + opts.top
|
||||
col = math.floor((ui.width - width) / 2) + opts.left
|
||||
end
|
||||
if opts == nil then
|
||||
width = math.max(1, math.floor(ui.width * 0.9))
|
||||
height = math.max(1, math.floor(ui.height * 0.9))
|
||||
row = math.floor((ui.height - height) / 2)
|
||||
col = math.floor((ui.width - width) / 2)
|
||||
end
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = M.opts.border.enabled and M.opts.border.type,
|
||||
})
|
||||
vim.api.nvim_set_option_value("winhighlight", "Normal:PolydevNormal,FloatBorder:PolydevBorder",
|
||||
{ win = win })
|
||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||
return buf, win
|
||||
end
|
||||
if M.opts.mode == "split" then
|
||||
if M.opts.win.type == "vertical" then
|
||||
if M.opts.win.anchor == "right" then
|
||||
vim.cmd("set splitright")
|
||||
end
|
||||
end
|
||||
if M.opts.win.type == "horizontal" then
|
||||
if M.opts.win.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
end
|
||||
|
||||
if M.opts.win.type == "vertical" then
|
||||
vim.cmd(M.opts.win.size .. " vsplit")
|
||||
end
|
||||
if M.opts.win.type == "horizontal" then
|
||||
vim.cmd(M.opts.win.size .. " split")
|
||||
end
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
|
||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||
return buf, win
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,52 @@
|
||||
local M = {}
|
||||
|
||||
M.create_project = function(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input(
|
||||
{ prompt = "Project language (e.g. python): ", completion = "filetype" },
|
||||
function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or vim.trim(ft) == "" then
|
||||
return
|
||||
end
|
||||
local ok, actions = pcall(require, "vern.actions." .. ft)
|
||||
local configs = require("vern.configs." .. ft)
|
||||
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
if ok and actions and type(actions.create_project) == "function" then
|
||||
actions.create_project(args)
|
||||
else
|
||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
||||
title = "Vern Project",
|
||||
})
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input({
|
||||
prompt = "File language (e.g. python): ",
|
||||
completion = "filetype",
|
||||
}, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or vim.trim(ft) == "" then
|
||||
return
|
||||
end
|
||||
local ok, actions = pcall(require, "vern.actions." .. ft)
|
||||
local configs = require("vern.configs." .. ft)
|
||||
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
if ok and actions and type(actions.create_file) == "function" then
|
||||
actions.create_file(args)
|
||||
else
|
||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
||||
title = "Vern File",
|
||||
})
|
||||
vim.notify("Error: " .. actions, vim.log.levels.ERROR, {
|
||||
title = "Vern File",
|
||||
})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,85 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
|
||||
local join, get = vim.fs.joinpath, vim.tbl_get
|
||||
function M.create_project(opts)
|
||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local configs = require("vern.configs")
|
||||
local pconfigs = require("vern.configs.python")
|
||||
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs, opts or {})
|
||||
local ctx = { project_name = pname }
|
||||
local py = cfg.python
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), py.root, pname)
|
||||
vim.fn.mkdir(join(root, utils.fmt(py.source_root, ctx)), "p")
|
||||
|
||||
local tmpl = get(py, "templates", "project") or {}
|
||||
local function dump(k, alt, id)
|
||||
local path = join(root, utils.fmt(get(tmpl, k, "target") or alt, ctx))
|
||||
utils.dump(path, templates.fetch("python", id, pname))
|
||||
return path
|
||||
end
|
||||
|
||||
local bin = dump("bin", "src/{project_name}/main.py", "main")
|
||||
dump("pkg", "src/{project_name}/__init__.py", "__init__")
|
||||
dump("spec", "pyproject.toml", "pyproject")
|
||||
utils.init_git(root, "python")
|
||||
|
||||
local venv_path = root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
function M.create_file(opts)
|
||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||
fname = fname and vim.trim(fname)
|
||||
if not fname or fname == "" then
|
||||
return
|
||||
end
|
||||
local root = get(opts, "python", "templates", "file", "module").target or {}
|
||||
local context = { project_name = utils.proj_name(), name = fname }
|
||||
local path = join(utils.proj_root(), utils.fmt(root, context))
|
||||
utils.dump(path, templates.fetch("python", "module", fname))
|
||||
vim.cmd.edit(vim.fn.expand(path))
|
||||
end)
|
||||
end
|
||||
|
||||
--- Goal is to add providers for uv and venv so its available to more users
|
||||
---@param opts? table Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local exe = opts.python.templates.project.bin.target or "src/%s/main.py"
|
||||
local full_path = vim.fn.expand(root, utils.fmt(exe, { project_name = pname }))
|
||||
utils.term({ "python3 " .. full_path }, opts.terminal or {})
|
||||
end
|
||||
|
||||
---@param cmd_args? table Takes a table for the runtime
|
||||
function M.pip_install(opts, cmd_args)
|
||||
local args = cmd_args and cmd_args.args and vim.trim(cmd_args.args) or ""
|
||||
if args ~= "" then
|
||||
utils.term({ "pip install " .. args }, opts.terminal or {})
|
||||
return
|
||||
end
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or vim.trim(pip_module) == "" then
|
||||
vim.notify("Pip Cancelled", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
utils.term({ "pip install " .. vim.trim(pip_module) }, opts.terminal or {})
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,44 @@
|
||||
local actions = require("vern.actions.python")
|
||||
local config = require("vern.configs.python")
|
||||
|
||||
return function(bufnr, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
|
||||
if type(actions.run) == "function" then
|
||||
actions.run(opts)
|
||||
end
|
||||
end, { desc = "Run python project" })
|
||||
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args)
|
||||
if actions.pip_install then
|
||||
actions.pip_install(opts, cmd_args)
|
||||
end
|
||||
end, { nargs = "*", desc = "Install python packages" })
|
||||
|
||||
for key, def in pairs(opts.python.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local root = require("vern.utils").proj_root()
|
||||
if not root then
|
||||
return
|
||||
end
|
||||
local venv_dir = nil
|
||||
if vim.uv.fs_stat(root .. "/venv/bin/python") then
|
||||
venv_dir = root .. "/venv"
|
||||
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
|
||||
venv_dir = root .. "/.venv"
|
||||
end
|
||||
if venv_dir then
|
||||
vim.env.VIRTUAL_ENV = venv_dir
|
||||
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,38 @@
|
||||
local actions = require("vern.actions")
|
||||
return {
|
||||
workspace_root = "~/personal/Projects",
|
||||
keybinds = {
|
||||
["<leader>pc"] = {
|
||||
desc = "Creates a new project",
|
||||
action = actions.create_project,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
desc = "Creates a new project file",
|
||||
action = actions.create_file,
|
||||
},
|
||||
},
|
||||
terminal = {
|
||||
mode = {
|
||||
type = "split", --- can be split or float
|
||||
win = {
|
||||
float = {
|
||||
padding = {
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
},
|
||||
border = {
|
||||
enabled = true,
|
||||
type = vim.o.winborder,
|
||||
},
|
||||
},
|
||||
split = {
|
||||
type = "horizontal", --- can be vertical or horizontal
|
||||
anchor = "bottom", --- can be right or bottom
|
||||
size = "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
return {
|
||||
python = {
|
||||
root = "Python",
|
||||
source_root = "src/{project_name}",
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes python code",
|
||||
action = require("vern.actions.python").run,
|
||||
},
|
||||
["<leader>pb"] = {
|
||||
desc = "Asks for what python package to install",
|
||||
action = require("vern.actions.python").pip_install,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
["bin"] = {
|
||||
target = "src/{project_name}/main.py",
|
||||
},
|
||||
["pkg"] = {
|
||||
target = "src/{project_name}/__init__.py",
|
||||
},
|
||||
["spec"] = {
|
||||
target = "pyproject.toml",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
["module"] = {
|
||||
target = "src/{project_name}/{name}.py",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
["gitignore"] = {
|
||||
template = "vern.templates.extras.gitignore", --- needs to call the function in file
|
||||
target = ".gitignore",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
local M = {}
|
||||
|
||||
function M.test()
|
||||
vim.ui.input({ prompt = "Test: ", default = "" }, function(input)
|
||||
print(input)
|
||||
end)
|
||||
end
|
||||
|
||||
local configs = require("vern.configs")
|
||||
local actions = require("vern.actions")
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(user_opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||
|
||||
--- Bind global keybinds
|
||||
for key, def in pairs(M.opts.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(M.opts)
|
||||
end, {
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
--- Load project cmdline commands
|
||||
vim.api.nvim_create_user_command("VernCreateProject", function()
|
||||
if actions.create_project then
|
||||
actions.create_project(M.opts)
|
||||
end
|
||||
end, { nargs = "*", desc = "Create a new project" })
|
||||
|
||||
vim.api.nvim_create_user_command("VernCreateFile", function()
|
||||
if type(actions.create_file) == "function" then
|
||||
actions.create_file(M.opts)
|
||||
end
|
||||
end, { nargs = "*", desc = "Creates a new file for project" })
|
||||
|
||||
--- Create group and attach based on ft
|
||||
local group =
|
||||
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = group,
|
||||
pattern = "*",
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
local ok, attach = pcall(require, "vern.attach." .. ft)
|
||||
if ok and type(attach) == "function" then
|
||||
attach(args.buf, M.opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,285 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local configs = require("Polydev.configs")
|
||||
local M = {}
|
||||
|
||||
local loaded_languages = {}
|
||||
|
||||
---@param lang string
|
||||
---@param opts? table
|
||||
---@return boolean
|
||||
function M.load_language_module(lang, opts)
|
||||
if loaded_languages[lang] then
|
||||
return true
|
||||
end
|
||||
|
||||
local ok, mod = pcall(require, "Polydev.languages")
|
||||
if not ok or type(mod.languages) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
local lang_mod = mod.languages[lang]
|
||||
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then
|
||||
return false
|
||||
end
|
||||
|
||||
lang_mod:setup(opts and opts[lang] or {})
|
||||
loaded_languages[lang] = lang_mod
|
||||
return true
|
||||
end
|
||||
|
||||
M.languages = {
|
||||
javascript = {
|
||||
setup = function(self, user_opts)
|
||||
local opts =
|
||||
vim.tbl_deep_extend("force", {}, configs.get("javascript"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavascriptRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavascriptRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("node " .. root .. "/main.js")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "node " .. root .. "/main.js" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavaRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
c = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
end
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CppRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
end
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
setup = function(user_opts)
|
||||
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("RustRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
if not root then
|
||||
return print("Error: Project root not found.")
|
||||
end
|
||||
|
||||
local cmd = { "cargo build" }
|
||||
local output = vim.fn.system(table.concat(cmd))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "cargo run" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("PythonPip", function()
|
||||
self:install_dependency()
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("PythonRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, command in pairs(opts.keybinds) do
|
||||
if command == "PythonRun" then
|
||||
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
||||
end
|
||||
if command == "PythonPip" then
|
||||
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
local root = utils.get_project_root()
|
||||
if root then
|
||||
local venv_path = root .. "/venv/bin/activate"
|
||||
if vim.fn.filereadable(venv_path) == 1 then
|
||||
vim.env.VIRTUAL_ENV = venv_path
|
||||
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
end,
|
||||
install_dependency = function()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or pip_module == "" then
|
||||
return print("Pip canceled")
|
||||
end
|
||||
utils.terminal({ "pip install " .. pip_module })
|
||||
end)
|
||||
end,
|
||||
run = function()
|
||||
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
end,
|
||||
},
|
||||
lua = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("LuaRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local init_lua_path = utils.get_project_root()
|
||||
.. "/lua/"
|
||||
.. utils.get_project_name()
|
||||
.. "/init.lua"
|
||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||
utils.terminal({ "lua " .. init_lua_path })
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,3 @@
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,487 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function extras(guard, file_type, file_name)
|
||||
if not file_name then
|
||||
return print("Header file creation canceled")
|
||||
end
|
||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||
local content = string.format(
|
||||
[[
|
||||
#ifndef %s
|
||||
#define %s
|
||||
|
||||
// Add code here
|
||||
|
||||
#endif
|
||||
]],
|
||||
guard_macro,
|
||||
guard_macro
|
||||
)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "include", file_name .. file_type },
|
||||
content
|
||||
)
|
||||
end
|
||||
|
||||
M.projects = {
|
||||
javascript = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.js" },
|
||||
[[
|
||||
console.log("Hello World!");
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.js")
|
||||
end,
|
||||
},
|
||||
lua = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "lua", project_name, "init.lua" },
|
||||
[[
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd(
|
||||
"edit "
|
||||
.. full_project_root
|
||||
.. "/lua/"
|
||||
.. project_name
|
||||
.. "/init.lua"
|
||||
)
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
for _, path in ipairs({ "/src", "/build" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
local content = [[
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
]]
|
||||
local gitignore = {
|
||||
"build/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
utils.write_file({ full_project_root, "src", "Main.java" }, content)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.py" },
|
||||
[[
|
||||
def main():
|
||||
print("Hello, World!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]]
|
||||
)
|
||||
utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
utils.write_file(
|
||||
{ full_project_root, "setup.py" },
|
||||
string.format(
|
||||
[[
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="%s",
|
||||
version="0.1.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
]],
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = {
|
||||
"venv/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
local venv_path = full_project_root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
print("Virtual environment activated for " .. project_name)
|
||||
end,
|
||||
},
|
||||
c = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]]
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.c" },
|
||||
[[
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(include)
|
||||
project(%s LANGUAGES C)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.cpp" },
|
||||
[[
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World\n";
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(%s LANGUAGES CXX)
|
||||
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.system("cargo new " .. full_project_root)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.rs")
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
if vim.fn.isdirectory(full_project_root) == 0 then
|
||||
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
|
||||
end
|
||||
local main_html_content = [[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]]
|
||||
utils.write_file(
|
||||
{ full_project_root, "index.html" },
|
||||
main_html_content
|
||||
)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
M.files = {
|
||||
lua = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{
|
||||
utils.get_project_root(),
|
||||
"lua",
|
||||
utils.get_project_name(),
|
||||
file_name .. ".lua",
|
||||
},
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".java" },
|
||||
string.format(
|
||||
[[
|
||||
public class %s {
|
||||
// New File
|
||||
}
|
||||
]],
|
||||
file_name
|
||||
)
|
||||
)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "include", file_name .. ".py" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
c = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".c" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".cpp" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".rs" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ ".", file_name .. ".html" },
|
||||
string.format([[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]])
|
||||
)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
M.extras = {
|
||||
run = function(lang, file_name)
|
||||
if lang == "c" then
|
||||
extras("_H", ".h", file_name)
|
||||
print("Successful creation of " .. file_name .. ".h")
|
||||
elseif lang == "cpp" then
|
||||
extras("_HPP", ".hpp", file_name)
|
||||
print("Successful creation of " .. file_name .. ".hpp")
|
||||
else
|
||||
print("Extras language is not found: enter cpp or c")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,31 @@
|
||||
local M = {}
|
||||
|
||||
---@param lang string
|
||||
M.template = function(lang)
|
||||
local base = [=[
|
||||
.DS_Store
|
||||
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
.env
|
||||
.env.*
|
||||
|
||||
]=]
|
||||
local lang_block = {
|
||||
python = vim.trim([=[
|
||||
__pycache__/
|
||||
build/
|
||||
dist/
|
||||
.venv/
|
||||
env/
|
||||
venv/
|
||||
.pytest_cache/
|
||||
]=]),
|
||||
}
|
||||
|
||||
local extra = (lang and lang_block[lang]) or ""
|
||||
return base .. extra
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,19 @@
|
||||
local M = {}
|
||||
|
||||
---@param ft string Filetype of template
|
||||
---@param template string Template in language table
|
||||
---@param name string A string to replace temp values in template
|
||||
---@return string
|
||||
function M.fetch(ft, template, name)
|
||||
ft, template, name = ft or "", template or "", name or ""
|
||||
if ft == "" or template == "" or name == "" then
|
||||
return ""
|
||||
end
|
||||
local ok, mod = pcall(require, "vern.templates." .. ft)
|
||||
if ok and type(mod) == "table" then
|
||||
return (string.gsub(mod[template], "%%s", name))
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,59 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.py
|
||||
Target: src/{project_name}/main.py
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
def main() -> None:
|
||||
print("Hello from %s!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: INIT (Package Anchor)
|
||||
File: __init__.py
|
||||
Target: src/{project_name}/__init__.py
|
||||
===================================================================== --]]
|
||||
__init__ = vim.trim([=[
|
||||
# %s init
|
||||
|
||||
__all__: list[str] = []
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: PYPROJECT (Spec / Build Manifest)
|
||||
File: pyproject.toml
|
||||
Target: pyproject.toml
|
||||
===================================================================== --]]
|
||||
pyproject = vim.trim([=[
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "%s"
|
||||
version = "0.1.0"
|
||||
description = "Project %s"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = []
|
||||
|
||||
[project.scripts]
|
||||
%s = "%s.main:main"
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MODULE (Standalone File)
|
||||
File: {name}.py
|
||||
Target: src/{project_name}/{name}.py
|
||||
===================================================================== --]]
|
||||
module = vim.trim([=[
|
||||
"""
|
||||
Module: %s
|
||||
"""
|
||||
]=]) .. "\n",
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
local M = {}
|
||||
|
||||
---@param path string
|
||||
---@param content string
|
||||
function M.dump(path, content)
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
file:write(content)
|
||||
file:close()
|
||||
end
|
||||
|
||||
function M.fmt(str, ctx)
|
||||
return (str:gsub("{([^}]+)}", ctx))
|
||||
end
|
||||
|
||||
---@param bufnr? integer Default is 0 (current buffer)
|
||||
function M.proj_root(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
local root_markers = {
|
||||
".git",
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"Makefile",
|
||||
"CMakeLists",
|
||||
"Cargo.toml",
|
||||
}
|
||||
return vim.fs.root(bufnr, root_markers) or vim.uv.cwd()
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.proj_name()
|
||||
return vim.fn.fnamemodify(M.proj_root(), ":t")
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param ft string
|
||||
function M.init_git(path, ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or ft == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local gitignore = require("vern.templates.extras.gitignore").template(ft)
|
||||
vim.fn.system({ "git", "-C", path, "init" })
|
||||
M.dump(vim.fs.joinpath(path, ".gitignore"), gitignore)
|
||||
end
|
||||
|
||||
---@param cmd table
|
||||
---@return integer, integer?
|
||||
function M.term(cmd, opts)
|
||||
opts = opts or {}
|
||||
local buf, win
|
||||
if opts.mode.type == "float" then
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
|
||||
local dim = {
|
||||
width = math.max(
|
||||
1,
|
||||
math.floor(ui.width * 0.9)
|
||||
- opts.mode.win.float.padding.left
|
||||
- opts.mode.win.float.padding.right
|
||||
),
|
||||
height = math.max(
|
||||
1,
|
||||
math.floor(ui.height * 0.9)
|
||||
- opts.mode.win.float.padding.top
|
||||
- opts.mode.win.float.padding.bottom
|
||||
),
|
||||
}
|
||||
|
||||
local pos = {
|
||||
row = math.floor(
|
||||
(ui.height - (vim.o.laststatus == 3 and 1 or 0) - vim.o.cmdheight - dim.height) / 2
|
||||
),
|
||||
col = math.floor((ui.width - dim.width) / 2),
|
||||
}
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = dim.width,
|
||||
height = dim.height,
|
||||
row = pos.row,
|
||||
col = pos.col,
|
||||
style = "minimal",
|
||||
border = opts.mode.win.float.border.enabled and opts.mode.win.float.border.type or nil,
|
||||
})
|
||||
end
|
||||
if opts.mode.type == "split" then
|
||||
if opts.mode.win.split.type == "vertical" then
|
||||
if opts.mode.win.split.anchor == "right" then
|
||||
vim.cmd("set splitright")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
||||
end
|
||||
if opts.mode.win.split.type == "horizontal" then
|
||||
if opts.mode.win.split.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " split")
|
||||
end
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_get_current_win()
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
end
|
||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<ESC>",
|
||||
"i<C-\\><C-n>:q<CR>",
|
||||
{ noremap = true, silent = true }
|
||||
)
|
||||
return buf, win
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
-- function M.exists(path)
|
||||
-- return (io.open(path, "r") ~= nil)
|
||||
-- end
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
-- return M
|
||||
@@ -1 +0,0 @@
|
||||
require("Polydev").setup()
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
# stylua.toml
|
||||
|
||||
# How many characters per line before wrapping
|
||||
column_width = 100
|
||||
|
||||
# Indentation style: "Tabs" or "Spaces"
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 4
|
||||
|
||||
# Quote styling: "AutoPreferDouble", "AutoPreferSingle", "ForceDouble", "ForceSingle"
|
||||
quote_style = "AutoPreferDouble"
|
||||
|
||||
# Call parentheses: "Always", "NoSingleString", "None", "Input"
|
||||
# "None" removes parens when a single string/table literal is passed: fn "arg" / fn { ... }
|
||||
# "Always" keeps them strictly standard: fn("arg") / fn({ ... })
|
||||
call_parentheses = "Always"
|
||||
|
||||
# Sorting and formatting behavior
|
||||
collapse_simple_statement = "Never"
|
||||
Reference in New Issue
Block a user