Update to documentation, update with merging run and build commands, cleaned up and organized the project manager
This commit is contained in:
+2
-2
@@ -23,7 +23,7 @@ Modern development often involves juggling multiple languages. Setting up simila
|
|||||||
- 🌐 **Language Support**: Define custom settings per language including `project_root`, `keybinds`, and `build_attributes`.
|
- 🌐 **Language Support**: Define custom settings per language including `project_root`, `keybinds`, and `build_attributes`.
|
||||||
- 🪟 **Floating Terminals**: Run builds and executions in a Neovim floating terminal.
|
- 🪟 **Floating Terminals**: Run builds and executions in a Neovim floating terminal.
|
||||||
- 🧱 **Scaffolding**: Automatically create the appropriate directory and file layout for new projects.
|
- 🧱 **Scaffolding**: Automatically create the appropriate directory and file layout for new projects.
|
||||||
- 🎹 **Keybind Mapping**: Rebind keys to execute project-specific commands like `Build`, `Run`, or `Test`.
|
- 🎹 **Keybind Mapping**: Rebind keys to execute project-specific commands like `Run`, or `Test`.
|
||||||
- 🔌 **Pluggable**: Designed to easily integrate with other tools or extend with your own commands and language presets.
|
- 🔌 **Pluggable**: Designed to easily integrate with other tools or extend with your own commands and language presets.
|
||||||
|
|
||||||
## 👥 Target Audience
|
## 👥 Target Audience
|
||||||
@@ -46,7 +46,7 @@ Say you're a developer who works with Rust, Lua, and Python. Instead of remember
|
|||||||
|
|
||||||
1. 🏗 Sets up your directory based on language conventions.
|
1. 🏗 Sets up your directory based on language conventions.
|
||||||
2. 📄 Generates boilerplate files.
|
2. 📄 Generates boilerplate files.
|
||||||
3. 🎛 Maps `<leader>pr` to `Run`, `<leader>pb` to `Build`, and so on.
|
3. 🎛 Maps `<leader>pr` to `Run`, `<leader>po` to `Open Polydev Project Manager`, and so on.
|
||||||
4. 🖥 Opens a floating terminal to show your output.
|
4. 🖥 Opens a floating terminal to show your output.
|
||||||
|
|
||||||
## 🏷 Versioning
|
## 🏷 Versioning
|
||||||
|
|||||||
@@ -3,22 +3,25 @@
|
|||||||
Polydev can be installed using any plugin manager of your choice—or even manually. Below are some examples for popular managers to get you started.
|
Polydev can be installed using any plugin manager of your choice—or even manually. Below are some examples for popular managers to get you started.
|
||||||
|
|
||||||
> ⚠️ **Disclaimer**: The `opts` and configuration values shown below are simply examples. You can customize them based on your preferences or even omit them entirely if not needed.
|
> ⚠️ **Disclaimer**: The `opts` and configuration values shown below are simply examples. You can customize them based on your preferences or even omit them entirely if not needed.
|
||||||
|
|
||||||
> 💡 **Heads up!** Many language presets in Polydev require a file named `<project_name>.polydev` in your project root. If it's missing, Polydev will let you know (loudly 😅).
|
> 💡 **Heads up!** Many language presets in Polydev require a file named `<project_name>.polydev` in your project root. If it's missing, Polydev will let you know (loudly 😅).
|
||||||
|
|
||||||
|
> **Note**: Languages that require to build just need to be run, building is builtin to the run command
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🛌 Lazy.nvim
|
## 🛌 Lazy.nvim
|
||||||
|
|
||||||
This is the **recommended** way if you're using [Lazy.nvim](https://github.com/folke/lazy.nvim):
|
> This is the **recommended** way if you're using [Lazy.nvim](https://github.com/folke/lazy.nvim):
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
{
|
return {
|
||||||
"DarthMooMancer/Polydev",
|
"DarthMooMancer/Polydev",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim",
|
||||||
"nvim-lua/plenary.nvim"
|
"nvim-lua/plenary.nvim"
|
||||||
},
|
},
|
||||||
opts = {
|
opts = { -- Below are just example values
|
||||||
lua = {
|
lua = {
|
||||||
project_root = "~/Projects/Lua",
|
project_root = "~/Projects/Lua",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
@@ -33,8 +36,6 @@ This is the **recommended** way if you're using [Lazy.nvim](https://github.com/f
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> ✅ Keep the `opts` key! It’s the modern way of setting up plugins in Lazy.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🧸 Mini.deps
|
## 🧸 Mini.deps
|
||||||
@@ -54,7 +55,6 @@ require("Polydev").setup({
|
|||||||
rust = {
|
rust = {
|
||||||
project_root = "~/Projects/Rust",
|
project_root = "~/Projects/Rust",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "RustBuild",
|
|
||||||
["<leader>pr"] = "RustRun",
|
["<leader>pr"] = "RustRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -111,7 +111,6 @@ require("Polydev").setup({
|
|||||||
c = {
|
c = {
|
||||||
project_root = "~/Projects/C",
|
project_root = "~/Projects/C",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "CBuild",
|
|
||||||
["<leader>pr"] = "CRun",
|
["<leader>pr"] = "CRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ You can customize keybinds for your C projects with Polydev.
|
|||||||
|
|
||||||
| Keybind | Action |
|
| Keybind | Action |
|
||||||
|---------------------|--------------------------------------------------|
|
|---------------------|--------------------------------------------------|
|
||||||
| `<leader>pb` | Build all C files in the `src` directory |
|
|
||||||
| `<leader>pr` | Run `<Project_name>` in your build directory |
|
| `<leader>pr` | Run `<Project_name>` in your build directory |
|
||||||
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
|
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ You can customize keybinds for your C projects with Polydev.
|
|||||||
```lua
|
```lua
|
||||||
require("Polydev").c.setup({
|
require("Polydev").c.setup({
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "CBuild", -- Build all C files in the src directory
|
|
||||||
["<leader>pr"] = "CRun", -- Run <Project_name> in your build directory
|
["<leader>pr"] = "CRun", -- Run <Project_name> in your build directory
|
||||||
["<leader>nh"] = "NewCHeaderFile" -- Create a new header file in the current project’s src folder
|
["<leader>nh"] = "NewCHeaderFile" -- Create a new header file in the current project’s src folder
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ You can customize keybinds for your C projects with Polydev.
|
|||||||
|
|
||||||
| Keybind | Action |
|
| Keybind | Action |
|
||||||
|---------------------|--------------------------------------------------|
|
|---------------------|--------------------------------------------------|
|
||||||
| `<leader>pb` | Build all C files in the `src` directory |
|
|
||||||
| `<leader>pr` | Run `<Project_name>` in your build directory |
|
| `<leader>pr` | Run `<Project_name>` in your build directory |
|
||||||
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
|
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ You can customize keybinds for your C projects with Polydev.
|
|||||||
```lua
|
```lua
|
||||||
require("Polydev").c.setup({
|
require("Polydev").c.setup({
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "CppBuild", -- Build all C files in the src directory
|
|
||||||
["<leader>pr"] = "CppRun", -- Run <Project_name> in your build directory
|
["<leader>pr"] = "CppRun", -- Run <Project_name> in your build directory
|
||||||
["<leader>nh"] = "NewCppHeaderFile" -- Create a new header file in the current project’s src folder
|
["<leader>nh"] = "NewCppHeaderFile" -- Create a new header file in the current project’s src folder
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ You can customize the keybinds for your Java projects in Polydev.
|
|||||||
|
|
||||||
| Keybind | Action |
|
| Keybind | Action |
|
||||||
|---------------------|-----------------------------------------------------|
|
|---------------------|-----------------------------------------------------|
|
||||||
| `<leader>pb` | Build all Java files in the `src` directory |
|
|
||||||
| `<leader>pr` | Run `Main.java` from the `out` folder in your project |
|
| `<leader>pr` | Run `Main.java` from the `out` folder in your project |
|
||||||
| `<leader>nf` | Create a new Java file in the `src` folder |
|
| `<leader>nf` | Create a new Java file in the `src` folder |
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ You can customize the keybinds for your Java projects in Polydev.
|
|||||||
-- These are defaults, so no need to copy them
|
-- These are defaults, so no need to copy them
|
||||||
require("Polydev").java.setup({
|
require("Polydev").java.setup({
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "JavaBuild", -- Build all Java files in the src directory
|
|
||||||
["<leader>pr"] = "JavaRun", -- Run Main.java in the out folder
|
["<leader>pr"] = "JavaRun", -- Run Main.java in the out folder
|
||||||
["<leader>nf"] = "NewJavaFile" -- Create a new Java file in the src folder
|
["<leader>nf"] = "NewJavaFile" -- Create a new Java file in the src folder
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-22
@@ -1,7 +1,19 @@
|
|||||||
# Setup and Customizing Polydev
|
# Setup and Customizing Polydev
|
||||||
|
|
||||||
## Project Manager
|
## Project Manager
|
||||||
Follows the netrw keybinds and allows for project management all in one spot
|
> Note: The project manager closely follows the netrw keybinds and allows for project management all in one spot
|
||||||
|
|
||||||
|
| Binding | Description |
|
||||||
|
|------------------|-----------------|
|
||||||
|
| **Enter** | `Open file / Enter directory` |
|
||||||
|
| **../** | `Go to parent directory` |
|
||||||
|
| **/** | `Filter (fuzzy search)` |
|
||||||
|
| **a** | `Create new folder` |
|
||||||
|
| **%** | `Create new file` |
|
||||||
|
| **d** | `Create new project` |
|
||||||
|
| **R** | `Rename file/folder` |
|
||||||
|
| **D** | `Delete file/folder` |
|
||||||
|
| **q** | `Quit popup` |
|
||||||
|
|
||||||
## 🔧 Project Name Customization
|
## 🔧 Project Name Customization
|
||||||
You can easily customize the default directory for your project! The project can be created from any directory, and Polydev will automatically create the required project root directory for you.
|
You can easily customize the default directory for your project! The project can be created from any directory, and Polydev will automatically create the required project root directory for you.
|
||||||
@@ -37,8 +49,8 @@ Polydev allows you to easily manage keybinds, providing a uniform way to interac
|
|||||||
### Keybind Categories
|
### Keybind Categories
|
||||||
| Keybind Type | Description |
|
| Keybind Type | Description |
|
||||||
|-------------------|--------------------------------------------------|
|
|-------------------|--------------------------------------------------|
|
||||||
| **Universal** | Cannot be changed through specific language settings (e.g., `<leader>nf` for a new file). |
|
| **Universal** | Cannot be changed through specific language settings (e.g., `<leader>po` for project manager). |
|
||||||
| **Per-language** | Can be customized per language (e.g., `<leader>pb` for language build). |
|
| **Per-language** | Can be customized per language (e.g., `<leader>pr` for language run). |
|
||||||
|
|
||||||
### LazyVim Example
|
### LazyVim Example
|
||||||
|
|
||||||
@@ -47,10 +59,9 @@ return {
|
|||||||
...
|
...
|
||||||
opts = {
|
opts = {
|
||||||
<language> = {
|
<language> = {
|
||||||
["<leader>pb"] = "languageBuild", -- Per-language
|
|
||||||
["<leader>pr"] = "languageRun", -- Per-language
|
["<leader>pr"] = "languageRun", -- Per-language
|
||||||
["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
|
["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
|
||||||
["<leader>po"] = "OpenSmartTable", -- Universal
|
["<leader>po"] = "PolydevManager", -- Universal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
@@ -62,10 +73,9 @@ return {
|
|||||||
```lua
|
```lua
|
||||||
require("Polydev").language.setup({
|
require("Polydev").language.setup({
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pb"] = "languageBuild", -- Per-language
|
|
||||||
["<leader>pr"] = "languageRun", -- Per-language
|
["<leader>pr"] = "languageRun", -- Per-language
|
||||||
["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
|
["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
|
||||||
["<leader>po"] = "OpenSmartTable", -- Universal
|
["<leader>po"] = "PolydevManager", -- Universal
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@@ -78,11 +88,7 @@ You can further tweak the terminal settings to suit your preferences! These opti
|
|||||||
### Available Terminal Settings
|
### Available Terminal Settings
|
||||||
| Setting | Default Value | Description |
|
| Setting | Default Value | Description |
|
||||||
|------------------|-----------------|---------------------------------------------------------|
|
|------------------|-----------------|---------------------------------------------------------|
|
||||||
| **presets** | `centered` | Presets for where the terminal is placed in the buffer |
|
| **presets** | `center` | Presets for where the terminal is placed in the buffer |
|
||||||
| **right_padding** | `0` | Padding for the right width of the terminal. |
|
|
||||||
| **left_padding** | `0` | Padding for the left width of the terminal. |
|
|
||||||
| **top_padding** | `0` | Padding for the top height of the terminal. |
|
|
||||||
| **bottom_padding**| `0` | Padding for the bottom height of the terminal. |
|
|
||||||
| **border** | `true` | Adds a rounded border to the window. |
|
| **border** | `true` | Adds a rounded border to the window. |
|
||||||
| **number** | `true` | Displays line numbers in the terminal. |
|
| **number** | `true` | Displays line numbers in the terminal. |
|
||||||
| **relativenumber**| `true` | Displays relative numbers based on cursor position. |
|
| **relativenumber**| `true` | Displays relative numbers based on cursor position. |
|
||||||
@@ -106,11 +112,7 @@ return {
|
|||||||
...
|
...
|
||||||
opts = {
|
opts = {
|
||||||
terminal = {
|
terminal = {
|
||||||
presets = "centered"
|
presets = "center"
|
||||||
right_padding = 0,
|
|
||||||
bottom_padding = 0,
|
|
||||||
left_padding = 0,
|
|
||||||
top_padding = 0,
|
|
||||||
border = true,
|
border = true,
|
||||||
number = true,
|
number = true,
|
||||||
relativenumber = true,
|
relativenumber = true,
|
||||||
@@ -126,11 +128,7 @@ return {
|
|||||||
```lua
|
```lua
|
||||||
require("Polydev").setup({
|
require("Polydev").setup({
|
||||||
terminal = {
|
terminal = {
|
||||||
presets = "centered"
|
presets = "center"
|
||||||
right_padding = 0,
|
|
||||||
bottom_padding = 0,
|
|
||||||
left_padding = 0,
|
|
||||||
top_padding = 0,
|
|
||||||
border = true,
|
border = true,
|
||||||
number = true,
|
number = true,
|
||||||
relativenumber = true,
|
relativenumber = true,
|
||||||
|
|||||||
+11
-2
@@ -8,7 +8,7 @@ local M = {}
|
|||||||
---@field project_root? string
|
---@field project_root? string
|
||||||
---@field keybinds? KeybindConfigs -- ? makes fields optional
|
---@field keybinds? KeybindConfigs -- ? makes fields optional
|
||||||
---@field build_attributes? string
|
---@field build_attributes? string
|
||||||
---
|
|
||||||
---@class TerminalConfigs
|
---@class TerminalConfigs
|
||||||
---@field presets string
|
---@field presets string
|
||||||
---@field right_padding integer
|
---@field right_padding integer
|
||||||
@@ -18,8 +18,12 @@ local M = {}
|
|||||||
---@field border boolean
|
---@field border boolean
|
||||||
---@field number boolean
|
---@field number boolean
|
||||||
---@field relativenumber boolean
|
---@field relativenumber boolean
|
||||||
---
|
|
||||||
|
---@class GlobalsConfigs
|
||||||
|
---@field keybinds KeybindConfigs
|
||||||
|
|
||||||
---@class Defaults
|
---@class Defaults
|
||||||
|
---@field globals GlobalsConfigs
|
||||||
---@field html LanguageConfigs
|
---@field html LanguageConfigs
|
||||||
---@field rust LanguageConfigs
|
---@field rust LanguageConfigs
|
||||||
---@field java LanguageConfigs
|
---@field java LanguageConfigs
|
||||||
@@ -31,6 +35,11 @@ local M = {}
|
|||||||
|
|
||||||
---@type Defaults
|
---@type Defaults
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
|
globals = {
|
||||||
|
keybinds = {
|
||||||
|
["<leader>po"] = "PolydevManager",
|
||||||
|
}
|
||||||
|
},
|
||||||
html = {
|
html = {
|
||||||
project_root = "~/Projects/Html",
|
project_root = "~/Projects/Html",
|
||||||
},
|
},
|
||||||
|
|||||||
+168
-23
@@ -2,6 +2,7 @@ local config = require("Polydev.configs")
|
|||||||
local utils = require("Polydev.utils")
|
local utils = require("Polydev.utils")
|
||||||
local templates = require("Polydev.templates")
|
local templates = require("Polydev.templates")
|
||||||
local Popup = require("nui.popup")
|
local Popup = require("nui.popup")
|
||||||
|
local Layout = require("nui.layout")
|
||||||
local event = require("nui.utils.autocmd").event
|
local event = require("nui.utils.autocmd").event
|
||||||
local Path = require("plenary.path")
|
local Path = require("plenary.path")
|
||||||
|
|
||||||
@@ -86,27 +87,123 @@ local function open_filtered_table()
|
|||||||
local entries = get_entries(cwd)
|
local entries = get_entries(cwd)
|
||||||
local current_view = vim.deepcopy(entries)
|
local current_view = vim.deepcopy(entries)
|
||||||
|
|
||||||
local popup = Popup({
|
local popup, search, preview, keybinds = Popup({
|
||||||
enter = true,
|
enter = true,
|
||||||
focusable = true,
|
focusable = true,
|
||||||
border = {
|
border = {
|
||||||
style = "rounded",
|
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
|
||||||
text = { top = " Project Manager ", top_align = "center" },
|
text = { top = " Project Manager ", top_align = "center" },
|
||||||
highlight = "Normal",
|
highlight = "Normal",
|
||||||
},
|
},
|
||||||
position = "50%",
|
position = "50%",
|
||||||
size = { width = 60, height = 14 },
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
}), Popup({
|
||||||
|
enter = false,
|
||||||
|
focusable = true,
|
||||||
|
border = {
|
||||||
|
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
|
||||||
|
text = { top = " Search ", top_align = "center" },
|
||||||
|
highlight = "Normal",
|
||||||
|
},
|
||||||
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
}), Popup({
|
||||||
|
enter = false,
|
||||||
|
focusable = false,
|
||||||
|
border = {
|
||||||
|
style = "rounded",
|
||||||
|
text = { top = " Preview ", top_align = "center" },
|
||||||
|
highlight = "Normal",
|
||||||
|
},
|
||||||
|
position = "50%",
|
||||||
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
}), Popup({
|
||||||
|
enter = false,
|
||||||
|
focusable = false,
|
||||||
|
border = {
|
||||||
|
style = "rounded",
|
||||||
|
text = { top = " Keybinds ", top_align = "center" },
|
||||||
|
highlight = "Normal",
|
||||||
|
},
|
||||||
|
position = "50%",
|
||||||
buf_options = { modifiable = true, readonly = false },
|
buf_options = { modifiable = true, readonly = false },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local layout = Layout({
|
||||||
|
position = "50%",
|
||||||
|
size = { width = "70%", height = "70%" },
|
||||||
|
},
|
||||||
|
Layout.Box({
|
||||||
|
Layout.Box(search, { size = "10%" }),
|
||||||
|
Layout.Box({
|
||||||
|
Layout.Box({
|
||||||
|
Layout.Box(popup, { size = "55%" }),
|
||||||
|
Layout.Box(keybinds, {size = "45%" }),
|
||||||
|
}, { dir = "col", size = "50%" }),
|
||||||
|
Layout.Box(preview, { size = "50%" }),
|
||||||
|
}, { dir = "row", size = "90%" }),
|
||||||
|
}, { dir = "col" })
|
||||||
|
)
|
||||||
|
layout:mount()
|
||||||
|
|
||||||
local function get_selected_entry()
|
local function get_selected_entry()
|
||||||
local row = vim.api.nvim_win_get_cursor(0)[1] - 1
|
local row = vim.api.nvim_win_get_cursor(popup.winid)[1] - 1
|
||||||
return current_view[row], row
|
return current_view[row], row
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function update_preview()
|
||||||
|
if not preview.bufnr then return end
|
||||||
|
vim.api.nvim_buf_set_lines(preview.bufnr, 0, -1, false, {}) -- Clear
|
||||||
|
|
||||||
|
local entry = get_selected_entry()
|
||||||
|
if not entry then return end
|
||||||
|
|
||||||
|
if entry.type == "file" or entry.type == "project" then
|
||||||
|
-- Preview file contents (first 100 lines)
|
||||||
|
local lines = {}
|
||||||
|
local fd = io.open(entry.full_path, "r")
|
||||||
|
if fd then
|
||||||
|
for i = 1, 100 do
|
||||||
|
local line = fd:read("*line")
|
||||||
|
if not line then break end
|
||||||
|
table.insert(lines, line)
|
||||||
|
end
|
||||||
|
fd:close()
|
||||||
|
else
|
||||||
|
table.insert(lines, "[Failed to read file]")
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_lines(preview.bufnr, 0, -1, false, lines)
|
||||||
|
elseif entry.type == "directory" then
|
||||||
|
-- List contents of directory
|
||||||
|
local contents = get_entries(entry.full_path)
|
||||||
|
local lines = {}
|
||||||
|
for _, item in ipairs(contents) do
|
||||||
|
table.insert(lines, string.format("- %s", item.name))
|
||||||
|
end
|
||||||
|
if #lines == 0 then
|
||||||
|
table.insert(lines, "[Empty folder]")
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_lines(preview.bufnr, 0, -1, false, lines)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||||
|
buffer = popup.bufnr,
|
||||||
|
callback = function()
|
||||||
|
vim.schedule(update_preview)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
local function refresh()
|
local function refresh()
|
||||||
entries = get_entries(cwd)
|
entries = get_entries(cwd)
|
||||||
local root = vim.fn.expand("~/Projects")
|
local root = vim.fn.expand("~/Projects")
|
||||||
|
|
||||||
|
-- If we're not in the Projects folder, redirect to Projects
|
||||||
|
if not cwd:find(root, 1, true) then
|
||||||
|
cwd = root
|
||||||
|
entries = get_entries(cwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Only add ".." if we're inside Projects and not at the root
|
||||||
if cwd ~= root then
|
if cwd ~= root then
|
||||||
table.insert(entries, 1, {
|
table.insert(entries, 1, {
|
||||||
name = "../",
|
name = "../",
|
||||||
@@ -122,14 +219,12 @@ local function open_filtered_table()
|
|||||||
if not popup.bufnr then return end
|
if not popup.bufnr then return end
|
||||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, {})
|
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, {})
|
||||||
for i, item in ipairs(current_view) do
|
for i, item in ipairs(current_view) do
|
||||||
local line = string.format("%-3d | %-30s | %-6s", i, item.name, item.type)
|
local line = string.format("%-2d | %-27s | %-6s", i, item.name, item.type)
|
||||||
vim.api.nvim_buf_set_lines(popup.bufnr, -1, -1, false, { line })
|
vim.api.nvim_buf_set_lines(popup.bufnr, -1, -1, false, { line })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add key mappings legend
|
-- Add key mappings legend
|
||||||
local hints = {
|
local hints = {
|
||||||
"",
|
|
||||||
"Keybinds:",
|
|
||||||
" <CR> : Open file / Enter directory",
|
" <CR> : Open file / Enter directory",
|
||||||
" <BS> : Go to parent directory",
|
" <BS> : Go to parent directory",
|
||||||
" / : Filter (fuzzy search)",
|
" / : Filter (fuzzy search)",
|
||||||
@@ -141,21 +236,42 @@ local function open_filtered_table()
|
|||||||
" q : Quit popup",
|
" q : Quit popup",
|
||||||
}
|
}
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(popup.bufnr, -1, -1, false, hints)
|
if not keybinds.bufnr then return end
|
||||||
|
vim.api.nvim_buf_set_lines(keybinds.bufnr, 0, -1, false, {})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_lines(keybinds.bufnr, -1, -1, false, hints)
|
||||||
|
update_preview()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function prompt_filter()
|
local function prompt_filter()
|
||||||
vim.ui.input({ prompt = "Search: " }, function(input)
|
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
|
||||||
if input then
|
vim.api.nvim_buf_set_option(search.bufnr, "modifiable", true)
|
||||||
|
if search.winid and vim.api.nvim_win_is_valid(search.winid) then
|
||||||
|
vim.api.nvim_set_current_win(search.winid)
|
||||||
|
end
|
||||||
|
vim.cmd("startinsert")
|
||||||
|
|
||||||
|
vim.keymap.set("i", "<CR>", function()
|
||||||
|
local input = vim.api.nvim_buf_get_lines(search.bufnr, 0, 1, false)[1]
|
||||||
|
if input and input ~= "" then
|
||||||
current_view = fuzzy_filter(entries, input)
|
current_view = fuzzy_filter(entries, input)
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
end)
|
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
|
||||||
|
vim.api.nvim_set_current_win(popup.winid)
|
||||||
|
vim.cmd("stopinsert") -- exit insert mode
|
||||||
|
end, { buffer = search.bufnr, noremap = true })
|
||||||
|
|
||||||
|
vim.keymap.set("i", "<Esc>", function()
|
||||||
|
vim.api.nvim_set_current_win(popup.winid)
|
||||||
|
vim.cmd("stopinsert") -- ensure we are in normal mode
|
||||||
|
end, { buffer = search.bufnr, noremap = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
popup:map("n", "/", function() vim.schedule(prompt_filter) end)
|
||||||
|
|
||||||
-- Mappings
|
-- Mappings
|
||||||
popup:map("n", "q", function() popup:unmount() end)
|
popup:map("n", "q", function() popup:unmount() end)
|
||||||
popup:map("n", "/", prompt_filter)
|
|
||||||
|
|
||||||
-- Creates a new folder
|
-- Creates a new folder
|
||||||
popup:map("n", "a", function()
|
popup:map("n", "a", function()
|
||||||
@@ -190,9 +306,10 @@ local function open_filtered_table()
|
|||||||
if M.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
|
if M.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
|
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
|
||||||
if not file_name or file_name == "" then return print("File creation canceled.") end
|
if not file_name or file_name == "" then return print("File creation canceled.") end
|
||||||
templates.files[lang].run(file_name)
|
popup:unmount()
|
||||||
refresh()
|
vim.schedule(function()
|
||||||
render()
|
templates.files[lang].run(file_name)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
print("Error: No File creation method for " .. lang)
|
print("Error: No File creation method for " .. lang)
|
||||||
@@ -207,10 +324,11 @@ local function open_filtered_table()
|
|||||||
if not lang or lang == "" then return print("Project creation canceled.") end
|
if not lang or lang == "" then return print("Project creation canceled.") end
|
||||||
opts = vim.tbl_deep_extend("force", {}, config.get(lang), opts or {})
|
opts = vim.tbl_deep_extend("force", {}, config.get(lang), opts or {})
|
||||||
if M.load_language_module(lang) and templates.projects[lang] and templates.projects[lang].run then
|
if M.load_language_module(lang) and templates.projects[lang] and templates.projects[lang].run then
|
||||||
templates.create_project(lang, opts.project_root)
|
popup:unmount()
|
||||||
vim.cmd("cd " .. templates.dir .. "/src")
|
vim.schedule(function()
|
||||||
refresh()
|
templates.create_project(lang, opts.project_root)
|
||||||
render()
|
end)
|
||||||
|
|
||||||
else
|
else
|
||||||
print("Error: No project creation method for " .. lang)
|
print("Error: No project creation method for " .. lang)
|
||||||
end
|
end
|
||||||
@@ -242,7 +360,10 @@ local function open_filtered_table()
|
|||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
if entry and entry.type == "file" then
|
if entry and entry.type == "file" then
|
||||||
vim.cmd("edit " .. entry.name)
|
popup:unmount()
|
||||||
|
vim.schedule(function()
|
||||||
|
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -255,13 +376,37 @@ local function open_filtered_table()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
popup:on(event.BufLeave, function() popup:unmount() end)
|
popup:on(event.BufLeave, function()
|
||||||
|
vim.defer_fn(function()
|
||||||
|
if not (popup.winid and vim.api.nvim_win_is_valid(popup.winid)) and
|
||||||
|
not (search.winid and vim.api.nvim_win_is_valid(search.winid)) then
|
||||||
|
popup:unmount()
|
||||||
|
end
|
||||||
|
end, 50)
|
||||||
|
end)
|
||||||
|
|
||||||
popup:mount()
|
popup:mount()
|
||||||
refresh()
|
refresh()
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@type table
|
||||||
|
M.keybinds = {}
|
||||||
|
|
||||||
|
local function setupKeybinds(opts)
|
||||||
|
M.opts = {}
|
||||||
|
|
||||||
|
M.opts = vim.tbl_deep_extend("force", {}, config.get("globals"), opts or {})
|
||||||
|
for key, command in pairs(M.opts.keybinds) do
|
||||||
|
M.keybinds[command] = key
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("PolydevProjectManagerOpen", open_filtered_table, {})
|
||||||
|
if M.keybinds.PolydevManager then
|
||||||
|
vim.keymap.set("n", M.keybinds.PolydevManager, ":PolydevProjectManagerOpen<CR>", { silent = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param opts table
|
---@param opts table
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
@@ -272,8 +417,8 @@ function M.setup(opts)
|
|||||||
config.user_config[lang] = vim.tbl_deep_extend("force", default, user_opts)
|
config.user_config[lang] = vim.tbl_deep_extend("force", default, user_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("OpenSmartTable", open_filtered_table, {})
|
setupKeybinds(opts)
|
||||||
vim.keymap.set("n", "<leader>po", ":OpenSmartTable<CR>", { silent = true })
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|||||||
+15
-17
@@ -11,12 +11,8 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
||||||
vim.api.nvim_create_user_command("CBuild", M.build, {})
|
|
||||||
vim.api.nvim_create_user_command("CRun", M.run, {})
|
vim.api.nvim_create_user_command("CRun", M.run, {})
|
||||||
|
|
||||||
if M.keybinds.CBuild then
|
|
||||||
vim.keymap.set("n", M.keybinds.CBuild, ":CBuild<CR>", { silent = true })
|
|
||||||
end
|
|
||||||
if M.keybinds.CRun then
|
if M.keybinds.CRun then
|
||||||
vim.keymap.set("n", M.keybinds.CRun, ":CRun<CR>", { silent = true })
|
vim.keymap.set("n", M.keybinds.CRun, ":CRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
@@ -56,27 +52,29 @@ function M.get_project_root()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.build()
|
function M.run()
|
||||||
local root = M.get_project_root()
|
local root = M.get_project_root()
|
||||||
if not root then return print("Error: Project root not found.") end
|
if not root then return print("Error: Project root not found.") end
|
||||||
local build_dir = root .. "/build"
|
local build_dir = root .. "/build"
|
||||||
|
|
||||||
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||||
local term_buf = utils.open_float_terminal(cmd)
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
local success = vim.v.shell_error == 0
|
local success = vim.v.shell_error == 0
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, vim.list_extend({ success and "Compilation successful!" or "Error during compilation:" }, vim.split(output, "\n", { trimempty = true })))
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.run()
|
if not success then
|
||||||
local root = M.get_project_root()
|
local term_buf = utils.open_float_terminal(cmd)
|
||||||
if not root then return print("Error: Project root not found.") end
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||||
local build_dir = root .. "/build"
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||||
if #files == 0 then return print("Error: No .polydev file found in build directory.") end
|
)
|
||||||
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. files[1]:match("([^/]+)%.polydev$"))
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||||
|
end
|
||||||
|
|
||||||
|
if success then
|
||||||
|
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
||||||
|
if #files == 0 then return print("Error: No .polydev file found in build directory.") end
|
||||||
|
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. files[1]:match("([^/]+)%.polydev$"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -11,12 +11,8 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("NewCppHeaderFile", M.create_new_header_file, {})
|
vim.api.nvim_create_user_command("NewCppHeaderFile", M.create_new_header_file, {})
|
||||||
vim.api.nvim_create_user_command("CppBuild", M.build, {})
|
|
||||||
vim.api.nvim_create_user_command("CppRun", M.run, {})
|
vim.api.nvim_create_user_command("CppRun", M.run, {})
|
||||||
|
|
||||||
if M.keybinds.CppBuild then
|
|
||||||
vim.keymap.set("n", M.keybinds.CppBuild, ":CppBuild<CR>", { silent = true })
|
|
||||||
end
|
|
||||||
if M.keybinds.CppRun then
|
if M.keybinds.CppRun then
|
||||||
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
|
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
@@ -25,6 +21,16 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.create_new_header_file()
|
function M.create_new_header_file()
|
||||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||||
if not header_name then return print("Header file creation canceled.") end
|
if not header_name then return print("Header file creation canceled.") end
|
||||||
@@ -46,37 +52,29 @@ void example_function();
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root()
|
function M.run()
|
||||||
local dir = vim.fn.expand("%:p:h")
|
|
||||||
while dir ~= "/" do
|
|
||||||
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
|
||||||
return dir
|
|
||||||
end
|
|
||||||
dir = vim.fn.fnamemodify(dir, ":h")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.build()
|
|
||||||
local root = M.get_project_root()
|
local root = M.get_project_root()
|
||||||
if not root then return print("Error: Project root not found.") end
|
if not root then return print("Error: Project root not found.") end
|
||||||
local build_dir = root .. "/build"
|
local build_dir = root .. "/build"
|
||||||
|
|
||||||
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||||
local term_buf = utils.open_float_terminal(cmd)
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
local success = vim.v.shell_error == 0
|
local success = vim.v.shell_error == 0
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, vim.list_extend({ success and "Compilation successful!" or "Error during compilation:" }, vim.split(output, "\n", { trimempty = true })))
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.run()
|
if not success then
|
||||||
local root = M.get_project_root()
|
local term_buf = utils.open_float_terminal(cmd)
|
||||||
if not root then return print("Error: Project root not found.") end
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||||
local build_dir = root .. "/build"
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||||
if #files == 0 then return print("Error: No .polydev file found in build directory.") end
|
)
|
||||||
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. files[1]:match("([^/]+)%.polydev$"))
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||||
|
end
|
||||||
|
|
||||||
|
if success then
|
||||||
|
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
||||||
|
if #files == 0 then return print("Error: No .polydev file found in build directory.") end
|
||||||
|
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. files[1]:match("([^/]+)%.polydev$"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -10,28 +10,27 @@ function M.setup(opts)
|
|||||||
M.keybinds[command] = key
|
M.keybinds[command] = key
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("JavaBuild", M.build, {})
|
|
||||||
vim.api.nvim_create_user_command("JavaRun", M.run, {})
|
vim.api.nvim_create_user_command("JavaRun", M.run, {})
|
||||||
|
|
||||||
if M.keybinds.JavaRun then
|
if M.keybinds.JavaRun then
|
||||||
vim.keymap.set("n", M.keybinds.JavaRun, ":JavaRun<CR>", { silent = true })
|
vim.keymap.set("n", M.keybinds.JavaRun, ":JavaRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
if M.keybinds.JavaBuild then
|
|
||||||
vim.keymap.set("n", M.keybinds.JavaBuild, ":JavaBuild<CR>", { silent = true })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.build()
|
function M.run()
|
||||||
local project_root = vim.fn.expand("%:p:h"):match("(.*)/src")
|
local project_root = vim.fn.expand("%:p:h"):match("(.*)/src")
|
||||||
if not project_root then return print("Error: Could not detect project root directory.") end
|
if not project_root then return print("Error: Must be inside the 'src' directory.") end
|
||||||
local out_dir = project_root .. "/build"
|
local out_dir = project_root .. "/build"
|
||||||
|
|
||||||
vim.fn.mkdir(out_dir, "p")
|
if not utils.is_dir(out_dir) then
|
||||||
|
vim.fn.mkdir(out_dir, "p")
|
||||||
|
end
|
||||||
|
|
||||||
local compile_command = string.format("javac -d %s %s/*.java", out_dir, project_root .. "/src")
|
local compile_command = string.format("javac -d %s %s/*.java", out_dir, project_root .. "/src")
|
||||||
local compile_status = vim.fn.system(compile_command)
|
local compile_status = vim.fn.system(compile_command)
|
||||||
|
|
||||||
if vim.v.shell_error == 0 then
|
if vim.v.shell_error == 0 then
|
||||||
print("Compilation successful!")
|
utils.open_float_terminal("java -cp " .. project_root .. "/build" .. " Main")
|
||||||
else
|
else
|
||||||
print("Error during compilation. Opening terminal for details...")
|
print("Error during compilation. Opening terminal for details...")
|
||||||
local term_buf = utils.open_float_terminal(compile_command)
|
local term_buf = utils.open_float_terminal(compile_command)
|
||||||
@@ -41,10 +40,4 @@ function M.build()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run()
|
|
||||||
local project_root = vim.fn.expand("%:p:h"):match("(.*)/src")
|
|
||||||
if not project_root then return print("Error: Must be inside the 'src' directory.") end
|
|
||||||
utils.open_float_terminal("java -cp " .. project_root .. "/build" .. " Main")
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -10,18 +10,14 @@ function M.setup(opts)
|
|||||||
M.keybinds[command] = key
|
M.keybinds[command] = key
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("RustBuild", M.build, {})
|
|
||||||
vim.api.nvim_create_user_command("RustRun", M.run, {})
|
vim.api.nvim_create_user_command("RustRun", M.run, {})
|
||||||
|
|
||||||
if M.keybinds.RustRun then
|
if M.keybinds.RustRun then
|
||||||
vim.keymap.set("n", M.keybinds.RustRun, ":RustRun<CR>", { silent = true })
|
vim.keymap.set("n", M.keybinds.RustRun, ":RustRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
if M.keybinds.RustBuild then
|
|
||||||
vim.keymap.set("n", M.keybinds.RustBuild, ":RustBuild<CR>", { silent = true })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root()
|
local function get_project_root()
|
||||||
local dir = vim.fn.expand("%:p:h")
|
local dir = vim.fn.expand("%:p:h")
|
||||||
while dir ~= "/" do
|
while dir ~= "/" do
|
||||||
if vim.fn.isdirectory(dir .. "/src") == 1 then
|
if vim.fn.isdirectory(dir .. "/src") == 1 then
|
||||||
@@ -31,22 +27,26 @@ function M.get_project_root()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.build()
|
function M.run()
|
||||||
local root = M.get_project_root()
|
local root = get_project_root()
|
||||||
if not root then return print("Error: Project root not found.") end
|
if not root then return print("Error: Project root not found.") end
|
||||||
|
|
||||||
local cmd = "cargo build"
|
local cmd = "cargo build"
|
||||||
local term_buf = utils.open_float_terminal(cmd)
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
local success = vim.v.shell_error == 0
|
local success = vim.v.shell_error == 0
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, vim.list_extend({ success and "Compilation successful!" or "Error during compilation:" }, vim.split(output, "\n", { trimempty = true })))
|
|
||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.run()
|
if not success then
|
||||||
local root = M.get_project_root()
|
local term_buf = utils.open_float_terminal(cmd)
|
||||||
if not root then return print("Error: Project root not found.") end
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||||
utils.open_float_terminal("cargo run")
|
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_buf_set_option(term_buf, "modifiable", false)
|
||||||
|
end
|
||||||
|
|
||||||
|
if success then
|
||||||
|
utils.open_float_terminal("cargo run")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ function M.setup(opts)
|
|||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@return boolean
|
||||||
|
function M.is_dir(path)
|
||||||
|
local stat = vim.loop.fs_stat(path)
|
||||||
|
return stat and stat.type == "directory"
|
||||||
|
end
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param content string
|
---@param content string
|
||||||
function M.write_file(path, content)
|
function M.write_file(path, content)
|
||||||
|
|||||||
Reference in New Issue
Block a user