Skip to content

Commit

Permalink
Diagnostics for TTCN-3 syntax errors (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnnblaser committed Jun 29, 2023
1 parent 1646075 commit 4c79c6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/lsp/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/nokia/ntt/internal/fs"
"github.com/nokia/ntt/internal/lsp/protocol"
"github.com/nokia/ntt/ttcn3"
"github.com/nokia/ntt/ttcn3/syntax"
)

Expand Down Expand Up @@ -34,11 +35,21 @@ func (s *Server) Diagnose(uris ...protocol.DocumentURI) {
defer s.syncDiagnostics()

// TODO(5nord): Run linter against uris
for _, uri := range uris {
s.client.PublishDiagnostics(context.TODO(), &protocol.PublishDiagnosticsParams{
Diagnostics: make([]protocol.Diagnostic, 0),
URI: uri,
})
tree := ttcn3.ParseFile(string(uri))
if err := tree.Err; err != nil {
s.reportError(err)
}
}
}

func (s *Server) reportError(err error) {
var (
serr *syntax.Error
serr syntax.Error
merr *multierror.Error
)

Expand Down Expand Up @@ -73,7 +84,7 @@ func (s *Server) syncDiagnostics() {
for k, v := range s.diags {
s.client.PublishDiagnostics(context.TODO(), &protocol.PublishDiagnosticsParams{
Diagnostics: v,
URI: protocol.URIFromPath(k),
URI: protocol.DocumentURI(k),
})
}
}
1 change: 1 addition & 0 deletions internal/lsp/text_synchronization.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (s *Server) didChange(ctx context.Context, params *protocol.DidChangeTextDo
}

s.db.Index(uri)
s.Diagnose(params.TextDocument.URI)
return nil
}

Expand Down

0 comments on commit 4c79c6f

Please sign in to comment.