diff --git a/.github/Repo.toml b/.github/Repo.toml new file mode 100644 index 0000000..107b8b9 --- /dev/null +++ b/.github/Repo.toml @@ -0,0 +1,6 @@ +[scopes] +config = ["lua/config"] +lua = ["lua"] +nvim = ["."] +plugins = ["lua/plugins"] +templates = ["templates"] diff --git a/.github/scopes.json b/.github/scopes.json.backup.20251027_202635 similarity index 100% rename from .github/scopes.json rename to .github/scopes.json.backup.20251027_202635 diff --git a/PLUGIN_STRUCTURE.md b/PLUGIN_STRUCTURE.md deleted file mode 100644 index 91724d5..0000000 --- a/PLUGIN_STRUCTURE.md +++ /dev/null @@ -1,177 +0,0 @@ -# AstroNvim Plugin Structure - -This document describes the complete plugin structure for your AstroNvim configuration. - -## 📁 Directory Structure - -``` -lua/plugins/ -├── README.md # Documentation and guide -├── astrocore.lua # Core settings, keymaps, autocmds (23KB) -├── astrolsp.lua # LSP, formatting, linting (23KB) -├── astroui.lua # UI configuration (8.3KB) -├── buildtools.lua # Build tools & dev environment (6.5KB) -├── bufferline.lua # Buffer/tab management (2.1KB) -├── claude.lua # Claude Code integration (1.3KB) -├── neotree.lua # File explorer (15KB) -├── _template-custom.lua # Template for custom plugins (disabled) -├── _template-filetype.lua # Template for filetype plugins (disabled) -├── _template-mason.lua # Template for Mason tools (disabled) -├── _template-treesitter.lua # Template for Treesitter (disabled) -└── _template-ui.lua # Template for UI plugins (disabled) -``` - -## 🎯 Active Plugin Files - -### Core Configuration (3 files) - -1. **astrocore.lua** - Core AstroNvim functionality - - Session management - - Root detection (lsp, git) - - Features configuration - - Options (vim settings) - - **Keymappings** (extensive custom bindings) - - **UI toggles** (`u` prefix) - -2. **astrolsp.lua** - Comprehensive LSP & Tooling (CONSOLIDATED) - - LSP configurations (Go, TypeScript, Tailwind, HTML, CSS, Protobuf, JSON, YAML, Lua, Volar) - - **Formatting** (Conform.nvim with oxfmt, stylua, rustfmt, taplo) - - **Linting** (nvim-lint with oxlint, stylelint, markdownlint) - - **Treesitter** configuration - - **TypeScript tooling** (typescript-tools, autotag) - - **Mason** auto-installation - - **Package management** (package-info, crates.nvim) - - **Diagnostics UI** (Trouble, lsp_lines, nvim-bqf) - -3. **astroui.lua** - UI/UX Configuration - - Colorscheme (cyberdream) - - Icons - - Statusline (Heirline) - - Status components - -### Feature Plugin Files (4 files) - -4. **buildtools.lua** - Development Tools - - Treesitter (TOML, YAML, JSON parsers) - - SchemaStore (JSON/YAML schemas) - - Overseer (task runner for bun, vite) - - Trouble (diagnostics) - - Gitsigns (git integration) - - EditorConfig - - DevContainer support - -5. **bufferline.lua** - Buffer Management - - Enhanced bufferline with diagnostics - - Custom close handlers - - Buffer groups support - - Icon integration - -6. **claude.lua** - AI Assistant - - Claude Code integration - - Git root detection - - Custom commands and keybindings - - File explorer integration - -7. **neotree.lua** - File Explorer - - Dynamic pattern filtering - - LSP file operations integration - - Snacks.rename integration (NEW) - - Custom keybindings for git, terminals, docker - - Custom commands (format, mason) - -8. **template.lua** - Code Templates (NEW) - - Snacks picker integration - - 14 essential templates for Cosmos SDK, Protobuf, and Vite+Cloudflare - - Smart variable substitution - - Filetype-aware template filtering - -## 📝 Template Files (5 files - disabled by default) - -These files are prefixed with `_template-` and disabled with `if true then return {} end`. -Remove the first line to activate them. - -1. **_template-custom.lua** - Examples for adding custom plugins -2. **_template-filetype.lua** - Filetype-specific configurations (Markdown, Rust, Python, Go, LaTeX) -3. **_template-mason.lua** - Mason tool installer customization -4. **_template-treesitter.lua** - Treesitter parser configuration -5. **_template-ui.lua** - UI plugins and colorscheme examples - -## ✅ Recent Changes - -### Consolidated Files -- ✅ **tsx.lua** → Merged into `astrolsp.lua` -- ✅ **linting.lua** → Merged into `astrolsp.lua` - -### Added Features -- ✅ Snacks.rename integration in `neotree.lua` -- ✅ Snacks.toggle keymaps in `astrocore.lua` (`u` prefix) -- ✅ Proper `---@type LazySpec` annotations on all files -- ✅ Comprehensive documentation (README.md) -- ✅ Template files for common customizations - -### New Toggle Keybindings (`u`) -- `ud` - Toggle diagnostics -- `un` - Toggle line numbers -- `ur` - Toggle relative numbers -- `uw` - Toggle line wrap -- `us` - Toggle spelling -- `ui` - Toggle inlay hints -- `ut` - Toggle treesitter -- `uc` - Toggle conceal -- `uI` - Toggle indent guides -- `uz` - Toggle zen mode -- `uZ` - Toggle zoom -- `ua` - Toggle animations -- `uS` - Toggle smooth scroll -- `up` - Toggle profiler -- `uh` - Toggle profiler highlights -- `ux` - Toggle dim inactive -- `uf` - Toggle format on save -- `ul` - Toggle LSP lines - -### Template Keybindings -- `` - Open template picker (Snacks integration) - -## 📚 Documentation - -All plugin files now include: -- ✅ Module documentation headers -- ✅ `---@type LazySpec` annotations -- ✅ Detailed inline comments -- ✅ Proper lazy loading strategies - -## 🎓 Quick Reference - -### Adding a New Plugin -1. Create a new `.lua` file in `lua/plugins/` -2. Add module documentation and `---@type LazySpec` -3. Return a table with plugin specifications -4. Configure lazy loading (event, cmd, ft, keys) - -### Modifying Existing Config -- Core settings → `astrocore.lua` -- LSP/formatting/linting → `astrolsp.lua` -- UI/statusline → `astroui.lua` -- Keymaps → `astrocore.lua` (mappings section) - -### Template Usage -1. Copy a template file (remove `_template-` prefix) -2. Remove `if true then return {} end` line -3. Customize the configuration -4. Save and restart Neovim - -## 🔧 Useful Commands -- `:Lazy` - Plugin manager -- `:Mason` - LSP/tool installer -- `:AstroReload` - Reload config -- `:ConformInfo` - Format status -- `:FormatToggle` - Toggle format on save -- `:LspLinesToggle` - Toggle inline diagnostics -- `:checkhealth` - Health check - -## 📖 Resources -- [AstroNvim Docs](https://docs.astronvim.com) -- [lazy.nvim](https://github.com/folke/lazy.nvim) -- [AstroCore](https://github.com/AstroNvim/astrocore) -- [AstroLSP](https://github.com/AstroNvim/astrolsp) -- [Snacks.nvim](https://github.com/folke/snacks.nvim) diff --git a/TEMPLATES_INTEGRATION.md b/TEMPLATES_INTEGRATION.md deleted file mode 100644 index c95b412..0000000 --- a/TEMPLATES_INTEGRATION.md +++ /dev/null @@ -1,451 +0,0 @@ -# Template.nvim Integration - -Complete code template system integrated with Snacks.nvim picker for rapid development. - -## 🎯 Overview - -Integrated template.nvim with custom Snacks picker for quick code scaffolding across your tech stack: -- **Cosmos SDK** (Go) - 4 templates -- **Protobuf** - 3 templates -- **Vite + Cloudflare + TanStack** - 7 templates - -## ⚡ Quick Start - -### Keybindings -- **``** - Open Snacks template picker (primary) -- **`t`** - Create a new template file -- **`T`** - Open Telescope template picker (alternative) - -### Commands -- `:TemplateSnacks` - Open Snacks picker for templates -- `:TemplateCreate [filetype]` - Create new template -- `:TemplateTelescope [type=insert|name=template] [filter_ft=true|false]` - Telescope picker -- `:Template ` - Use native template.nvim command - -### Usage Flow -1. Press `` to open picker -2. Templates are filtered by current filetype automatically -3. Select template from list -4. Enter variable name if prompted -5. Template is inserted with cursor at `{{_cursor_}}` position - -## 📦 Installation - -### Plugin Configuration -Location: `/home/prad/.config/nvim/lua/plugins/template.lua` - -Features: -- ✅ Snacks.nvim picker integration -- ✅ Smart variable substitution -- ✅ Filetype-aware filtering -- ✅ Custom template markers -- ✅ Interactive variable prompts - -### Keybindings -Location: `/home/prad/.config/nvim/lua/plugins/astrocore.lua` - -```lua -[""] = { "TemplateSnacks", desc = "Open template picker" } -["t"] = { function() vim.fn.feedkeys(":TemplateCreate ") end, desc = "Create new template" } -["T"] = { "TemplateTelescope type=insert", desc = "Template picker (Telescope)" } -``` - -## 📁 Template Structure - -``` -~/.config/nvim/templates/ -├── README.md # Template documentation -├── cosmos/ # Cosmos SDK templates -│ ├── keeper.go.tpl # Module keeper -│ ├── msg_server.go.tpl # Transaction server -│ ├── query_server.go.tpl # Query server -│ └── handler.go.tpl # Message handler -├── proto/ # Protobuf templates -│ ├── message.proto.tpl # Basic message -│ ├── tx.proto.tpl # Transaction service -│ └── query.proto.tpl # Query service -└── vite/ # Vite + Cloudflare templates - ├── worker.ts.tpl # Cloudflare Worker - ├── pages-function.ts.tpl # Pages Function - ├── page.tsx.tpl # TanStack Router page - ├── component.tsx.tpl # React component - ├── hook.ts.tpl # Custom hook - └── api.ts.tpl # TanStack Query API -``` - -## 🔧 Template Variables - -### Built-in Variables -- `{{_date_}}` → `2025-10-22 10:30:15` -- `{{_file_name_}}` → `user_service` (from user_service.go) -- `{{_camel_case_file_}}` → `UserService` -- `{{_upper_file_}}` → `USER_SERVICE` -- `{{_author_}}` → `Prad` -- `{{_email_}}` → `prad@sonr.io` -- `{{_cursor_}}` → Cursor position after insertion - -### Custom Registered Variables (New!) -- `{{_path_}}` → `/full/path/to/current/file.go` -- `{{_relative_path_}}` → `src/services/file.go` -- `{{_dir_}}` → `/full/path/to/current` -- `{{_project_}}` → `nvim` (current directory name) - -### Interactive Variables -- `{{_variable_}}` → Prompts for custom input -- `{{_lua:_}}` → Execute Lua code - -### Example -```go -// Template content -func New{{_camel_case_file_}}(id string) *{{_variable_}} { - {{_cursor_}} -} - -// After insertion (file: user_service.go, variable: UserData) -func NewUserService(id string) *UserData { - | // cursor here -} -``` - -## 📚 Template Reference - -### Cosmos SDK Templates - -#### keeper.go.tpl -**Purpose:** Module keeper with state management -**Variables:** Module name from filename -**Use case:** Starting new Cosmos SDK module - -```go -// Creates: -type Keeper struct { - storeKey sdk.StoreKey - cdc codec.BinaryCodec - paramstore paramtypes.Subspace -} -``` - -#### msg_server.go.tpl -**Purpose:** Transaction message handler -**Variables:** Message type name (prompted) -**Use case:** Adding new transaction types - -```go -// Prompts for: CreatePost -// Creates: Msg server with CreatePost handler -func (k msgServer) CreatePost(ctx, msg) (*MsgCreatePostResponse, error) -``` - -#### query_server.go.tpl -**Purpose:** Query handler implementation -**Variables:** Query method name (prompted) -**Use case:** Adding module queries - -```go -// Prompts for: GetPost -// Creates: Query handler for GetPost -func (k queryServer) GetPost(ctx, req) (*QueryGetPostResponse, error) -``` - -#### handler.go.tpl -**Purpose:** Message routing handler -**Use case:** Module message dispatcher - -### Protobuf Templates - -#### message.proto.tpl -**Purpose:** Basic protobuf message -**Variables:** Message name (prompted) -**Use case:** Data structures - -```protobuf -// Prompts for: Post -// Creates: -message Post { - option (gogoproto.equal) = true; - // fields here -} -``` - -#### tx.proto.tpl -**Purpose:** Transaction service definition -**Variables:** Method name (prompted) -**Use case:** Transaction RPC methods - -```protobuf -// Prompts for: CreatePost -// Creates service with CreatePost RPC -service Msg { - rpc CreatePost(MsgCreatePost) returns (MsgCreatePostResponse); -} -``` - -#### query.proto.tpl -**Purpose:** Query service with REST -**Variables:** Method name (prompted) -**Use case:** gRPC + HTTP queries - -```protobuf -// Prompts for: GetPost -// Creates query with HTTP annotation -rpc GetPost(QueryGetPostRequest) returns (QueryGetPostResponse) { - option (google.api.http).get = "/sonr/module/v1/GetPost"; -} -``` - -### Vite + Cloudflare Templates - -#### worker.ts.tpl -**Purpose:** Cloudflare Worker -**Use case:** Edge compute functions - -```typescript -// Creates Worker with Env interface -export default { - async fetch(request, env, ctx): Promise { - // worker logic - } -} -``` - -#### pages-function.ts.tpl -**Purpose:** Cloudflare Pages Function -**Use case:** Pages API routes - -```typescript -// Creates Pages Function handler -export const onRequest: PagesFunction = async (context) => { - const { request, env, params } = context - // function logic -} -``` - -#### page.tsx.tpl -**Purpose:** TanStack Router page -**Use case:** Full page routes - -```tsx -// For file: dashboard.tsx -// Creates: -export const Route = createFileRoute('/dashboard')({ - component: DashboardPage, -}) - -function DashboardPage() { - // page component -} -``` - -#### component.tsx.tpl -**Purpose:** React component -**Use case:** Reusable components - -```tsx -// For file: user_card.tsx -// Creates: -interface UserCardProps { } - -export const UserCard = memo(({ }) => { - return
-}) -``` - -#### hook.ts.tpl -**Purpose:** Custom React hook -**Use case:** Reusable logic - -```tsx -// For file: use_posts.ts -// Creates: -interface UsePostsOptions { } - -export function usePosts(options?: UsePostsOptions) { - const [data, setData] = useState() - // hook logic - return { data } -} -``` - -#### api.ts.tpl -**Purpose:** TanStack Query API client -**Use case:** Full API integration - -```typescript -// For file: posts.ts -// Creates: -- Query keys factory -- Fetch functions -- usePost(id) hook -- useCreatePost() mutation hook -``` - -## 💡 Workflow Examples - -### Example 1: Creating a Cosmos SDK Message Handler - -**Scenario:** Add a CreatePost transaction to your module - -1. **Create file:** `msg_server_create_post.go` -2. **Open picker:** `` -3. **Select:** `[cosmos] msg_server.go.tpl` -4. **Enter variable:** `CreatePost` when prompted -5. **Result:** -```go -func (k msgServer) CreatePost(goCtx context.Context, msg *types.MsgCreatePost) (*types.MsgCreatePostResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Validate message - if err := msg.ValidateBasic(); err != nil { - return nil, err - } - - | // cursor here - - return &types.MsgCreatePostResponse{}, nil -} -``` - -### Example 2: Creating a TanStack Query API - -**Scenario:** Add API client for posts - -1. **Create file:** `posts.ts` -2. **Open picker:** `` -3. **Select:** `[vite] api.ts.tpl` -4. **Result:** Full API client with: - - `postsKeys` query key factory - - `fetchPost(id)` function - - `createPost(data)` function - - `usePost(id)` query hook - - `useCreatePost()` mutation hook - -### Example 3: Creating a React Page - -**Scenario:** Add a new dashboard page - -1. **Create file:** `dashboard.tsx` -2. **Open picker:** `` -3. **Select:** `[vite] page.tsx.tpl` -4. **Result:** -```tsx -export const Route = createFileRoute('/dashboard')({ - component: DashboardPage, -}) - -function DashboardPage() { - | // cursor here - - return ( -
-

Dashboard

-
- ) -} -``` - -## 🎨 Customization - -### Adding New Templates - -#### Quick Method (Recommended) -1. Press `t` to start TemplateCreate command -2. Type category and filename: `vite/form.tsx` or `cosmos/store.go` -3. Optional: specify filetype as second argument (defaults to current buffer's filetype) -4. Template file is created with filetype marker and opens automatically - -Example: -```vim -:TemplateCreate vite/form.tsx typescriptreact -``` - -#### Manual Method -1. **Create template file** in templates directory: -```bash -nvim ~/.config/nvim/templates/vite/form.tsx.tpl -``` - -2. **Add filetype marker** as first line: -```tsx -;; typescriptreact -``` - -3. **Write template** with variables: -```tsx -;; typescriptreact -import { useForm } from 'react-hook-form' - -interface {{_camel_case_file_}}FormData { - {{_cursor_}} -} - -export function {{_camel_case_file_}}Form() { - const { register, handleSubmit } = useForm<{{_camel_case_file_}}FormData>() - - return
-} -``` - -4. **Use template:** `` → select your template - -### Modifying Configuration - -Edit `lua/plugins/template.lua` to change: -- Author name and email -- Template directory location -- Custom variable processors - -#### Adding Custom Variables -```lua --- In lua/plugins/template.lua, add after setup: -template.register("{{_custom_var_}}", function() - return "your value here" -end) -``` - -Example: -```lua --- Add project root detection -template.register("{{_git_root_}}", function() - return vim.fn.systemlist("git rev-parse --show-toplevel")[1] -end) -``` - -## 📊 Template Statistics - -- **Total Templates:** 14 -- **Cosmos SDK:** 4 templates -- **Protobuf:** 3 templates -- **Vite/Cloudflare:** 7 templates -- **Lines of Code Saved:** ~300-500 per template usage - -## 🚀 Benefits - -1. **Consistency** - All code follows same patterns -2. **Speed** - Scaffold in seconds vs minutes -3. **Best Practices** - Templates include proper structure -4. **Documentation** - Auto-included author/date info -5. **Type Safety** - Proper TypeScript/Go types - -## 📖 Resources - -- Template Documentation: `~/.config/nvim/templates/README.md` -- Plugin Source: `~/.config/nvim/lua/plugins/template.lua` -- [template.nvim GitHub](https://github.com/glepnir/template.nvim) - -## 🔥 Pro Tips - -1. **Filetype Filtering:** Templates auto-filter by current filetype in Snacks picker -2. **Variable Naming:** Use descriptive names for `{{_variable_}}` prompts -3. **Nested Directories:** Organize templates in subdirectories (shown as `[category] filename`) -4. **Custom Markers:** Register your own variables with `template.register()` -5. **Lua Expressions:** Use `{{_lua:vim.fn.getcwd()_}}` for dynamic content -6. **Quick Template Creation:** Use `t` to quickly create new templates with auto-completion -7. **Telescope Alternative:** Use `T` for Telescope picker with Snacks backend -8. **Path Variables:** Use new `{{_path_}}`, `{{_relative_path_}}`, `{{_dir_}}`, `{{_project_}}` variables - ---- - -**Integrated by:** Prad -**Date:** 2025-10-22 -**Total Integration Time:** ~30 minutes -**Templates Created:** 14 diff --git a/templates/README.md b/templates/README.md deleted file mode 100644 index 8eee7e7..0000000 --- a/templates/README.md +++ /dev/null @@ -1,207 +0,0 @@ -# Code Templates - -Essential templates for modern development with Cosmos SDK, Protobuf, and Vite+Cloudflare. - -## 🚀 Usage - -### Quick Access -- **``** - Open Snacks template picker (primary) -- **`t`** - Create a new template file -- **`T`** - Open Telescope template picker (alternative) -- `:TemplateSnacks` - Command for Snacks picker -- `:TemplateCreate [filetype]` - Create new template -- `:TemplateTelescope` - Command for Telescope picker - -### Template Variables - -Templates support the following placeholders: - -#### Built-in Variables -- `{{_date_}}` - Current date and time -- `{{_cursor_}}` - Cursor position after insertion -- `{{_file_name_}}` - Current file name (without extension) -- `{{_camel_case_file_}}` - File name converted to CamelCase -- `{{_upper_file_}}` - File name in UPPERCASE -- `{{_author_}}` - Author name (configured in plugin) -- `{{_email_}}` - Email address (configured in plugin) -- `{{_variable_}}` - Prompts for custom variable name -- `{{_lua:_}}` - Execute Lua expression - -#### Custom Registered Variables -- `{{_path_}}` - Full path to current file -- `{{_relative_path_}}` - Relative path to current file -- `{{_dir_}}` - Directory of current file -- `{{_project_}}` - Current project/directory name - -## 📁 Available Templates - -### Cosmos SDK (Go) - `/cosmos` - -#### `keeper.go.tpl` -Creates a Cosmos SDK keeper with store management and parameter store. - -**Use for:** Module keeper implementation -**Variables:** Uses `{{_file_name_}}` for module name - -#### `msg_server.go.tpl` -Creates a message server implementation for handling transactions. - -**Use for:** Transaction message handlers -**Variables:** `{{_variable_}}` for the message type name - -#### `query_server.go.tpl` -Creates a query server implementation for handling read queries. - -**Use for:** Query handlers for module state -**Variables:** `{{_variable_}}` for the query method name - -#### `handler.go.tpl` -Creates a message handler router for the module. - -**Use for:** Main message routing logic - -### Protobuf - `/proto` - -#### `message.proto.tpl` -Creates a basic protobuf message definition. - -**Use for:** Data structures and types -**Variables:** `{{_variable_}}` for the message name - -#### `tx.proto.tpl` -Creates a transaction message service with RPC definitions. - -**Use for:** Transaction (Msg) service definitions -**Variables:** `{{_variable_}}` for the transaction method name - -#### `query.proto.tpl` -Creates a query service with gRPC and HTTP annotations. - -**Use for:** Query service definitions with REST endpoints -**Variables:** `{{_variable_}}` for the query method name - -### Vite + Cloudflare + TanStack - `/vite` - -#### `worker.ts.tpl` -Creates a Cloudflare Worker with proper TypeScript types. - -**Use for:** Cloudflare Worker scripts -**File type:** TypeScript - -#### `pages-function.ts.tpl` -Creates a Cloudflare Pages Function. - -**Use for:** Cloudflare Pages API routes -**File type:** TypeScript - -#### `page.tsx.tpl` -Creates a TanStack Router page component. - -**Use for:** Full page routes with TanStack Router -**File type:** TypeScript React - -#### `component.tsx.tpl` -Creates a memoized React component with TypeScript. - -**Use for:** Reusable React components -**File type:** TypeScript React - -#### `hook.ts.tpl` -Creates a custom React hook with TypeScript. - -**Use for:** Reusable React hooks -**File type:** TypeScript - -#### `api.ts.tpl` -Creates a TanStack Query API client with CRUD operations. - -**Use for:** API integration with TanStack Query -**File type:** TypeScript -**Includes:** Query keys, fetch functions, and hooks - -## 💡 Examples - -### Creating a Cosmos SDK Message Server - -1. Create/open a file: `msg_server_create_post.go` -2. Press `` -3. Select `msg_server.go.tpl` -4. Enter variable name when prompted: `CreatePost` -5. Template is inserted with all placeholders filled - -### Creating a TanStack Query API - -1. Create/open a file: `posts.ts` -2. Press `` -3. Select `api.ts.tpl` -4. Template creates full API client with: - - Query keys - - Fetch functions - - React hooks for queries and mutations - -### Creating a React Component - -1. Create/open a file: `user_card.tsx` -2. Press `` -3. Select `component.tsx.tpl` -4. Component created with name `UserCard` (auto-converted to CamelCase) - -## 🎨 Customization - -### Adding Your Own Templates - -#### Quick Method (Recommended) -1. Press `t` to start the TemplateCreate command -2. Type category and filename (e.g., `vite/form.tsx`) -3. Optional: specify filetype (defaults to current buffer's filetype) -4. Template file is created automatically and opens for editing - -Example command: -```vim -:TemplateCreate vite/form.tsx typescriptreact -``` - -#### Manual Method -1. Create a new `.tpl` file in the templates directory -2. Add filetype marker as first line: `;; ` -3. Use template variables as needed -4. Save and use with `` - -Example: -```typescript -;; typescript -/** - * {{_file_name_}} - * @author {{_author_}} - * @project {{_project_}} - * @path {{_relative_path_}} - */ - -export const {{_camel_case_file_}} = {{_cursor_}} -``` - -### Template Organization - -- Use subdirectories to organize templates by category -- Template picker shows category in selection: `[category] filename` -- Templates are filtered by current file type automatically - -## 🔧 Configuration - -Edit template configuration in `lua/plugins/template.lua`: - -```lua -template.setup { - temp_dir = vim.fn.stdpath "config" .. "/templates", - author = "Your Name", - email = "your.email@example.com", -} -``` - -## 📚 Resources - -- [template.nvim GitHub](https://github.com/glepnir/template.nvim) -- [Cosmos SDK Docs](https://docs.cosmos.network/) -- [Cloudflare Workers Docs](https://developers.cloudflare.com/workers/) -- [TanStack Router](https://tanstack.com/router) -- [TanStack Query](https://tanstack.com/query) diff --git a/templates/cosmos/handler.go.tpl b/templates/cosmos/handler.go.tpl deleted file mode 100644 index 0ae8aeb..0000000 --- a/templates/cosmos/handler.go.tpl +++ /dev/null @@ -1,27 +0,0 @@ -;; go -package {{_file_name_}} - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/sonr-io/sonr/x/{{_file_name_}}/keeper" - "github.com/sonr-io/sonr/x/{{_file_name_}}/types" -) - -// NewHandler returns a handler for {{_file_name_}} module messages -func NewHandler(k keeper.Keeper) sdk.Handler { - msgServer := keeper.NewMsgServerImpl(k) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - {{_cursor_}} - default: - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - } - } -} diff --git a/templates/cosmos/keeper.go.tpl b/templates/cosmos/keeper.go.tpl deleted file mode 100644 index 7ab5b87..0000000 --- a/templates/cosmos/keeper.go.tpl +++ /dev/null @@ -1,39 +0,0 @@ -;; go -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sonr-io/sonr/x/{{_file_name_}}/types" -) - -type Keeper struct { - storeKey sdk.StoreKey - cdc codec.BinaryCodec - paramstore paramtypes.Subspace -} - -func NewKeeper( - cdc codec.BinaryCodec, - storeKey sdk.StoreKey, - ps paramtypes.Subspace, -) *Keeper { - // set KeyTable if it has not already been set - if !ps.HasKeyTable() { - ps = ps.WithKeyTable(types.ParamKeyTable()) - } - - return &Keeper{ - cdc: cdc, - storeKey: storeKey, - paramstore: ps, - } -} - -// Logger returns a module-specific logger. -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/{{_file_name_}}") -} - -{{_cursor_}} diff --git a/templates/cosmos/msg_server.go.tpl b/templates/cosmos/msg_server.go.tpl deleted file mode 100644 index e47ed0c..0000000 --- a/templates/cosmos/msg_server.go.tpl +++ /dev/null @@ -1,43 +0,0 @@ -;; go -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sonr-io/sonr/x/{{_file_name_}}/types" -) - -type msgServer struct { - Keeper -} - -// NewMsgServerImpl returns an implementation of the {{_camel_case_file_}} MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} -} - -var _ types.MsgServer = msgServer{} - -// {{_variable_}} implements types.MsgServer -func (k msgServer) {{_variable_}}(goCtx context.Context, msg *types.Msg{{_variable_}}) (*types.Msg{{_variable_}}Response, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Validate message - if err := msg.ValidateBasic(); err != nil { - return nil, err - } - - {{_cursor_}} - - // Emit event - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventType{{_variable_}}, - sdk.NewAttribute(types.AttributeKeyCreator, msg.Creator), - ), - ) - - return &types.Msg{{_variable_}}Response{}, nil -} diff --git a/templates/cosmos/query_server.go.tpl b/templates/cosmos/query_server.go.tpl deleted file mode 100644 index 447b96b..0000000 --- a/templates/cosmos/query_server.go.tpl +++ /dev/null @@ -1,36 +0,0 @@ -;; go -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sonr-io/sonr/x/{{_file_name_}}/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type queryServer struct { - Keeper -} - -// NewQueryServerImpl returns an implementation of the {{_camel_case_file_}} QueryServer interface -// for the provided Keeper. -func NewQueryServerImpl(keeper Keeper) types.QueryServer { - return &queryServer{Keeper: keeper} -} - -var _ types.QueryServer = queryServer{} - -// {{_variable_}} implements types.QueryServer -func (k queryServer) {{_variable_}}(goCtx context.Context, req *types.Query{{_variable_}}Request) (*types.Query{{_variable_}}Response, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - {{_cursor_}} - - return &types.Query{{_variable_}}Response{}, nil -} diff --git a/templates/proto/message.proto.tpl b/templates/proto/message.proto.tpl deleted file mode 100644 index bae979d..0000000 --- a/templates/proto/message.proto.tpl +++ /dev/null @@ -1,17 +0,0 @@ -;; proto -syntax = "proto3"; -package sonr.{{_file_name_}}.v1; - -option go_package = "github.com/sonr-io/sonr/x/{{_file_name_}}/types"; - -import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; -import "amino/amino.proto"; - -// {{_variable_}} defines the {{_variable_}} message -message {{_variable_}} { - option (gogoproto.equal) = true; - option (amino.name) = "sonr/{{_file_name_}}/{{_variable_}}"; - - {{_cursor_}} -} diff --git a/templates/proto/query.proto.tpl b/templates/proto/query.proto.tpl deleted file mode 100644 index 3d25446..0000000 --- a/templates/proto/query.proto.tpl +++ /dev/null @@ -1,29 +0,0 @@ -;; proto -syntax = "proto3"; -package sonr.{{_file_name_}}.v1; - -option go_package = "github.com/sonr-io/sonr/x/{{_file_name_}}/types"; - -import "gogoproto/gogo.proto"; -import "google/api/annotations.proto"; -import "cosmos/base/query/v1beta1/pagination.proto"; -import "cosmos/query/v1/query.proto"; - -// Query defines the gRPC querier service -service Query { - // {{_variable_}} queries the {{_variable_}} - rpc {{_variable_}}(Query{{_variable_}}Request) returns (Query{{_variable_}}Response) { - option (cosmos.query.v1.module_query_safe) = true; - option (google.api.http).get = "/sonr/{{_file_name_}}/v1/{{_variable_}}"; - } -} - -// Query{{_variable_}}Request is the request type for the Query/{{_variable_}} RPC method -message Query{{_variable_}}Request { - {{_cursor_}} -} - -// Query{{_variable_}}Response is the response type for the Query/{{_variable_}} RPC method -message Query{{_variable_}}Response { - -} diff --git a/templates/proto/tx.proto.tpl b/templates/proto/tx.proto.tpl deleted file mode 100644 index 91b2926..0000000 --- a/templates/proto/tx.proto.tpl +++ /dev/null @@ -1,30 +0,0 @@ -;; proto -syntax = "proto3"; -package sonr.{{_file_name_}}.v1; - -option go_package = "github.com/sonr-io/sonr/x/{{_file_name_}}/types"; - -import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; -import "cosmos/msg/v1/msg.proto"; -import "amino/amino.proto"; - -// Msg defines the {{_file_name_}} Msg service -service Msg { - option (cosmos.msg.v1.service) = true; - - // {{_variable_}} defines the {{_variable_}} RPC method - rpc {{_variable_}}(Msg{{_variable_}}) returns (Msg{{_variable_}}Response); -} - -// Msg{{_variable_}} defines the {{_variable_}} message -message Msg{{_variable_}} { - option (cosmos.msg.v1.signer) = "creator"; - option (amino.name) = "sonr/{{_file_name_}}/{{_variable_}}"; - - string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - {{_cursor_}} -} - -// Msg{{_variable_}}Response defines the {{_variable_}} response -message Msg{{_variable_}}Response {} diff --git a/templates/vite/api.ts.tpl b/templates/vite/api.ts.tpl deleted file mode 100644 index 2c5d0d6..0000000 --- a/templates/vite/api.ts.tpl +++ /dev/null @@ -1,58 +0,0 @@ -;; typescript -/** - * {{_camel_case_file_}} API Client - * @author {{_author_}} - * @created {{_date_}} - */ - -import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' - -// API Types -interface {{_camel_case_file_}}Data { - {{_cursor_}} -} - -// Query Keys -export const {{_file_name_}}Keys = { - all: ['{{_file_name_}}'] as const, - lists: () => [...{{_file_name_}}Keys.all, 'list'] as const, - list: (filters: string) => [...{{_file_name_}}Keys.lists(), { filters }] as const, - details: () => [...{{_file_name_}}Keys.all, 'detail'] as const, - detail: (id: string) => [...{{_file_name_}}Keys.details(), id] as const, -} - -// API Functions -async function fetch{{_camel_case_file_}}(id: string): Promise<{{_camel_case_file_}}Data> { - const response = await fetch(`/api/{{_file_name_}}/${id}`) - if (!response.ok) throw new Error('Failed to fetch {{_file_name_}}') - return response.json() -} - -async function create{{_camel_case_file_}}(data: Partial<{{_camel_case_file_}}Data>): Promise<{{_camel_case_file_}}Data> { - const response = await fetch('/api/{{_file_name_}}', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) - if (!response.ok) throw new Error('Failed to create {{_file_name_}}') - return response.json() -} - -// Hooks -export function use{{_camel_case_file_}}(id: string) { - return useQuery({ - queryKey: {{_file_name_}}Keys.detail(id), - queryFn: () => fetch{{_camel_case_file_}}(id), - }) -} - -export function useCreate{{_camel_case_file_}}() { - const queryClient = useQueryClient() - - return useMutation({ - mutationFn: create{{_camel_case_file_}}, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: {{_file_name_}}Keys.lists() }) - }, - }) -} diff --git a/templates/vite/component.tsx.tpl b/templates/vite/component.tsx.tpl deleted file mode 100644 index 85ef2f0..0000000 --- a/templates/vite/component.tsx.tpl +++ /dev/null @@ -1,22 +0,0 @@ -;; typescriptreact -/** - * {{_camel_case_file_}} Component - * @author {{_author_}} - * @created {{_date_}} - */ - -import { memo } from 'react' - -interface {{_camel_case_file_}}Props { - {{_cursor_}} -} - -export const {{_camel_case_file_}} = memo<{{_camel_case_file_}}Props>(({ }) => { - return ( -
- -
- ) -}) - -{{_camel_case_file_}}.displayName = '{{_camel_case_file_}}' diff --git a/templates/vite/hook.ts.tpl b/templates/vite/hook.ts.tpl deleted file mode 100644 index 3c42f2a..0000000 --- a/templates/vite/hook.ts.tpl +++ /dev/null @@ -1,24 +0,0 @@ -;; typescript -/** - * {{_camel_case_file_}} Hook - * @author {{_author_}} - * @created {{_date_}} - */ - -import { useState, useEffect } from 'react' - -interface Use{{_camel_case_file_}}Options { - {{_cursor_}} -} - -export function use{{_camel_case_file_}}(options?: Use{{_camel_case_file_}}Options) { - const [data, setData] = useState() - - useEffect(() => { - // Hook logic here - }, []) - - return { - data, - } -} diff --git a/templates/vite/page.tsx.tpl b/templates/vite/page.tsx.tpl deleted file mode 100644 index b02a39b..0000000 --- a/templates/vite/page.tsx.tpl +++ /dev/null @@ -1,23 +0,0 @@ -;; typescriptreact -/** - * {{_camel_case_file_}} Page Component - * @author {{_author_}} - * @created {{_date_}} - */ - -import { createFileRoute } from '@tanstack/react-router' - -export const Route = createFileRoute('/{{_file_name_}}')({ - component: {{_camel_case_file_}}Page, -}) - -function {{_camel_case_file_}}Page() { - {{_cursor_}} - - return ( -
-

{{_camel_case_file_}}

- -
- ) -} diff --git a/templates/vite/pages-function.ts.tpl b/templates/vite/pages-function.ts.tpl deleted file mode 100644 index edf9f23..0000000 --- a/templates/vite/pages-function.ts.tpl +++ /dev/null @@ -1,20 +0,0 @@ -;; typescript -/** - * Cloudflare Pages Function - {{_file_name_}} - * @author {{_author_}} - * @created {{_date_}} - */ - -interface Env { - // Add your environment bindings here -} - -export const onRequest: PagesFunction = async (context) => { - const { request, env, params } = context - - {{_cursor_}} - - return new Response(JSON.stringify({ success: true }), { - headers: { 'Content-Type': 'application/json' }, - }) -} diff --git a/templates/vite/worker.ts.tpl b/templates/vite/worker.ts.tpl deleted file mode 100644 index f73ef52..0000000 --- a/templates/vite/worker.ts.tpl +++ /dev/null @@ -1,23 +0,0 @@ -;; typescript -/** - * Cloudflare Worker - {{_file_name_}} - * @author {{_author_}} - * @created {{_date_}} - */ - -export interface Env { - // Add your environment bindings here - // Example: DB: D1Database -} - -export default { - async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise { - const url = new URL(request.url); - - {{_cursor_}} - - return new Response('Hello World!', { - headers: { 'Content-Type': 'text/plain' }, - }); - }, -} satisfies ExportedHandler;