User48591
User48591

Reputation: 301

How to trigger validation after executing a quickfix?

I have implemented a quickfix for a validation warning that does a certain action, fixing the cause of the warning. But the warning does not go away until I edit the file, which triggers a new validation cycle.

Is there a way to trigger the validation after the quickfix is executed, preferably only for the @Check-annotated method that caused the warning in the first place.

invalid file warning

After I go for the quick fix, a file is created with that name but, as I said above, the warning only goes away after I edit the file, which triggers the validation again.

Here is the code.

Validation:

@Check
def checkFileExists(FileType file)
{
    if (!fileExists(file))
    {
        warning('This file does not exist.', TestsPackage.Literals.FILE_TYPE__FILE_NAME, INVALID_FILE)
    }
}

Quickfix:

@Fix(TestsValidator.INVALID_FILE)
def createFile(Issue issue, IssueResolutionAcceptor acceptor)
{
    acceptor.accept(issue, "Create file", "", null,
    new ISemanticModification()
    {
        override apply(EObject element, IModificationContext context)
        throws Exception {
            {
                val file = element as FileType
                createFile(file)
            }
        }
    });
}

Upvotes: 0

Views: 149

Answers (1)

Christian Dietrich
Christian Dietrich

Reputation: 11868

maybe you can try something like

@Fix(MyDslValidator.INVALID_NAME)
def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [
        context |
        val xtextDocument = context.xtextDocument
        val firstLetter = xtextDocument.get(issue.offset, 1)
        xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase)
        (xtextDocument as XtextDocument).validationJob.schedule
    ]
}

Upvotes: 1

Related Questions