VS Code extension แสดง preview ของ Go HTML template (Fiber/Gin/Echo/Chi) — คลิก control บนฟอร์มเพื่อกระโดดไป Go handler / route / JS function / struct field / SQL
Features
- Render
.html/.gohtml/.tmpl/.phpใน webview พร้อม CSS จากโปรเจกต์ (auto-detectweb/static,static,public/static, ฯลฯ) - Strip Go template syntax
{{...}}ให้แสดงเป็น⟨FieldName⟩แทน - PHP preview (NEW): ไฟล์
.phpที่มี HTML ปนอยู่ — strip โค้ด PHP ทิ้ง โดย<?= $user->name ?>/<?php echo $row['hn']; ?>แสดงเป็น⟨user.name⟩/⟨row.hn⟩ส่วน control flow (if/foreach) และ logic block หายไป เหลือ HTML เพียว ๆ - Laravel Blade preview + click-to-jump (NEW v0.8): ไฟล์
.blade.php—{{ $user->name }}/{!! ... !!}→⟨user.name⟩,{{ old('hn') }}→⟨hn⟩,@extends/@include→⟪tpl: x⟫@if/@foreach/@csrf/@errorฯลฯ หายไป เหลือ HTML (CSS@mediaใน<style>ไม่โดนแตะ){{ asset('css/app.css') }}→ โหลด CSS จากpublic/ให้, layout auto-detect ที่resources/views/layouts/- Submit form ที่
action="{{ route('patients.store') }}"→ กระโดดไปRoute::post(...)ในroutes/web.php→ chain ต่อไป method ใน Controller - คลิก
<input name="X">→ กระโดดไป$request->input('X')/request('X')/ key ในvalidate([...])
- PHP click-to-jump (NEW v0.7): คลิก control ใน preview ของไฟล์
.php→<input name="X">→ กระโดดไปบรรทัดที่อ่าน$_POST['X']/$_GET['X']/$_REQUEST['X']<form action="/save.php">→ กระโดดไปไฟล์save.phponclick="fn()"→ กระโดดไป JS function ใน<script>ของไฟล์.phpและ chain ต่อผ่านfetch('/api/x.php')ไปยังไฟล์ปลายทาง- Auto re-index เมื่อ save ไฟล์
.php
- คลิก
<input>,<select>,<textarea>,<button>,<form>→ กระโดดไป:- Direct reads (Fiber/Gin/Echo):
c.FormValue("X"),c.PostForm("X"),c.Form("X") - Query reads:
c.Query("X"),c.QueryParam("X") - Path params:
c.Params("X"),c.Param("X"),c.PathValue("X") - Struct fields by tag (NEW v0.5): กรณีใช้
c.BodyParser(&req)/c.ShouldBindJSON(&req)— extension จะเจอ field declaration ที่มี\json:"X"`` หรือ\form:"X"`` ตรงกัน - Routes:
r.Post("/path", h.Handler)→ resolve handler function declaration - Group chains (NEW v0.5):
app.Group("/api")→api.Group("/users")→users.Get("/")รวมเป็นGET /api/usersอัตโนมัติ - JS handlers: function/arrow function ที่ชื่อตรงกับ id ของ element หรือชื่อใน
onclick="X()" - Chain via JS → fetch URL → Go route → handler ที่มี SQL
- Direct reads (Fiber/Gin/Echo):
- Generic router variable (NEW v0.5): รองรับชื่อตัวแปรอะไรก็ได้ (
auth,protected,users,api, ฯลฯ) ไม่ใช่แค่r/app/router - รองรับ Fiber, Gin, Echo, Chi (heuristic regex)
- Auto rebuild Go index เมื่อ save
.gofile
Settings
| Key | Default | คำอธิบาย |
|---|---|---|
gumgoPreview.staticRoot |
web/static |
path ของ static assets |
gumgoPreview.templateRoot |
internal/templates |
path ของ template files |
gumgoPreview.layoutFile |
internal/templates/layouts/app.html |
layout file สำหรับ wrap partial templates |
gumgoPreview.framework |
auto |
web framework convention (fiber/gin/echo/chi/nethttp/auto) |
Usage
เปิดไฟล์ template (เช่น internal/templates/pages/patient_register.html) แล้ว:
- คลิก context menu icon บน editor title → GumGo: Preview Template
- หรือ
Ctrl+Shift+P→ GumGo: Preview Template - หรือคลิกขวาที่ไฟล์ใน Explorer → Open With... → GumGo Preview
Build
cd D:\VsCodeExtension\GumGoPreview
npm install
npm run build # development
npm run package # production (minified)
npx @vscode/vsce package --no-dependencies --allow-missing-repository --skip-license
code --install-extension gumgo-preview-0.1.0.vsix
ข้อจำกัด
- Static preview เท่านั้น — ค่าใน
{{.X}}แสดงเป็น⟨X⟩placeholder ไม่มี data จริง - Click-to-jump ใช้ regex-based indexer — แม่นมากกับ pattern ที่ใช้กันแพร่หลาย แต่ pattern ที่ซับซ้อนพิเศษอาจหลุด (เช่น routes ที่สร้าง path จากตัวแปร, struct binding ผ่าน middleware ที่ inject เอง)
- ยังไม่รองรับ
templ(Go templ language) — เฉพาะhtml/templateของ stdlib