Skip to content

Commit 98dc328

Browse files
committed
Do not evaluate the file on opening if it is empty
Signed-off-by: Jack Baldry <[email protected]>
1 parent ffb7509 commit 98dc328

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

server.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,19 @@ func (s *server) DidDeleteFiles(context.Context, *protocol.DeleteFilesParams) er
330330
func (s *server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) (err error) {
331331
defer s.publishDiagnostics(params.TextDocument.URI)
332332
doc := document{item: params.TextDocument}
333-
doc.ast, doc.err = jsonnet.SnippetToAST(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
334-
if doc.err != nil {
335-
return s.cache.put(doc)
336-
}
337-
symbols := analyseSymbols(doc.ast)
338-
if len(symbols) != 1 {
339-
panic("There should only be a single root symbol for an AST")
333+
if params.TextDocument.Text != "" {
334+
doc.ast, doc.err = jsonnet.SnippetToAST(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
335+
if doc.err != nil {
336+
return s.cache.put(doc)
337+
}
338+
symbols := analyseSymbols(doc.ast)
339+
if len(symbols) != 1 {
340+
panic("There should only be a single root symbol for an AST")
341+
}
342+
doc.symbols = symbols[0]
343+
// TODO(#12): Work out better way to invalidate the VM cache.
344+
doc.val, doc.err = s.vm.EvaluateAnonymousSnippet(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
340345
}
341-
doc.symbols = symbols[0]
342-
// TODO(#12): Work out better way to invalidate the VM cache.
343-
doc.val, doc.err = s.vm.EvaluateAnonymousSnippet(params.TextDocument.URI.SpanURI().Filename(), params.TextDocument.Text)
344346
return s.cache.put(doc)
345347
}
346348

0 commit comments

Comments
 (0)