if (!(element instanceof HPAbstractIdent))
return null;
HPAbstractIdent ident = (HPAbstractIdent) element;
TextRange range = ident.getTextRange();
PsiFile psiFile = element.getContainingFile();
VirtualFile file = psiFile.getVirtualFile();
if (file == null)
return null;
// todo: run in event-dispatch thread
//fdm.saveAllDocuments();
// try this: PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
int offset = range.getStartOffset();
LineCol coord = LineCol.fromOffset(psiFile, offset);
Module module = DeclarationPosition.getDeclModule(psiFile);
if (module == null)
return null;
CompilerLocation compiler = CompilerLocation.get(module);
if (compiler == null) {
return null;
}
try {
String sourcePath = GHCUtil.rootsAsString(module, false);
List<String> compilerArgs = compiler.getCompileOptionsList(
"-m", "GetIdType",
"-s", sourcePath,
"--line-number", String.valueOf(coord.line), "--column-number", String.valueOf(coord.column),
file.getPath()
);
ProcessLauncher idLauncher = new ProcessLauncher(false, null, compilerArgs);
String stdOut = idLauncher.getStdOut();
if (stdOut.trim().isEmpty())
return null;