16 Commits
22 changed files with 1002 additions and 589 deletions
+1
View File
@@ -1,2 +1,3 @@
*.polydev *.polydev
LICENSE LICENSE
Lua_Annotation_CheatSheet/
+49 -19
View File
@@ -1,26 +1,56 @@
# Polydev # **Polydev** 🌐
A multi-lingual plugin that adds some nice features to neovim for managing, creating, building and runnning projects all within neovim.
!!! Documentation is over at [Polydev Documentation](https://darthmoomancer.github.io/Polydev/) **Polydev** is a powerful multi-lingual plugin for Neovim that streamlines project management, file creation, building, and running code—all within your favorite terminal editor. Whether you're coding in Java, Python, Lua, Rust, or more, Polydev brings seamless integration and enhanced productivity right to your fingertips.
![Python-polydev-720](https://github.com/user-attachments/assets/b66f46e8-901f-4a46-8e79-10b688d4109a) ![Polydev-c](https://github.com/user-attachments/assets/365dd673-6b1f-4ccc-ac1f-c5131d055fd9)
---
### Quick Features ## 🚀 **Quick Features**
The ability to -
* Create new projects
* Create new files
* Build those files
* Run those files
* Builtin terminal for running code
* And More!
### Currently Supported (And working) Languages Polydev helps you work smarter, not harder. With this plugin, you can:
* Java
* Python
* C/C++
* Lua
## Questions and Contributing - 📂 **Create New Projects**: Start fresh with ease.
- 📝 **Generate New Files**: Add files to your projects with just a few keystrokes.
- ⚙️ **Build Your Files**: Compile and prepare your projects directly within Neovim.
- 🎮 **Run Your Code**: Execute your code and see results without leaving your terminal.
- 🖥️ **Built-in Terminal**: A terminal integrated directly into Neovim for running commands, scripts, or code.
- 🌱 **More to Come**: Ongoing development means new features and improvements are always on the horizon!
If you want to contribute, make a PR or issue and I will answer as soon as I see it. If there is a language that you want added for easier use, please voice it. If you have questions, just ask in issues or discussions and I will answer them. **Need more info?** Check out the full [Polydev Documentation](https://darthmoomancer.github.io/Polydev/) for setup instructions, configurations, and usage details.
---
## ✅ **Currently Supported (And Working) Languages**
Polydev supports a wide range of languages, providing a smooth development experience:
- **Java** ☕️
- **Python** 🐍
- **C/C++** 💻
- **Lua** 🐢
- **Rust** 🦀
- **HTML** 🌍
And more on the way! Stay tuned for future updates.
---
## 🔮 **Planned Features**
We're always working to make Polydev better. Here’s a sneak peek at some exciting plans:
- 🚀 **Rust Integration**: Leverage Rust to speed up certain aspects of the plugin for faster performance and better scalability.
---
## 🤝 **Questions and Contributing**
Got ideas? 💡 Have a feature you’d love to see or a language you want to see supported? Your contributions are always welcome! Here's how you can get involved:
- 🔧 **Contribute**: Open a Pull Request (PR) or create an issue with your suggestions or bug reports.
- 💬 **Ask Questions**: If you're stuck or have questions, drop them in the issues or discussions section, and I'll get back to you as soon as I can.
Your feedback and contributions are key to making Polydev even better! Thank you for being part of the journey. 🙏
---
-29
View File
@@ -1,29 +0,0 @@
### Lazy and Config
```lua
-- There is no need to copy this. This is an example and it consists of the defaults. This is a c example
return {
'DarthMooMancer/Polydev',
opts = {
c = {
build_attributes = "-DBUILD_SHARED_LIBS=OFF"
project_root = "~/Projects/C",
keybinds = {
["<Esc>"] = "CloseTerminal",
["<leader>pb"] = "CBuild",
["<leader>pr"] = "CRun",
["<leader>nh"] = "NewCHeaderFile",
},
terminal = {
right_padding = 0,
bottom_padding = 0,
left_padding = 0,
top_padding = 0,
border = true,
number = true,
relativenumber = true,
scroll = true,
},
}
}
}
```
+53 -10
View File
@@ -1,13 +1,56 @@
# Welcome to Polydev # 🚀 Welcome to Polydev
![Python-polydev-720](https://github.com/user-attachments/assets/08232673-01a4-4464-9e98-5a94227e98f9) Polydev is a highly customizable and extensible Neovim plugin aimed at streamlining project creation and management for multiple programming languages. It’s especially suited for developers who work across different languages and want a consistent workflow for initializing, building, and running projects.
---- ![Polydev-c](https://github.com/user-attachments/assets/365dd673-6b1f-4ccc-ac1f-c5131d055fd9)
### What is Polydev?
Polydev is a simple plugin that gives neovim some nice functions while being extremely extensible for developers. It automatically detects your language and enables the module for that language. It is a standalone plugin that has no dependencies aside from getting file types. Below are a few features that are currently implemented:
* Creating New Projects ## ❓ What is Polydev?
* Creating New Files
* Building Files Polydev is designed to be a centralized workspace tool that reduces repetitive tasks involved in setting up development environments. Whether you’re working on a Lua plugin, a Rust CLI tool, or a C++ project, Polydev helps you scaffold project directories, create boilerplate code, and define keybinds to streamline execution — all from within Neovim.
* Running Files
* Builtin Terminal ## 💡 Why Polydev?
Modern development often involves juggling multiple languages. Setting up similar environments repeatedly or manually running commands wastes time. Polydev solves this by providing:
- 📦 **Project templates per language**
- 🎯 **Custom keybindings for common actions**
- 💻 **Floating terminal support**
- 🗂 **Easy file creation and directory structure generation**
- 🔌 **Plugin-first architecture to expand functionality**
## 🔧 Core Features
- 🌐 **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.
- 🧱 **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`.
- 🔌 **Pluggable**: Designed to easily integrate with other tools or extend with your own commands and language presets.
## 👥 Target Audience
Polydev is perfect for:
- 🧑‍💻 Developers building across multiple languages
- 🔌 Plugin authors and power users of Neovim
- ⚡ Anyone who wants automated project bootstrapping
## 🎯 Goals
- 📏 **Consistency**: Provide a common interface for all your dev projects.
- 🧩 **Extensibility**: Let users add their own languages and tools.
- ✨ **Simplicity**: Reduce boilerplate and context switching.
## 🧪 Example Use Case
Say you're a developer who works with Rust, Lua, and Python. Instead of remembering build commands, directory structures, or manually creating a `main.rs` or `init.lua`, Polydev:
1. 🏗 Sets up your directory based on language conventions.
2. 📄 Generates boilerplate files.
3. 🎛 Maps `<leader>pr` to `Run`, `<leader>pb` to `Build`, and so on.
4. 🖥 Opens a floating terminal to show your output.
## 🏷 Versioning
Polydev uses GitHub tags and branches to manage plugin versions. Each version corresponds to a stable release that users can track.
---
+117 -22
View File
@@ -1,32 +1,127 @@
# Installation # 📦 Installation
!!! Polydev can be installed with any plugin installer or manually. These are just examples.
* Side note: A lot of the languages require a <project_name>.polydev file. If you dont have it in a language that needs it, it will error out and yell at you. 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.
## Lazyvim > ⚠️ **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 😅).
---
## 🛌 Lazy.nvim
This is the **recommended** way if you're using [Lazy.nvim](https://github.com/folke/lazy.nvim):
```lua ```lua
require { {
"DarthMooMancer/Polydev", "DarthMooMancer/Polydev",
config = function() opts = {
require("Polydev").setup() lua = {
--require("Polydev").language.setup({ project_root = "~/Projects/Lua",
-- configs keybinds = {
--}) ["<leader>pr"] = "LuaRun",
end },
},
terminal = {
border = true,
number = true,
},
},
} }
``` ```
## Mini.Deps > ✅ Keep the `opts` key! It’s the modern way of setting up plugins in Lazy.
------------
```lua
MiniDeps.add({
source = 'DarthMooMancer/Polydev',
})
require("Polydev").setup() ---
--require("Polydev").language.setup({
-- configs ## 🧸 Mini.deps
--})
For users of [mini.nvim](https://github.com/echasnovski/mini.nvim)'s dependency manager:
```lua
MiniDeps.add({ source = "DarthMooMancer/Polydev" })
require("Polydev").setup({
rust = {
project_root = "~/Projects/Rust",
keybinds = {
["<leader>pb"] = "RustBuild",
["<leader>pr"] = "RustRun",
},
},
terminal = {
border = true,
number = true,
},
})
```
---
## 📁 Packer.nvim
For fans of [Packer.nvim](https://github.com/wbthomason/packer.nvim):
```lua
use({
"DarthMooMancer/Polydev",
config = function()
require("Polydev").setup({
python = {
project_root = "~/Projects/Python",
keybinds = {
["<leader>pb"] = "PythonPip",
["<leader>pr"] = "PythonRun",
},
},
terminal = {
relativenumber = true,
},
})
end,
})
```
---
## 🔐 Vim-Plug (Classic)
Even if you're still using [vim-plug](https://github.com/junegunn/vim-plug), you’re covered:
```vim
Plug 'DarthMooMancer/Polydev'
lua << EOF
require("Polydev").setup({
c = {
project_root = "~/Projects/C",
keybinds = {
["<leader>pb"] = "CBuild",
["<leader>pr"] = "CRun",
},
},
terminal = {
number = true,
},
})
EOF
```
---
## 🛠 Manual Install
Clone the repo into your `~/.config/nvim/lua` or any runtime path:
```bash
git clone https://github.com/DarthMooMancer/Polydev ~/.config/nvim/lua/Polydev
```
Then in your config:
```lua
require("Polydev").setup({
terminal = {
border = true,
},
})
``` ```
+41 -9
View File
@@ -1,19 +1,49 @@
## Key Notes ### C Setup for Polydev 🛠️
* Currently with the way I have it work, the first time you build a project, it will error out no matter what. Just rerun the build and then if there are errors it is most likely a you issue more than a me issue.
#### Key Notes ⚠️
> **Important**: The first time you build a project, it might throw an error. This is expected behavior. Simply rerun the build, and if errors persist, it may be an issue with your project setup rather than the plugin.
---
#### Keybinds 🎮
You can customize keybinds for your C projects with Polydev.
| Keybind | Action |
|---------------------|--------------------------------------------------|
| `<leader>pb` | Build all C files in the `src` directory |
| `<leader>pr` | Run `<Project_name>` in your build directory |
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
#### Configuration Example:
## Keybinds
```lua ```lua
require("Polydev").c.setup({ require("Polydev").c.setup({
keybinds = { keybinds = {
["<Esc>"] = "CloseTerminal" -- Closes terminal, esc by default. ["<leader>pb"] = "CBuild", -- Build all C files in the src directory
["<leader>pb"] = "CBuild", -- Building all C Files in src directory in. ["<leader>pr"] = "CRun", -- Run <Project_name> in your build directory
["<leader>pr"] = "CRun", -- Runs <Project_name> in your build directory ["<leader>nh"] = "NewCHeaderFile" -- Create a new header file in the current project’s src folder
["<leader>nf"] = "NewCFile", -- Creates a new c file in the current project src folder }
["<leader>nh"] = "NewCHeaderFile", -- Creates a new header file in the current project src folder
}) })
``` ```
## File Structure ---
#### File Structure 📂
This is the recommended file structure for your C projects using Polydev:
| Directory/File Path | Description |
|----------------------------|------------------------------------------------------|
| `CMakeLists.txt` | Configuration file for your project build |
| `src/` | Folder containing source files for the project |
| `main.c` | Main C file for the project |
| `*.c` | Additional C source files |
| `build/` | Folder where the build artifacts will be generated |
| `<project_name>.polydev` | Polydev metadata file (generated during build) |
| `include/` | Folder for header files |
| `*.h` | C header files |
#### Example Structure:
```md ```md
Projects/ Projects/
└── C/ └── C/
@@ -27,3 +57,5 @@ Projects/
└── include/ └── include/
└── *.h └── *.h
``` ```
---
+61
View File
@@ -0,0 +1,61 @@
### C Setup for Polydev 🛠️
#### Key Notes ⚠️
> **Important**: The first time you build a project, it might throw an error. This is expected behavior. Simply rerun the build, and if errors persist, it may be an issue with your project setup rather than the plugin.
---
#### Keybinds 🎮
You can customize keybinds for your C projects with Polydev.
| Keybind | Action |
|---------------------|--------------------------------------------------|
| `<leader>pb` | Build all C files in the `src` directory |
| `<leader>pr` | Run `<Project_name>` in your build directory |
| `<leader>nh` | Create a new header file in the current project’s `src` folder |
#### Configuration Example:
```lua
require("Polydev").c.setup({
keybinds = {
["<leader>pb"] = "CppBuild", -- Build all C files in the src 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
}
})
```
---
#### File Structure 📂
This is the recommended file structure for your C projects using Polydev:
| Directory/File Path | Description |
|----------------------------|------------------------------------------------------|
| `CMakeLists.txt` | Configuration file for your project build |
| `src/` | Folder containing source files for the project |
| `main.cpp` | Main Cpp file for the project |
| `*.cpp` | Additional Cpp source files |
| `build/` | Folder where the build artifacts will be generated |
| `<project_name>.polydev` | Polydev metadata file (generated during build) |
| `include/` | Folder for header files |
| `*.hpp` | Cpp header files |
#### Example Structure:
```md
Projects/
└── Cpp/
└── Project_Name/
├── CMakeLists.txt
├── src/
│ ├── main.cpp
│ └── *.cpp
├── build/
│ └── <project_name>.polydev
└── include/
└── *.hpp
```
---
+41 -6
View File
@@ -1,16 +1,49 @@
## Keybinds ### Java Setup for Polydev ☕️
#### Keybinds 🎮
You can customize the keybinds for your Java projects in Polydev.
| 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>nf` | Create a new Java file in the `src` folder |
#### Configuration Example:
```lua ```lua
-- 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 = {
["<Esc>"] = "CloseTerminal" -- Closes terminal, esc by default. ["<leader>pb"] = "JavaBuild", -- Build all Java files in the src directory
["<leader>pb"] = "JavaBuild" -- Building all Java Files in src directory in. ["<leader>pr"] = "JavaRun", -- Run Main.java in the out folder
["<leader>pr"] = "JavaRun" -- Runs Main.java in the out folder in your project_root ["<leader>nf"] = "NewJavaFile" -- Create a new Java file in the src folder
["<leader>nf"] = "NewJavaFile" -- Creates a new Java file in the current project src folder
} }
}) })
``` ```
## File Structure
---
#### Java Features ✨
* **Java Build and Run**:
Polydev allows you to build all Java files in the `src` directory with the press of a keybind. Once built, you can run the project from the `out` folder, with the `Main.java` file executed automatically.
* **Project File Management**:
The plugin manages your Java project files efficiently, helping you quickly add new Java files to the `src` directory. It also ensures that your build and run processes are streamlined.
---
#### File Structure 📂
Here’s the recommended structure for your Java projects using Polydev:
| Directory/File Path | Description |
|----------------------------|------------------------------------------------------|
| `src/` | Contains the source code files, including `Main.java` |
| `build/` | Contains compiled `.class` files |
| `Main.java` | The main entry point of your Java project |
#### Example Structure:
```md ```md
Projects/ Projects/
@@ -21,3 +54,5 @@ Projects/
└── build/ └── build/
└── *.class └── *.class
``` ```
---
+50 -8
View File
@@ -1,22 +1,64 @@
## Keybinds ### Lua Setup for Polydev 🐢
#### Key Notes ⚠️
* Polydev provides seamless integration with Lua projects, allowing you to easily run and manage Lua code.
* You must include a `<Project_name>.polydev` file in your project root directory for Polydev to recognize the project. Missing this file will lead to errors.
* The file structure should be organized to ensure smooth execution and functionality.
---
#### Keybinds 🎮
Below are the default keybinds for Lua projects using Polydev. You can adjust them to suit your personal preferences.
| Keybind | Action |
|---------------------|-------------------------------------------------|
| `<leader>pr` | Run the Lua project |
##### Configuration Example:
```lua ```lua
-- These are the defaults for lua -- These are the defaults for Lua, adjust as needed
require("Polydev").lua.setup({ require("Polydev").lua.setup({
keybinds = { keybinds = {
["<Esc>"] = "CloseTerminal", ["<leader>pr"] = "LuaRun", -- Run the Lua project
["<leader>pr"] = "LuaRun",
["<leader>nf"] = "NewLuaFile",
} }
}) })
``` ```
## File Structure ---
#### Lua Features ✨
* **Run Lua Projects**:
Easily run your Lua project from within your terminal using the `<leader>pr` keybind. This automatically runs your `init.lua` or the entry point of your Lua code.
* **Create New Lua Files**:
With the `<leader>nf` keybind, you can quickly create new Lua files in the `src` directory, maintaining an organized project structure.
---
#### File Structure 📂
Here’s the suggested directory structure for your Lua projects with Polydev:
| Directory/File Path | Description |
|----------------------------|-----------------------------------------------------|
| `<Project_name>.polydev` | Project metadata file that Polydev uses for configuration |
| `lua/` | Directory containing the main Lua project files |
| `lua/<Project_name>/init.lua` | The main entry point for your Lua project |
##### Example File Structure:
```md ```md
Projects/ Projects/
└── Lua/ └── Lua/
└── Project_Name/ └── Project_Name/
├── <Project_name>.polydev ├── <Project_name>.polydev -- Polydev configuration file
└── lua/ └── lua/
└── Project_name/ └── Project_name/
└── init.lua └── init.lua -- Main Lua file
``` ```
---
+45 -10
View File
@@ -1,20 +1,54 @@
## Keybinds ### Python Setup for Polydev 🐍
#### Keybinds 🎮
You can easily customize the keybinds for your Python projects using Polydev.
| Keybind | Action |
|---------------------|---------------------------------------------------|
| `<leader>pr` | Run the Python project in your active terminal |
| `<leader>pb` | Install dependencies using pip |
#### Configuration Example:
```lua ```lua
require("Polydev").python.setup({ require("Polydev").python.setup({
keybinds = { keybinds = {
["<Esc>"] = "CloseTerminal", ["<leader>pr"] = "PythonRun", -- Run the Python project
["<leader>pr"] = "PythonRun", ["<leader>pb"] = "PythonPip" -- Install dependencies using pip
["<leader>nf"] = "NewPythonFile",
["<leader>pb"] = "PythonPip"
} }
}) })
``` ```
## Python Features ---
* A feature that is added to the python language for this plugin is to be able to install dependencies with pip within the terminal. You can even update pip. Just type your dependency you want and boom it is installed or not depending on if python likes you.
* Each project with python creates a new virtual environment and automatically uses it so you dont have to worry, just install modules as you like. #### Python Features 🚀
Here are some cool features available for Python projects using Polydev:
- **Automatic Virtual Environment Creation** 🔧
Each Python project automatically sets up and uses a new virtual environment. You don’t need to worry about environment management. Just install your dependencies with `pip` as needed.
- **Dependency Management with Pip** 📦
Need to install Python modules? Simply type the name of the module in the terminal, and Polydev will take care of the installation using `pip`. You can even update `pip` if required, ensuring smooth installation.
- **Effortless Dependency Handling** ⚡
You no longer need to manually activate or deactivate virtual environments. With Polydev, the environment is set up and activated automatically, simplifying your workflow.
---
#### File Structure 📂
Here’s the recommended structure for your Python projects using Polydev:
| Directory/File Path | Description |
|----------------------------|------------------------------------------------------|
| `requirements.txt` | File for listing project dependencies |
| `setup.py` | Python project setup file |
| `tests/` | Folder containing test files |
| `venv/` | Virtual environment folder |
| `main.py` | Main Python file for your project |
#### Example Structure:
## File Structure
```md ```md
Projects/ Projects/
└── Python/ └── Python/
@@ -24,5 +58,6 @@ Projects/
├── setup.py ├── setup.py
├── tests/ ├── tests/
└── venv/ └── venv/
``` ```
---
+64 -48
View File
@@ -1,90 +1,102 @@
# Setup and Customizing
## Project Name # Setup and Customizing Polydev
* You can change the default directory for the project. The project can be made from anywhere you want.
* It will automatically make the new Root Directory, so you don't have to worry about making it. ## 🔧 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.
> **Note:** `project_root` allows you to customize where your project will be stored. If you don't specify it, the default is `~/Projects/Language`.
---
### LazyVim Example
### Lazy
```lua ```lua
return { return {
... ...
opts = { opts = {
<language> = { <language> = {
project_root = "~/Home/..." -- Default: ~/Projects/Language project_root = "~/Home/..." -- Default: ~/Projects/Language
} }
} }
... ...
} }
``` ```
### Others ### Packer Example
```lua ```lua
require("Polydev").language.setup({ require("Polydev").language.setup({
project_root = "~/Home/..." -- Default: ~/Projects/Language project_root = "~/Home/..." -- Default: ~/Projects/Language
}) })
``` ```
## Keybinds
* Every language has the almost same keybinds so it is easy to remember keybinds and not have to remember thousands of keybinds.
* Some languages have separate functions (python has a pip keybind for example) adding more keybinds
``` ## ⌨ Keybinds Customization
Key/ Polydev allows you to easily manage keybinds, providing a uniform way to interact with different languages. Most keybinds are the same across languages, while some have language-specific ones (e.g., Python's pip keybind).
├── *Universal, cannot be changed through specific language settings
└── *Per-language, can be changed separately by language if wanted ### Keybind Categories
``` | Keybind Type | Description |
|-------------------|--------------------------------------------------|
| **Universal** | Cannot be changed through specific language settings (e.g., `<leader>nf` for a new file). |
| **Per-language** | Can be customized per language (e.g., `<leader>pb` for language build). |
### LazyVim Example
### Lazy
```lua ```lua
return { return {
... ...
opts = { opts = {
<language> = { <language> = {
["<Esc>"] = "CloseTerminal", -- Planned to be *Universal -- However can be changed per language for now ["<Esc>"] = "CloseTerminal", -- Universal, can be changed per language for now
["<leader>pb"] = "languageBuild", -- *Per-language ["<leader>pb"] = "languageBuild", -- Per-language
["<leader>pr"] = "languageRun", -- *Per-language ["<leader>pr"] = "languageRun", -- Per-language
["<leader>nf"] = "NewLanguageFile", --*Universal -- such as .c files ["<leader>nf"] = "NewLanguageFile", -- Universal
["<leader>nh"] = "NewLanguageSecondaryFile", --*Universal -- such as .h files ["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
} }
} }
... ...
} }
``` ```
### Others ### Packer Example
```lua ```lua
require("Polydev"}.language.setup({ require("Polydev").language.setup({
keybinds = [ keybinds = {
["<Esc>"] = "CloseTerminal", -- Planned to be *Universal -- However can be changed per language for now ["<Esc>"] = "CloseTerminal", -- Universal, can be changed per language for now
["<leader>pb"] = "languageBuild", -- *Per-language ["<leader>pb"] = "languageBuild", -- Per-language
["<leader>pr"] = "languageRun", -- *Per-language ["<leader>pr"] = "languageRun", -- Per-language
["<leader>nf"] = "NewLanguageFile", --*Universal -- such as .c files ["<leader>nf"] = "NewLanguageFile", -- Universal
["<leader>nh"] = "NewLanguageSecondaryFile", --*Universal -- such as .h files ["<leader>nh"] = "NewLanguageSecondaryFile", -- Universal
} }
}) })
``` ```
## Terminal ---
* I plan on making the terminal settings a global setting instead of language specific, just need to figure out how
* The terminal has a couple of options that can be customized and with more to come ## 🖥 Terminal Customization
- Each is set to 0 by default You can further tweak the terminal settings to suit your preferences! These options allow you to adjust padding, borders, numbers, and scrolling behavior.
* **_right_padding:_** Padding for the right width of the terminal
* **_left_padding:_** Padding for the left width of the terminal ### Available Terminal Settings
* **_top_padding:_** Padding for the top height of the terminal | Setting | Default Value | Description |
* **_bottom_padding:_** Padding for the bottom padding of the terminal |------------------|-----------------|---------------------------------------------------------|
- Each is enabled by default | **right_padding** | `0` | Padding for the right width of the terminal. |
* **_border:_** Adds a rounded border to the window | **left_padding** | `0` | Padding for the left width of the terminal. |
* **_number:_** Adds numbers to side of terminal | **top_padding** | `0` | Padding for the top height of the terminal. |
* **_relativenumber:_** Relative numbers indicate distances from the cursor, only works if number is enabled | **bottom_padding**| `0` | Padding for the bottom height of the terminal. |
* **_scroll:_** Allows scrolling in terminal | **border** | `true` | Adds a rounded border to the window. |
| **number** | `true` | Displays line numbers in the terminal. |
| **relativenumber**| `true` | Displays relative numbers based on cursor position. |
| **scroll** | `true` | Enables scroll functionality in the terminal. |
> **Note:** These terminal settings allow you to personalize the terminal view and improve usability. You can easily adjust the padding, borders, and other aspects to your preference.
---
### LazyVim Example
### Lazy
```lua ```lua
return { return {
... ...
opts = { opts = {
<language> = {
terminal = { terminal = {
right_padding = 0, right_padding = 0,
bottom_padding = 0, bottom_padding = 0,
@@ -96,16 +108,14 @@ return {
scroll = true, scroll = true,
} }
} }
}
... ...
} }
``` ```
### Others ### Packer Example
```lua ```lua
-- These are just defaults, so no need to copy them require("Polydev").setup({
require("Polydev").language.setup({
terminal = { terminal = {
right_padding = 0, right_padding = 0,
bottom_padding = 0, bottom_padding = 0,
@@ -118,3 +128,9 @@ require("Polydev").language.setup({
} }
}) })
``` ```
## 🚀 Final Thoughts and Customizations
This guide provided you with the basic configuration steps for setting up Polydev with your preferred package manager and customizing key aspects like project names, keybinds, and terminal settings.
You can further explore other Polydev features and modify the configuration to suit your development workflow.
+20 -13
View File
@@ -1,13 +1,15 @@
---@type table
local M = {} local M = {}
---@class Keybinds
---@class KeybindConfigs
---@field [string] string ---@field [string] string
--- ---
---@class Language ---@class LanguageConfigs
---@field project_root string ---@field project_root? string
---@field keybinds? Keybinds -- ? makes fields optional ---@field keybinds? KeybindConfigs -- ? makes fields optional
---@field build_attributes? string ---@field build_attributes? string
--- ---
---@class Terminal ---@class TerminalConfigs
---@field right_padding integer ---@field right_padding integer
---@field left_padding integer ---@field left_padding integer
---@field bottom_padding integer ---@field bottom_padding integer
@@ -17,14 +19,14 @@ local M = {}
---@field relativenumber boolean ---@field relativenumber boolean
--- ---
---@class Defaults ---@class Defaults
---@field html Language ---@field html LanguageConfigs
---@field rust Language ---@field rust LanguageConfigs
---@field java Language ---@field java LanguageConfigs
---@field python Language ---@field python LanguageConfigs
---@field lua Language ---@field lua LanguageConfigs
---@field c Language ---@field c LanguageConfigs
---@field cpp Language ---@field cpp LanguageConfigs
---@field terminal Terminal ---@field terminal TerminalConfigs
---@type Defaults ---@type Defaults
M.defaults = { M.defaults = {
@@ -87,14 +89,19 @@ M.defaults = {
} }
} }
---@type string[]
M.user_config = {} M.user_config = {}
---@param user_opts table
function M.setup(user_opts) function M.setup(user_opts)
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {}) M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
end end
---@param lang string
---@return string|table
function M.get(lang) function M.get(lang)
return M.user_config[lang] or {} return M.user_config[lang] or {}
end end
---@return table
return M return M
+26 -18
View File
@@ -1,16 +1,21 @@
---@module "Polydev.configs"
local config = require("Polydev.configs")
---@module "Polydev.utils"
local utils = require("Polydev.utils")
---@module "Polydev.templates"
local templates = require("Polydev.templates")
---@type table
local M = {} local M = {}
---@type table
M.loaded_languages = {} M.loaded_languages = {}
M.config = require("Polydev.configs")
M.utils = require("Polydev.utils")
M.java = require("Polydev.languages.java")
M.c = require("Polydev.languages.c")
M.cpp = require("Polydev.languages.cpp")
M.lua = require("Polydev.languages.lua")
M.python = require("Polydev.languages.python")
M.rust = require("Polydev.languages.rust")
M.html = require("Polydev.languages.html")
---@param lang string
---@param opts table?
---@return boolean
function M.load_language_module(lang, opts) function M.load_language_module(lang, opts)
if M.loaded_languages[lang] then return true end if M.loaded_languages[lang] then return true end
@@ -25,11 +30,12 @@ function M.load_language_module(lang, opts)
end end
function M.create_project() function M.create_project()
local opts = {}
vim.ui.input({ prompt = "Enter language for project: " }, function(lang) vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
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 {})
if M.load_language_module(lang) and M.loaded_languages[lang].create_project then if M.load_language_module(lang) and templates.projects[lang] and templates.projects[lang].run then
M.loaded_languages[lang].create_project() templates.create_project(lang, opts.project_root)
else else
print("Error: No project creation method for " .. lang) print("Error: No project creation method for " .. lang)
end end
@@ -40,21 +46,22 @@ function M.create_new_file()
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang) vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
if not lang or lang == "" then return print("File creation canceled.") end if not lang or lang == "" then return print("File creation canceled.") end
if M.load_language_module(lang) and M.loaded_languages[lang].create_new_file then if M.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
M.loaded_languages[lang].create_new_file() templates.create_new_file(lang)
else else
print("Error: No File creation method for " .. lang) print("Error: No File creation method for " .. lang)
end end
end) end)
end end
---@param opts table
function M.setup(opts) function M.setup(opts)
opts = opts or {} opts = opts or {}
M.config.setup(opts) config.setup(opts)
M.utils.setup(opts) utils.setup(opts)
for lang, user_opts in pairs(opts) do for lang, user_opts in pairs(opts) do
local default = M.config.defaults[lang] or {} local default = config.defaults[lang] or {}
M.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("NewProject", M.create_project, {}) vim.api.nvim_create_user_command("NewProject", M.create_project, {})
@@ -70,4 +77,5 @@ function M.setup(opts)
}) })
end end
---@return table
return M return M
-88
View File
@@ -25,94 +25,6 @@ function M.setup(opts)
end end
end end
function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then
print("Project creation canceled.")
return
end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do
vim.fn.mkdir(project_root .. path, "p")
end
utils.write_file(project_root .. "/build/" .. project_name .. ".polydev", project_name)
utils.write_file(project_root .. "/src/main.c", [[
/* If you have vcpkg and want to use it:
vcpkg new --application
vcpkg add port <package_name>
*/
#include <stdio.h>
int main() {
printf("%s", "Hello World");
return 0;
}
]])
utils.write_file(project_root .. "/CMakeLists.txt", string.format([[
cmake_minimum_required(VERSION 3.10)
project(%s)
include_directories(include)
set(SOURCES src/main.c)
add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
# target_link_libraries(Game PRIVATE SDL3::SDL3)
]], project_name, project_name))
utils.write_file(project_root .. "/CMakePresets.json", string.format([[
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
]]))
utils.write_file(project_root .. "/CMakeUserPresets.json", string.format([[
{
"version": 2,
"configurePresets": [
{
"name": "default",
"inherits": "vcpkg",
"environment": {
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
}
}
]
}
]]))
vim.cmd("edit " .. project_root .. "/src/main.c")
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
if not class_name or class_name == "" then return print("File creation canceled.") end
local root_dir = M.get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. class_name .. ".c", "")
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
-89
View File
@@ -25,95 +25,6 @@ function M.setup(opts)
end end
end end
function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then
print("Project creation canceled.")
return
end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do
vim.fn.mkdir(project_root .. path, "p")
end
utils.write_file(project_root .. "/build/" .. project_name .. ".polydev", project_name)
utils.write_file(project_root .. "/src/main.cpp", [[
/* If you have vcpkg and want to use it:
vcpkg new --application
vcpkg add port <package_name>
*/
#include <iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
]])
utils.write_file(project_root .. "/CMakeLists.txt", string.format([[
cmake_minimum_required(VERSION 3.10)
project(%s)
include_directories(include)
set(SOURCES src/main.cpp)
add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
# target_link_libraries(Game PRIVATE SDL3::SDL3)
]], project_name, project_name))
utils.write_file(project_root .. "/CMakePresets.json", string.format([[
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
]]))
utils.write_file(project_root .. "/CMakeUserPresets.json", string.format([[
{
"version": 2,
"configurePresets": [
{
"name": "default",
"inherits": "vcpkg",
"environment": {
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
}
}
]
}
]]))
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
vim.cmd("edit " .. project_root .. "/src/main.cpp")
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
if not class_name or class_name == "" then return print("File creation canceled.") end
local root_dir = M.get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. class_name .. ".cpp", "")
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
+4 -46
View File
@@ -1,55 +1,13 @@
local utils = require("Polydev.utils") ---@type table
local M = {} local M = {}
---@type table|nil
M.opts = nil M.opts = nil
---@param opts table
function M.setup(opts) function M.setup(opts)
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {})
end end
function M.create_project() ---@return table
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
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(project_root .. "index.html", main_html_content)
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter page name: " }, function(page)
if not page or page == "" then return print("Class creation canceled.") end
local html_content = string.format([[
<!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("./" .. page .. ".html", html_content)
end)
end
return M return M
-32
View File
@@ -21,38 +21,6 @@ function M.setup(opts)
end end
end end
function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(project_root .. path, "p") end
local main_java_content = [[
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
]]
utils.write_file(project_root .. "/src/Main.java", main_java_content)
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter class name: " }, function(class_name)
if not class_name or class_name == "" then return print("Class creation canceled.") end
local root_dir = vim.fn.expand("%:p:h"):match("(.*)/src")
if not root_dir then return print("Error: src directory not found.") end
local java_content = string.format([[
public class %s {
// New File
}
]], class_name)
utils.write_file(root_dir .. "/src/" .. class_name .. ".java", java_content)
end)
end
function M.build() function M.build()
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: Could not detect project root directory.") end
+17 -39
View File
@@ -1,9 +1,16 @@
---@module "Polydev.utils"
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
---@type table
local M = {} local M = {}
---@type table
M.keybinds = {} M.keybinds = {}
---@type table|nil
M.opts = nil M.opts = nil
---@param opts table
function M.setup(opts) function M.setup(opts)
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {})
for key, command in pairs(M.opts.keybinds) do for key, command in pairs(M.opts.keybinds) do
@@ -17,7 +24,9 @@ function M.setup(opts)
end end
end end
function M.get_project_root() function M.run()
---@return string|nil
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
local polydev_file = vim.fn.glob(dir .. "/*.polydev") local polydev_file = vim.fn.glob(dir .. "/*.polydev")
@@ -27,49 +36,18 @@ function M.get_project_root()
return nil return nil
end end
function M.get_project_name() ---@return string
local polydev_file = vim.fn.glob((M.get_project_root() or "") .. "/*.polydev") local function get_project_name()
return polydev_file:match("([^/]+)%.polydev$") return vim.fn.glob((M.get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$")
end end
if not get_project_root() or not get_project_name() then return print("Error: Project root not found.") end
function M.create_project() local init_lua_path = get_project_root() .. "/lua/" .. get_project_name() .. "/init.lua"
vim.ui.input({ prompt = "Enter project name: " },
function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(project_root .. path, "p") end
utils.write_file(project_root .. "/lua/" .. project_name .. "/init.lua", [[
local M = {}
return M
]])
utils.write_file(project_root .. "/" .. project_name .. ".polydev", "[[DO NOT REMOVE THIS FILE]]")
vim.cmd("edit " .. project_root .. "/lua/" .. project_name .. "/init.lua")
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
if not class_name or class_name == "" then return print("File creation canceled.") end
local root_dir = M.get_project_root()
local project_name = M.get_project_name()
if not root_dir or not project_name then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/lua/" .. project_name .. "/" .. class_name .. ".lua", "")
end)
end
function M.run()
local root = M.get_project_root()
local project_name = M.get_project_name()
if not root or not project_name then return print("Error: Project root not found.") end
local init_lua_path = root .. "/lua/" .. project_name .. "/init.lua"
if vim.fn.filereadable(init_lua_path) == 1 then if vim.fn.filereadable(init_lua_path) == 1 then
utils.open_float_terminal("lua " .. init_lua_path) utils.open_float_terminal("lua " .. init_lua_path)
else else
print("Error: " .. init_lua_path .. " not found in " .. root) print("Error: " .. init_lua_path .. " not found in " .. get_project_root())
end end
end end
---@return table
return M return M
-65
View File
@@ -42,71 +42,6 @@ function M.get_project_root()
return nil return nil
end end
function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then
print("Project creation canceled.")
return
end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/include" }) do
vim.fn.mkdir(project_root .. path, "p")
end
utils.write_file(project_root .. "/main.py", [[
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
]])
utils.write_file(project_root .. "/include/__init__.py", "")
utils.write_file(project_root .. "/requirements.txt", "")
utils.write_file(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))
vim.cmd("edit " .. project_root .. "/main.py")
local venv_path = 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)
end
function M.create_new_file()
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:match("%.py$") then
file_name = file_name .. ".py"
end
local root_dir = M.get_project_root()
if not root_dir then
return print("Error: Project root not found.")
end
local file_path = root_dir .. "/include/" .. file_name
utils.write_file(file_path, "")
end)
end
function M.install_dependency() function M.install_dependency()
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module) vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
if not pip_module or pip_module == "" then if not pip_module or pip_module == "" then
-18
View File
@@ -21,24 +21,6 @@ function M.setup(opts)
end end
end end
function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
vim.fn.system("cargo new " .. project_root)
vim.cmd("edit " .. project_root .. "/src/main.rs")
end)
end
function M.create_new_file()
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
if not class_name or class_name == "" then return print("File creation canceled.") end
local root_dir = M.get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. class_name .. ".rs", "")
end)
end
function M.get_project_root() function M.get_project_root()
local dir = vim.fn.expand("%:p:h") local dir = vim.fn.expand("%:p:h")
while dir ~= "/" do while dir ~= "/" do
+393
View File
@@ -0,0 +1,393 @@
---@module 'Polydev.utils'
local utils = require("Polydev.utils")
---
---@type table
local M = {}
---@class TemplateLanguage
---@field run fun(project_name: string, project_root: string): nil
---@class Projects
---@field java TemplateLanguage
---@field python TemplateLanguage
---@field lua TemplateLanguage
---@field c TemplateLanguage
---@field cpp TemplateLanguage
---@field rust TemplateLanguage
---@field html TemplateLanguage
---@alias TemplatesLanguageName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
---@type Projects
M.projects = {
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 main_java_content = [[
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
]]
utils.write_file(full_project_root .. "/src/Main.java", main_java_content)
return nil
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))
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)
return nil
end
},
lua = {
run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(full_project_root .. path, "p") end
utils.write_file(full_project_root .. "/lua/" .. project_name .. "/init.lua", [[
local M = {}
return M
]])
utils.write_file(full_project_root .. "/" .. project_name .. ".polydev", "[[DO NOT REMOVE THIS FILE]]")
vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua")
return nil
end
},
c = {
run = function(project_name, project_root)
local full_project_root = vim.fn.expand(M.opts.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 .. "/build/" .. project_name .. ".polydev", project_name)
utils.write_file(full_project_root .. "/src/main.c", [[
/* If you have vcpkg and want to use it:
vcpkg new --application
vcpkg add port <package_name>
*/
#include <stdio.h>
int main() {
printf("%s", "Hello World");
return 0;
}
]])
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
cmake_minimum_required(VERSION 3.10)
project(%s)
include_directories(include)
set(SOURCES src/main.c)
add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
# target_link_libraries(Game PRIVATE SDL3::SDL3)
]], project_name, project_name))
utils.write_file(full_project_root .. "/CMakePresets.json", string.format([[
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
]]))
utils.write_file(full_project_root .. "/CMakeUserPresets.json", string.format([[
{
"version": 2,
"configurePresets": [
{
"name": "default",
"inherits": "vcpkg",
"environment": {
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
}
}
]
}
]]))
vim.cmd("edit " .. full_project_root .. "/src/main.c")
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", full_project_root))
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 .. "/build/" .. project_name .. ".polydev", project_name)
utils.write_file(full_project_root .. "/src/main.cpp", [[
/* If you have vcpkg and want to use it:
vcpkg new --application
vcpkg add port <package_name>
*/
#include <iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
]])
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
cmake_minimum_required(VERSION 3.10)
project(%s)
include_directories(include)
set(SOURCES src/main.cpp)
add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
# target_link_libraries(Game PRIVATE SDL3::SDL3)
]], project_name, project_name))
utils.write_file(full_project_root .. "/CMakePresets.json", string.format([[
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
]]))
utils.write_file(full_project_root .. "/CMakeUserPresets.json", string.format([[
{
"version": 2,
"configurePresets": [
{
"name": "default",
"inherits": "vcpkg",
"environment": {
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
}
}
]
}
]]))
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", full_project_root))
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
return nil
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
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
},
}
---@class TemplateFile
---@field run fun(file_name: string): nil
---@class Files
---@field java TemplateFile
---@field python TemplateFile
---@field lua TemplateFile
---@field c TemplateFile
---@field cpp TemplateFile
---@field rust TemplateFile
---@field html TemplateFile
---@alias TemplatesFileName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
---@type Files
M.files = {
java = {
run = function (file_name)
local root_dir = vim.fn.expand("%:p:h"):match("(.*)/src")
if not root_dir then return print("Error: src directory not found.") end
local java_content = string.format([[
public class %s {
// New File
}
]], class_name)
utils.write_file(root_dir .. "/src/" .. file_name .. ".java", java_content)
end
},
python = {
run = function (file_name)
if not file_name:match("%.py$") then file_name = file_name .. ".py" end
local root_dir = M.get_project_root()
if not root_dir then return print("Error: Project root not found.") end
local file_path = root_dir .. "/include/" .. file_name
utils.write_file(file_path, "")
end
},
lua = {
run = function (file_name)
local function get_project_root()
local dir = vim.fn.expand("%:p:h")
while dir ~= "/" do
local polydev_file = vim.fn.glob(dir .. "/*.polydev")
if polydev_file ~= "" then return dir end
dir = vim.fn.fnamemodify(dir, ":h")
end
return nil
end
local function get_project_name() return vim.fn.glob((get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$") end
if not get_project_root() or not get_project_name() then return print("Error: Project root not found.") end
utils.write_file(get_project_root() .. "/lua/" .. get_project_name() .. "/" .. file_name .. ".lua", "")
end
},
c = {
run = function (file_name)
local function 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
if not file_name or file_name == "" then return print("File creation canceled.") end
local root_dir = get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. file_name .. ".c", "")
end
},
cpp = {
run = function (file_name)
local function 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
local root_dir = get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. file_name .. ".cpp", "")
end
},
rust = {
run = function (file_name)
local function get_project_root()
local dir = vim.fn.expand("%:p:h")
while dir ~= "/" do
if vim.fn.isdirectory(dir .. "/src") == 1 then
return dir
end
dir = vim.fn.fnamemodify(dir, ":h")
end
end
local root_dir = get_project_root()
if not root_dir then return print("Error: Project root not found.") end
utils.write_file(root_dir .. "/src/" .. file_name .. ".rs", "")
end
},
html = {
run = function (file_name)
local html_content = string.format([[
<!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("./" .. file_name .. ".html", html_content)
end
}
}
---@param lang TemplatesLanguageName
---@param project_root string
function M.create_project(lang, project_root)
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end
M.projects[lang].run(project_name, project_root)
end)
end
---@param lang TemplatesFileName
function M.create_new_file(lang)
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
if not file_name or file_name == "" then return print("File creation canceled.") end
M.files[lang].run(file_name)
end)
end
---@return any
return M
+1 -1
View File
@@ -3,10 +3,10 @@ nav:
- Home: index.md - Home: index.md
- Installation: installation.md - Installation: installation.md
- Setup: setup.md - Setup: setup.md
- Examples: examples.md
- Language Specific Docs: - Language Specific Docs:
- Java: languages/java.md - Java: languages/java.md
- C: languages/c.md - C: languages/c.md
- Cpp: languages/cpp.md
- Lua: languages/lua.md - Lua: languages/lua.md
- Python: languages/python.md - Python: languages/python.md
theme: theme: