Skip to content

Commit

Permalink
feat(lsp): non diagnostic errors creates an alert (fixes #1629) (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
gak authored Jun 7, 2024
1 parent 59e5d15 commit 90c41b9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func (s *Server) BuildStarted(dir string) {
})
}

// Post sends diagnostics to the client. err must be joined schema.Errors.
// Post sends diagnostics to the client.
func (s *Server) post(err error) {
errByFilename := make(map[string]errSet)
errUnspecified := []error{}

// Deduplicate and associate by filename.
for _, err := range ftlErrors.DeduplicateErrors(ftlErrors.UnwrapAll(err)) {
Expand All @@ -85,13 +86,16 @@ func (s *Server) post(err error) {
errByFilename[filename] = errSet{}
}
errByFilename[filename] = append(errByFilename[filename], ce)
} else {
errUnspecified = append(errUnspecified, err)
}
}

go publishErrors(errByFilename, s)
go publishPositionalErrors(errByFilename, s)
go publishUnspecifiedErrors(errUnspecified, s)
}

func publishErrors(errByFilename map[string]errSet, s *Server) {
func publishPositionalErrors(errByFilename map[string]errSet, s *Server) {
for filename, errs := range errByFilename {
var diagnostics []protocol.Diagnostic
for _, e := range errs {
Expand Down Expand Up @@ -135,6 +139,22 @@ func publishErrors(errByFilename map[string]errSet, s *Server) {
}
}

// publishUnspecifiedErrors sends non-positional errors to the client as alerts.
func publishUnspecifiedErrors(errUnspecified []error, s *Server) {
if s.glspContext == nil {
return
}

for _, err := range errUnspecified {
message := fmt.Sprintf("FTL Error: %s", err)

go s.glspContext.Notify(protocol.ServerWindowShowMessage, protocol.ShowMessageParams{
Type: protocol.MessageTypeError,
Message: message,
})
}
}

func (s *Server) publishDiagnostics(uri protocol.DocumentUri, diagnostics []protocol.Diagnostic) {
s.logger.Debugf("Publishing diagnostics for %s\n", uri)
if s.glspContext == nil {
Expand Down

0 comments on commit 90c41b9

Please sign in to comment.