-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored document builder and affected analysis #1094
Conversation
1f19308
to
6bfd0cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels very heavy-handed and workaround-y. I don't think that the document should know about ephemeral build information (aside from its own state). I can also imagine that this property being set only once per completed build might lead to inconsistencies when multiple builds with different options are started. Maybe you want none
to override all
.
I would much rather like to see a change in BuildOptions.validationChecks
to include a only-open
value that only performs validation on files that are in the TextDocuments
service. And use that as the default for the textDocument/open
request we receive from the language client.
I moved the build state to DocumentBuilder and added validation options. Edit: I improved the API again and am adding tests. |
I used this opportunity to add tests for ValidationRegistry, DocumentValidator and DocumentBuilder (there weren't any). Edit: I updated the PR description to capture the new approach and full set of changes. |
d27f5bc
to
e261dec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few minor suggestions, no major objections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After rethinking my initial restraint to approve this, I'm happy with the new design. I'm sure there's still some space to iterate on the details, but this works well for now 👍
We had a longer (offline) discussion about this and decided that this needs another small refactoring
a469e34
to
f6a0667
Compare
f6a0667
to
71a89e4
Compare
I changed where the The new options merging logic in the |
// 4. Index references | ||
await this.runCancelable(documents, DocumentState.IndexedReferences, cancelToken, doc => | ||
this.indexManager.updateReferences(doc, cancelToken) | ||
); | ||
// 5. Validation | ||
const validateDocs = documents.filter(doc => this.shouldValidate(doc, options)); | ||
await this.runCancelable(validateDocs, DocumentState.Validated, cancelToken, doc => | ||
const toBeValidated = documents.filter(doc => this.shouldValidate(doc)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If shouldValidate
returns false
the document will never reach the Validated state. This state is checked in Line 113. Does that mean that the custom implementation inside the shouldValidate
should take care about setting the build state? If so we should add this information to the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the document state is set in runCancelable
(line 282). Custom implementations of shouldValidate
don't need to check or modify that property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toBeValidated
will not contain the document for that shouldValidate
returns false. For this document runCancelable
will not be called. Or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so the state won't be set to Validated, but that's fine. The check you mentioned in line 113 is only for documents where validation is already partially done.
protected async buildDocuments(documents: LangiumDocument[], options: BuildOptions, cancelToken: CancellationToken): Promise<void> { | ||
this.prepareBuild(documents, options); | ||
// 0. Parse content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we numerate the phases in the comments using the Document State numbers?
- Parse content => Parsed = 1
... - Validation => Validated = 6
I believe it will help to better understand what is going on when debugging here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the current numbering makes sense because it expresses that document of that state will be included in each phase. Example: documents with state Changed = 0 are included in the "Parse content" phase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
This PR fixes two issues that have not been noticed until recently:
DefaultDocumentBuilder.collectDocuments
includes all documents for whichstate < DocumentState.Validated
.didOpen
notification, which triggers an update of the respectiveTextDocument
(that's the standard behavior ofTextDocuments
provided by Microsoft).DocumentBuilder
for the initial build are now continued with the newBuildOptions
, which enable validation.The issues are fixed with the following changes:
DocumentBuilder
tracks the state of building (completed or not), including the last used build options.Additional improvements:
IndexManager
and improve performance with large workspaces.initialBuildOptions
property toWorkspaceManager
to control validation for the initial build.updateBuildOptions
property toDocumentBuilder
to control validation for updates (document changes).'fast'
(default) and'slow'
. You can set the category when you register a record of validation checks. The category can be selected in the build options. If no category is specified, all checks are executed.'built-in'
validation category is enabled.state
of the document is always set by the document builder