What's the right way to insert code after validation? #880
|
For example, for the DomainModel, after user input Instead of showing the error of not finding a Comment, I would like to generate a Comment entity for the user if he hasn't done so. How should I achieve that? |
Replies: 1 comment 1 reply
|
Hey @jiashengguo, to not interrupt the normal document lifecycle, it would make sense to basically do the following:
Note that I would not recommend building such an automated solution due to false positives. Let's take the following for example: Once the user writes an invalid reference, it will automatically create a new entity in the text which might not be what the user wants, especially if it's only due to a typo. You should let the user decide whether they want to create an entity for that instead using code actions. You can see an example how to create code actions on linking errors here. |
Hey @jiashengguo,
to not interrupt the normal document lifecycle, it would make sense to basically do the following:
onBuildPhaselistener on your document builder instance for theValidatedstate (i.e. so that the callback runs after a document has been validated)referencesof your document for unresolved references (i.e. those reference with theirerrornot being undefined)workspace/applyEditLSP endpoint available on theservices.lsp.Connectionobject.Note that I would not recommend building such an automated solution due to false positives. Let's take the following fo…