Skip to content

Commit 5ed3282

Browse files
authored
maint: Improve lsp errors, run gofmt (#24)
Improve lsp errors, run gofmt
1 parent d661f1e commit 5ed3282

File tree

9 files changed

+445
-428
lines changed

9 files changed

+445
-428
lines changed

gwirl-lsp/server.go

+23-36
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ func (s *GwirlLspServer) Handle() {
247247
case lsp.MethodTextDocumentHover:
248248
go handleRequest[lsp.HoverParams, *lsp.Hover](s, method, s.Hover, s.context, bytes)
249249
default:
250-
s.logf("Not handling method \"%s\"", method)
251250
}
252251
}
253252
}
@@ -514,27 +513,12 @@ func (s *GwirlLspServer) DidChange(ctx context.Context, params *lsp.DidChangeTex
514513

515514
res := s.parser.Parse(s.fileContents[params.TextDocument.URI], params.TextDocument.URI.Filename())
516515

517-
diagnostics := make([]lsp.Diagnostic, len(res.Errors), len(res.Errors))
518-
for i, e := range res.Errors {
519-
s.logf("error: %v", e)
520-
line := uint32(e.Line())
521-
column := uint32(e.Column())
522-
d := lsp.Diagnostic{
523-
Range: lsp.Range{
524-
Start: lsp.Position{Line: line, Character: column},
525-
End: lsp.Position{Line: line, Character: column},
526-
},
527-
Severity: lsp.DiagnosticSeverityError,
528-
Source: "gwirl-lsp",
529-
Message: e.String(),
530-
}
531-
diagnostics[i] = d
532-
}
516+
diagnostics := createDiagnosticsFromErrors(res.Errors)
533517

534-
s.sendNotification("textDocument/publishDiagnostics", lsp.PublishDiagnosticsParams{
535-
Diagnostics: diagnostics,
536-
URI: params.TextDocument.URI,
537-
})
518+
s.sendNotification("textDocument/publishDiagnostics", lsp.PublishDiagnosticsParams{
519+
Diagnostics: diagnostics,
520+
URI: params.TextDocument.URI,
521+
})
538522

539523
return nil
540524
}
@@ -562,21 +546,7 @@ func (s *GwirlLspServer) DidOpen(ctx context.Context, params *lsp.DidOpenTextDoc
562546

563547
res := s.parser.Parse(params.TextDocument.Text, params.TextDocument.URI.Filename())
564548

565-
diagnostics := make([]lsp.Diagnostic, len(res.Errors), len(res.Errors))
566-
for i, e := range res.Errors {
567-
line := uint32(e.Line())
568-
column := uint32(e.Column())
569-
d := lsp.Diagnostic{
570-
Range: lsp.Range{
571-
Start: lsp.Position{Line: line, Character: column},
572-
End: lsp.Position{Line: line, Character: column},
573-
},
574-
Severity: lsp.DiagnosticSeverityError,
575-
Source: "gwirl-lsp",
576-
Message: e.String(),
577-
}
578-
diagnostics[i] = d
579-
}
549+
diagnostics := createDiagnosticsFromErrors(res.Errors)
580550

581551
s.sendNotification("textDocument/publishDiagnostics", lsp.PublishDiagnosticsParams{
582552
Diagnostics: diagnostics,
@@ -725,3 +695,20 @@ func (s *GwirlLspServer) Moniker(ctx context.Context, params *lsp.MonikerParams)
725695
func (s *GwirlLspServer) Request(ctx context.Context, method string, params interface{}) (result interface{}, err error) {
726696
return nil, nil
727697
}
698+
699+
func createDiagnosticsFromErrors(errors []parser.ParseError) []lsp.Diagnostic {
700+
diagnostics := make([]lsp.Diagnostic, len(errors), len(errors))
701+
for i, e := range errors {
702+
d := lsp.Diagnostic{
703+
Range: lsp.Range{
704+
Start: ParserPosToLspPos(e.Start),
705+
End: ParserPosToLspPos(e.End),
706+
},
707+
Severity: lsp.DiagnosticSeverityError,
708+
Source: "gwirl-lsp",
709+
Message: e.Err,
710+
}
711+
diagnostics[i] = d
712+
}
713+
return diagnostics
714+
}

gwirl.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import (
77
)
88

99
type TemplateBuilder struct {
10-
strings.Builder
10+
strings.Builder
1111
}
1212

13-
// Writes the
13+
// Writes the
1414
func WriteEscapedHTML(builder *TemplateBuilder, value interface{}) {
15-
builder.WriteString(html.HTMLEscapeString(fmt.Sprintf("%v", value)))
15+
builder.WriteString(html.HTMLEscapeString(fmt.Sprintf("%v", value)))
1616
}
1717

1818
func WriteRawHTML(builder *TemplateBuilder, value interface{}) {
19-
builder.WriteString(fmt.Sprintf("%v", value))
19+
builder.WriteString(fmt.Sprintf("%v", value))
2020
}
21-

0 commit comments

Comments
 (0)