LineColRange lcRange = ghcMessage.getRange();
TextRange range = lcRange.getRange(psiFile);
String message = ghcMessage.getErrorMessage();
CompilerMessageCategory category = ghcMessage.getCategory();
Annotation out = null;
switch (category) {
case ERROR:
out = annotationHolder.createErrorAnnotation(range, message);
break;
case WARNING:
out = annotationHolder.createWarningAnnotation(range, message);
break;
case INFORMATION:
out = annotationHolder.createInfoAnnotation(range, message);
break;
case STATISTICS:
break;
}
if (out != null) {
if (message.startsWith("Not in scope")) {
Module module = DeclarationPosition.getDeclModule(psiFile);
String symbol = psiFile.getText().substring(range.getStartOffset(), range.getEndOffset());
int dotIndex = symbol.lastIndexOf('.');
String unqualifiedSymbol = dotIndex >= 0 ? symbol.substring(dotIndex + 1) : symbol;
if (userImports == null) {
userImports = listUserImports(module, Paths.get(path));
}
List<String> imports = new ArrayList<String>();
ImportTrie importTrie = ImportTrie.get(module, path, getAllFiles(module));
addImports(imports, userImports, unqualifiedSymbol, importTrie);
addStandardImports(module, unqualifiedSymbol, imports, importTrie);
if (!imports.isEmpty()) {
out.registerFix(new AutoImportIntention(psiFile, range, imports.toArray(new String[imports.size()]), unqualifiedSymbol), range);
}
}
out.setTooltip(out.getTooltip().replaceAll("\\n", "<br/>").replaceAll("`(\\w+?)'", "<b>$1</b>"));
}
}
}
}