No Longer Store Diagnostics in CompilationState
#35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the extension directly uses
CompilationState
(ast, files, diagnostics) fromslicec
.This PR adds a new type to replace it:
CompilationData
. This type only holds (ast, files).It does this to simplify how we get, and publish diagnostics.
Currently:
ConfigurationSet
, it compiles.Usually, we aren't ready to publish diagnostics at this point, so we need to temporarily store them, just for a bit.
CompilationState
has a requireddiagnostics
field. When we're ready to publish diagnostics, we usemem::take
totake the diagnostics from the state and publish them. This means we have to be careful to only call this after freshly compiling (otherwise there's nothing to take), and make sure we don't touch
diagnostics
afterwards (since it was taken).So, it being a required field is a little strange. 99% of the time it's actually been taken out.
I also think it's a little strange that just making a
Configuration
triggers a compilation.That's pretty heavy for a constructor, and I'd expect it to be a different function you call on it.
CompilationData
solves these problems:trigger_compilation
.So, now we create the
CompilationData
, then, when we're actually ready to compile and report diagnostics,we call
trigger_compilation
. No moremem::take
, no more hackily storing the diagnostics temporarily.It also has the side-benefit of centralizing where we compile.
Before this PR, we call
slicec::compile_from...
in 3 places. Now it's only called fromtrigger_compilation
.