gotmpls

module
v0.0.0-...-c9c0277 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2025 License: Apache-2.0

README ΒΆ

Go Template Types VSCode Extension πŸš€

A powerful Language Server Protocol (LSP) implementation for Go templates with type checking and advanced features.

                  +------------------+
                  |   VSCode/Editor  |
                  +--------+---------+
                           |
                           | LSP Protocol
                           |
                  +--------+---------+
                  |  Template LSP    |
                  |     Server       |
                  +--------+---------+
                           |
             +------------+------------+
             |                        |
    +--------+--------+     +--------+--------+
    |   Go Template   |     |   Type System   |
    |     Parser      |     |    Analyzer     |
    +----------------+      +----------------+

Features 🌟

  • 🎯 Go template parsing and validation
  • πŸ” Type checking for template variables
  • πŸ’‘ Intelligent code completion
  • πŸ“ Hover information
  • 🎨 Semantic token highlighting
  • πŸ› Error diagnostics
  • πŸ”„ Live template validation

Semantic Token Support 🎨

The extension provides rich semantic highlighting for:

{{ .Name }}     // Variable access
{{ .GetAge }}   // Method calls
{{ if .Ready }} // Keywords
{{ range . }}   // Block delimiters

Supported token types:

  • Delimiters ({{, }})
  • Functions
  • Variables
  • Types
  • Strings
  • Comments
  • Keywords
  • Operators

Installation πŸ“¦

  1. Install the extension from VSCode marketplace
  2. Make sure you have Go installed
  3. Open a workspace with Go templates

Usage πŸ’»

  1. Create a Go template file (.tmpl or .gotmpl)
  2. Add type annotations:
    {{- /*gotype: mypackage.MyType*/ -}}
    {{ .Field }}
    
  3. Enjoy rich IDE features!

Development πŸ› οΈ

Prerequisites
  • Go 1.21+
  • VSCode
Building
# Install dependencies
go mod tidy

# Run tests
go test ./...

# Build the extension
task build
Architecture πŸ—οΈ
graph TD
    A[Editor] -->|LSP| B[LSP Server]
    B --> C[Template Parser]
    B --> D[Type Checker]
    C --> E[AST]
    D --> F[Go Types]
    E --> G[Semantic Tokens]
    F --> H[Type Information]

Contributing 🀝

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License πŸ“„

MIT License - see LICENSE file for details

Directories ΒΆ

Path Synopsis
cmd
gotmpls command
gotmpls-wasm command
stdio-proxy command
gen
pkg
ast
hover
Package hover provides functionality for generating hover information.
Package hover provides functionality for generating hover information.
lsp
lsp/protocol/generator command
The generate command generates Go declarations from VSCode's description of the Language Server Protocol.
The generate command generates Go declarations from VSCode's description of the Language Server Protocol.
lsp/semtok
The semtok package provides an encoder for LSP's semantic tokens.
The semtok package provides an encoder for LSP's semantic tokens.
position
Package position provides utilities for handling text positions and ranges in Go template files.
Package position provides utilities for handling text positions and ranges in Go template files.
semtok
Package semtok provides semantic token support for the Go template language server.
Package semtok provides semantic token support for the Go template language server.
std/internal/fmtsort
Package fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages.
Package fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages.
std/text/template
Package template implements data-driven templates for generating textual output.
Package template implements data-driven templates for generating textual output.
std/text/template/parse
Package parse builds parse trees for templates as defined by text/template and html/template.
Package parse builds parse trees for templates as defined by text/template and html/template.
tools module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL