Skip to content

Commit

Permalink
feat: post to language server from log stream
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell committed Apr 3, 2024
1 parent 812adb7 commit 9b48ffb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 43 deletions.
8 changes: 0 additions & 8 deletions buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ type schemaChange struct {
}

type Listener struct {
OnBuildComplete func(project Project, err error)
OnDeployComplete func(project Project, err error)
}

// Engine for building a set of modules.
Expand Down Expand Up @@ -370,9 +368,6 @@ func (e *Engine) buildAndDeploy(ctx context.Context, replicas int32, waitForDepl
}
if module, ok := project.(Module); ok {
err := Deploy(ctx, module, replicas, waitForDeployOnline, e.client)
if e.listener != nil && e.listener.OnDeployComplete != nil {
e.listener.OnDeployComplete(project, err)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -474,9 +469,6 @@ func (e *Engine) build(ctx context.Context, key ProjectKey, builtModules map[str
sch := &schema.Schema{Modules: maps.Values(combined)}

err := Build(ctx, sch, project)
if e.listener != nil && e.listener.OnBuildComplete != nil {
e.listener.OnBuildComplete(project, err)
}
if err != nil {
return err
}
Expand Down
15 changes: 2 additions & 13 deletions cmd/ftl/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
"github.com/TBD54566975/ftl/buildengine"
"github.com/TBD54566975/ftl/common/projectconfig"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/rpc"
"github.com/TBD54566975/ftl/lsp"
)
Expand Down Expand Up @@ -62,15 +63,11 @@ func (d *devCmd) Run(ctx context.Context, projConfig projectconfig.Config) error
var listener *buildengine.Listener
if d.RunLsp {
d.languageServer = lsp.NewServer(ctx)
listener = &buildengine.Listener{
OnBuildComplete: d.OnBuildComplete,
OnDeployComplete: d.OnDeployComplete,
}
ctx = log.ContextWithLogger(ctx, log.FromContext(ctx).AddSink(lsp.NewLogSink(d.languageServer)))
g.Go(func() error {
return d.languageServer.Run()
})
}

engine, err := buildengine.New(ctx, client, d.Dirs, d.External, buildengine.Parallelism(d.Parallelism), buildengine.WithListener(listener))
if err != nil {
return err
Expand All @@ -80,11 +77,3 @@ func (d *devCmd) Run(ctx context.Context, projConfig projectconfig.Config) error

return g.Wait()
}

func (d *devCmd) OnBuildComplete(project buildengine.Project, err error) {
d.languageServer.BuildComplete(project.Config().Dir, err)
}

func (d *devCmd) OnDeployComplete(project buildengine.Project, err error) {
d.languageServer.DeployComplete(project.Config().Dir, err)
}
17 changes: 17 additions & 0 deletions lsp/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ func toGLSPLevel(l log.Level) commonlog.Level {
return commonlog.Debug
}
}

type LogSink struct {
server *Server
}

var _ log.Sink = (*LogSink)(nil)

func NewLogSink(server *Server) *LogSink {
return &LogSink{server: server}
}

func (l *LogSink) Log(entry log.Entry) error {
if entry.Level == log.Error {
l.server.post(entry.Error)
}
return nil
}
22 changes: 0 additions & 22 deletions lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewServer(ctx context.Context) *Server {
logger: *log.FromContext(ctx),
}
handler.Initialize = server.initialize()
// handler.TextDocumentDidOpen = server.textDocumentDidOpen()
handler.TextDocumentDidChange = server.textDocumentDidChange()
return server
}

Expand All @@ -58,18 +56,6 @@ func (s *Server) Run() error {

type errSet map[string]schema.Error

func (s *Server) BuildComplete(dir string, err error) {
if err != nil {
s.post(err)
}
}

func (s *Server) DeployComplete(dir string, err error) {
if err != nil {
s.post(err)
}
}

// Post sends diagnostics to the client. err must be joined schema.Errors.
func (s *Server) post(err error) {
errByFilename := make(map[string]errSet)
Expand Down Expand Up @@ -137,14 +123,6 @@ func (s *Server) initialize() protocol.InitializeFunc {
}, nil
}
}

func (s *Server) textDocumentDidChange() protocol.TextDocumentDidChangeFunc {
return func(context *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
// s.refreshDiagnosticsOfDocument(params.TextDocument.URI)
return nil
}
}

func (s *Server) clearDiagnosticsOfDocument(uri protocol.DocumentUri) {
go func() {
go s.glspContext.Notify(protocol.ServerTextDocumentPublishDiagnostics, protocol.PublishDiagnosticsParams{
Expand Down

0 comments on commit 9b48ffb

Please sign in to comment.