package lukazitnik.jshint;

import java.util.List;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.netbeans.modules.editor.NbEditorDocument;
import org.netbeans.modules.editor.NbEditorUtilities;
import org.openide.util.Cancellable;

public class LintingThread extends Thread {

    private final NbEditorDocument d;
    private final ProgressHandle progressHandle;

    public LintingThread(NbEditorDocument d) {
        this.d = d;
        this.setName("Linting Thread");
        String fileName = NbEditorUtilities.getFileObject(d).getNameExt();
        progressHandle = ProgressHandleFactory.createHandle("Linting " + fileName, new Cancellable() {

            @Override
            public boolean cancel() {
                LintingThread.this.stopAndFinishProgressHandle();
                return true;
            }
        });
    }

    @Override
    public void run() {
        progressHandle.start();

        JSHint jshint = JSHint.instance;
        final List<JSHintError> errors = jshint.lint(d);

        progressHandle.finish();

        SwingUtilities.invokeLater(new Annotator(d, errors));
    }

    public void stopAndFinishProgressHandle() {
        stop();
        progressHandle.finish();
    }
}

@@ -1252,24 +1252,424 @@
 ssHandle() %7B
+%0A%0A        // Shouldn't be a problem, only errors property of the JS function changes.%0A        // If this turns out to be wrong, RequestProcessor.Task.cancel() can be used%0A        // instead, though that would incur poorer performance -- cancel() would%0A        // remove not yet running tasks from the queue, but the running task would%0A        // have to finish if it's interruption cannot be handled.
 %0A        sto
@@ -1669,24 +1669,25 @@
     stop();%0A
+%0A
         prog

add comment