Vladimir Schneider 77a019842c change FindUsages getWordScanner not to be static.
If it is static then there are multi-threading issues. When indexing multiple threads are running and overwriting the lexer state that the word scanner uses.

I copied the SimplePlugin find usages class and spent hours chasing index out range bugs. I also noticed that the SimplePlugin which I have installed in my plugin dev environment would once in a while cause an exception but I did not pay it much attention. The static word scanner is the source.
2015-09-16 02:06:53 -04:00

63 lines
1.8 KiB
Java

package com.simpleplugin;
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
import com.intellij.lang.cacheBuilder.WordsScanner;
import com.intellij.lang.findUsages.FindUsagesProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.tree.TokenSet;
import com.simpleplugin.psi.SimpleProperty;
import com.simpleplugin.psi.SimpleTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleFindUsagesProvider implements FindUsagesProvider {
@Nullable
@Override
public WordsScanner getWordsScanner() {
return new DefaultWordsScanner(new SimpleLexerAdapter(),
TokenSet.create(SimpleTypes.KEY), TokenSet.create(SimpleTypes.COMMENT), TokenSet.EMPTY);;
}
@Override
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
return psiElement instanceof PsiNamedElement;
}
@Nullable
@Override
public String getHelpId(@NotNull PsiElement psiElement) {
return null;
}
@NotNull
@Override
public String getType(@NotNull PsiElement element) {
if (element instanceof SimpleProperty) {
return "simple property";
} else {
return "";
}
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
if (element instanceof SimpleProperty) {
return ((SimpleProperty) element).getKey();
} else {
return "";
}
}
@NotNull
@Override
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
if (element instanceof SimpleProperty) {
return ((SimpleProperty) element).getKey() + ":" + ((SimpleProperty) element).getValue();
} else {
return "";
}
}
}