Skip to content

Commit

Permalink
feat(lsp): non diagnostic errors creates an alert
Browse files Browse the repository at this point in the history
  • Loading branch information
gak committed Jun 6, 2024
1 parent 18c2058 commit b449f9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
import * as vscode from "vscode"
import { FTLStatus } from "./status"
import { checkMinimumVersion, getFTLVersion, getProjectOrWorkspaceRoot, isFTLRunning, resolveFtlPath } from "./config"
import path from "path"

export const MIN_FTL_VERSION = '0.169.0'

const clientName = "ftl languge server"
const clientName = "ftl language server"
const clientId = "ftl"
let client: LanguageClient
let statusBarItem: vscode.StatusBarItem
Expand Down
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 b449f9b

Please sign in to comment.