mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
deactivate gdsl on VFS contents change
take the gdsl text from VFS, not PSI
This commit is contained in:
@@ -20,7 +20,9 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -37,7 +39,9 @@ public class GroovyDslAnnotator implements Annotator {
|
||||
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
|
||||
if (psiElement instanceof GroovyFile) {
|
||||
final VirtualFile vfile = ((GroovyFile)psiElement).getVirtualFile();
|
||||
if (vfile != null && "gdsl".equals(vfile.getExtension()) && !GroovyDslFileIndex.isActivated(vfile)) {
|
||||
Document document = ((GroovyFile)psiElement).getViewProvider().getDocument();
|
||||
if (vfile != null && "gdsl".equals(vfile.getExtension()) &&
|
||||
(!GroovyDslFileIndex.isActivated(vfile) || document != null && FileDocumentManager.getInstance().isDocumentUnsaved(document))) {
|
||||
final Annotation annotation = holder.createWarningAnnotation(psiElement, "DSL descriptor file has been changed and isn't currently executed. Click to activate it back.");
|
||||
annotation.setFileLevelAnnotation(true);
|
||||
annotation.registerFix(new IntentionAction() {
|
||||
@@ -56,6 +60,7 @@ public class GroovyDslAnnotator implements Annotator {
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
GroovyDslFileIndex.activateUntilModification(vfile);
|
||||
DaemonCodeAnalyzer.getInstance(project).restart();
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
@@ -34,6 +31,9 @@ import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileAdapter;
|
||||
import com.intellij.openapi.vfs.VirtualFileEvent;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.newvfs.FileAttribute;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiModificationTrackerImpl;
|
||||
@@ -93,6 +93,19 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
|
||||
private final EnumeratorStringDescriptor myKeyDescriptor = new EnumeratorStringDescriptor();
|
||||
private static final byte[] ENABLED_FLAG = new byte[]{(byte)239};
|
||||
|
||||
public GroovyDslFileIndex() {
|
||||
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
|
||||
|
||||
@Override
|
||||
public void contentsChanged(VirtualFileEvent event) {
|
||||
if (event.getFileName().endsWith(".gdsl")) {
|
||||
disableFile(event.getFile());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public ID<String, Void> getName() {
|
||||
return NAME;
|
||||
}
|
||||
@@ -132,17 +145,6 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
|
||||
}
|
||||
|
||||
public static void activateUntilModification(final VirtualFile vfile) {
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(vfile);
|
||||
if (document != null) {
|
||||
document.addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
public void beforeDocumentChange(DocumentEvent e) {
|
||||
disableFile(vfile);
|
||||
document.removeDocumentListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
ENABLED.writeAttributeBytes(vfile, ENABLED_FLAG);
|
||||
}
|
||||
@@ -237,15 +239,10 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
|
||||
}
|
||||
}
|
||||
|
||||
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vfile);
|
||||
if (psiFile == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final long stamp = vfile.getModificationStamp();
|
||||
final GroovyDslExecutor cached = getCachedExecutor(vfile, stamp);
|
||||
if (cached == null) {
|
||||
scheduleParsing(queue, project, vfile, stamp, psiFile.getText());
|
||||
scheduleParsing(queue, project, vfile, stamp, LoadTextUtil.loadText(vfile).toString());
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user