super(true);
}
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
PsiElement element = queryParameters.getElementToSearch();
if (!(element instanceof HPAbstractIdent))
return;
PsiFile file = element.getContainingFile();
try {
DeclarationPosition declaration = DeclarationPosition.get(file, LineCol.fromOffset(file, element.getTextOffset()));
if (declaration == null)
return;
LineCol coord = declaration.coord;
VirtualFile virtualFile = file.getVirtualFile();
Project project = file.getProject();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (virtualFile == null)
return;
Module module = fileIndex.getModuleForFile(virtualFile);
CompilerLocation compiler = CompilerLocation.get(module);
if (compiler == null)
return;
List<String> args = compiler.getCompileOptionsList(
"-m", "FindUsages",
"-s", GHCUtil.rootsAsString(module, false),
"--line-number", String.valueOf(coord.line), "--column-number", String.valueOf(coord.column),
"-f", virtualFile.getPath()
);
final List<String> srcFiles = new ArrayList<String>();
fileIndex.iterateContent(new ContentIterator() {
public boolean processFile(VirtualFile virtualFile) {
if (HaskellCompiler.isCompilableFile(virtualFile)) {
srcFiles.add(virtualFile.getPath());
}
return true;
}
});
args.addAll(srcFiles);
ProcessLauncher launcher = new ProcessLauncher(true, null, args);
BufferedReader bf = new BufferedReader(new StringReader(launcher.getStdOut()));
while (true) {
String srcLineCol = bf.readLine();
if (srcLineCol == null)
break;
LineCol refLineCol = LineCol.parse(srcLineCol);
String srcModule = bf.readLine();
if (srcModule != null) {
PsiElement elementAt = HPIdentImpl.getElementAt(project, new DeclarationPosition(refLineCol, srcModule));
PsiReference reference = elementAt.getReference();
consumer.process(reference);
}
}
} catch (Exception e) {
LOG.error(e);