Skip to content

Commit

Permalink
Do not evaluate the file on opening if it is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Baldry <[email protected]>
  • Loading branch information
jdbaldry committed Oct 29, 2021
1 parent ffb7509 commit 98dc328
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,19 @@ func (s *server) DidDeleteFiles(context.Context, *protocol.DeleteFilesParams) er
func (s *server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) (err error) {
defer s.publishDiagnostics(params.TextDocument.URI)
doc := document{item: params.TextDocument}
doc.ast, doc.err = jsonnet.SnippetToAST(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
if doc.err != nil {
return s.cache.put(doc)
}
symbols := analyseSymbols(doc.ast)
if len(symbols) != 1 {
panic("There should only be a single root symbol for an AST")
if params.TextDocument.Text != "" {
doc.ast, doc.err = jsonnet.SnippetToAST(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
if doc.err != nil {
return s.cache.put(doc)
}
symbols := analyseSymbols(doc.ast)
if len(symbols) != 1 {
panic("There should only be a single root symbol for an AST")
}
doc.symbols = symbols[0]
// TODO(#12): Work out better way to invalidate the VM cache.
doc.val, doc.err = s.vm.EvaluateAnonymousSnippet(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
}
doc.symbols = symbols[0]
// TODO(#12): Work out better way to invalidate the VM cache.
doc.val, doc.err = s.vm.EvaluateAnonymousSnippet(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
return s.cache.put(doc)
}

Expand Down

0 comments on commit 98dc328

Please sign in to comment.