Skip to content

Commit

Permalink
chore: fix minor linter nits
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Mar 6, 2023
1 parent 73c650a commit c2d18aa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
6 changes: 4 additions & 2 deletions cmd/templ/lspcmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Run(args Arguments) error {
}()
if args.PPROF {
go func() {
http.ListenAndServe("localhost:9999", nil)
_ = http.ListenAndServe("localhost:9999", nil)
}()
}
go func() {
Expand Down Expand Up @@ -67,7 +67,9 @@ func run(ctx context.Context, args Arguments) (err error) {
os.Exit(1)
}
}
defer log.Sync()
defer func() {
_ = log.Sync()
}()
log.Info("lsp: starting up...")
defer func() {
if r := recover(); r != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/templ/lspcmd/proxy/documentcontents.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (d *Document) Overwrite(r *lsp.Range, with string) {
d.remove(int(r.Start.Line), int(r.End.Line+1))
}
d.insert(int(r.Start.Line), withLines)
return
}

func (d *Document) String() string {
Expand Down
21 changes: 9 additions & 12 deletions cmd/templ/lspcmd/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ func NewServer(log *zap.Logger, target lsp.Server, cache *SourceMapCache) (s *Se

// updatePosition maps positions and filenames from source templ files into the target *.go files.
func (p *Server) updatePosition(templURI lsp.DocumentURI, current lsp.Position) (goURI lsp.DocumentURI, updated lsp.Position) {
goURI = templURI
updated = current
log := p.Log.With(zap.String("uri", string(templURI)))
var isTemplFile bool
isTemplFile, goURI = convertTemplToGoURI(templURI)
if !isTemplFile {
return
if isTemplFile, goURI = convertTemplToGoURI(templURI); !isTemplFile {
return templURI, current
}
sourceMap, ok := p.SourceMapCache.Get(string(templURI))
if !ok {
Expand All @@ -65,15 +62,15 @@ func (p *Server) updatePosition(templURI lsp.DocumentURI, current lsp.Position)
}
// Map from the source position to target Go position.
to, ok := sourceMap.TargetPositionFromSource(current.Line, current.Character)
if ok {
log.Info("updatePosition: found", zap.String("fromTempl", fmt.Sprintf("%d:%d", current.Line, current.Character)),
zap.String("toGo", fmt.Sprintf("%d:%d", to.Line, to.Col)))
updated.Line = to.Line
updated.Character = to.Col
} else {
if !ok {
log.Info("updatePosition: not found", zap.String("from", fmt.Sprintf("%d:%d", current.Line, current.Character)))
return templURI, current
}
return
log.Info("updatePosition: found", zap.String("fromTempl", fmt.Sprintf("%d:%d", current.Line, current.Character)),
zap.String("toGo", fmt.Sprintf("%d:%d", to.Line, to.Col)))
updated.Line = to.Line
updated.Character = to.Col
return goURI, updated
}

func (p *Server) convertTemplRangeToGoRange(templURI lsp.DocumentURI, input lsp.Range) (output lsp.Range) {
Expand Down
20 changes: 10 additions & 10 deletions example/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestHeader(t *testing.T) {
// Pipe the rendered template into goquery.
r, w := io.Pipe()
go func() {
headerTemplate("Posts").Render(context.Background(), w)
w.Close()
_ = headerTemplate("Posts").Render(context.Background(), w)
_ = w.Close()
}()
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
Expand All @@ -40,8 +40,8 @@ func TestFooter(t *testing.T) {
// Pipe the rendered template into goquery.
r, w := io.Pipe()
go func() {
footerTemplate().Render(context.Background(), w)
w.Close()
_ = footerTemplate().Render(context.Background(), w)
_ = w.Close()
}()
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
Expand All @@ -61,8 +61,8 @@ func TestFooter(t *testing.T) {
func TestNav(t *testing.T) {
r, w := io.Pipe()
go func() {
navTemplate().Render(context.Background(), w)
w.Close()
_ = navTemplate().Render(context.Background(), w)
_ = w.Close()
}()
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
Expand All @@ -77,8 +77,8 @@ func TestNav(t *testing.T) {
func TestHome(t *testing.T) {
r, w := io.Pipe()
go func() {
home().Render(context.Background(), w)
w.Close()
_ = home().Render(context.Background(), w)
_ = w.Close()
}()
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
Expand Down Expand Up @@ -110,8 +110,8 @@ func TestPosts(t *testing.T) {
}
r, w := io.Pipe()
go func() {
posts(testPosts).Render(context.Background(), w)
w.Close()
_ = posts(testPosts).Render(context.Background(), w)
_ = w.Close()
}()
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,11 @@ func (g *generator) writeBlockTemplElementExpression(indentLevel int, n parser.T
}

func (g *generator) writeSelfClosingTemplElementExpression(indentLevel int, n parser.TemplElementExpression) (err error) {
var r parser.Range
if r, err = g.w.WriteIndent(indentLevel, `err = `); err != nil {
if _, err = g.w.WriteIndent(indentLevel, `err = `); err != nil {
return err
}
// Template expression.
var r parser.Range
if r, err = g.w.Write(n.Expression.Value); err != nil {
return err
}
Expand All @@ -656,11 +656,11 @@ func (g *generator) writeCallTemplateExpression(indentLevel int, n parser.CallTe
if _, err = g.w.WriteIndent(indentLevel, "// CallTemplate\n"); err != nil {
return err
}
var r parser.Range
if r, err = g.w.WriteIndent(indentLevel, `err = `); err != nil {
if _, err = g.w.WriteIndent(indentLevel, `err = `); err != nil {
return err
}
// Template expression.
var r parser.Range
if r, err = g.w.Write(n.Expression.Value); err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions parser/v2/elementparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (p boolExpressionAttributeParser) Parse(pi parse.Input) parse.Result {
var r BoolExpressionAttribute

start := pi.Index()
from := NewPositionFromInput(pi)
pr := whitespaceParser(pi)
if !pr.Success {
return pr
Expand All @@ -182,7 +181,7 @@ func (p boolExpressionAttributeParser) Parse(pi parse.Input) parse.Result {
}

// Once we have a prefix, we must have an expression that returns a template.
from = NewPositionFromInput(pi)
from := NewPositionFromInput(pi)
pr = exp.Parse(pi)
if pr.Error != nil && pr.Error != io.EOF {
return pr
Expand Down Expand Up @@ -212,7 +211,6 @@ func (p expressionAttributeParser) Parse(pi parse.Input) parse.Result {
var r ExpressionAttribute

start := pi.Index()
from := NewPositionFromInput(pi)
pr := whitespaceParser(pi)
if !pr.Success {
return pr
Expand All @@ -237,7 +235,7 @@ func (p expressionAttributeParser) Parse(pi parse.Input) parse.Result {
}

// Once we've seen a expression prefix, read until the tag end.
from = NewPositionFromInput(pi)
from := NewPositionFromInput(pi)
pr = exp.Parse(pi)
if pr.Error != nil && pr.Error != io.EOF {
return pr
Expand Down

0 comments on commit c2d18aa

Please sign in to comment.