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? |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
Hey @jiashengguo,
to not interrupt the normal document lifecycle, it would make sense to basically do the following:
onBuildPhase
listener on your document builder instance for theValidated
state (i.e. so that the callback runs after a document has been validated)references
of your document for unresolved references (i.e. those reference with theirerror
not being undefined)workspace/applyEdit
LSP endpoint available on theservices.lsp.Connection
object.Note that I would not recommend building such an automated solution due to false positives. Let's take the following fo…