int caretOffset = editor.getCaretModel().getOffset();
if (project == null) {
return null;
}
GoNamesCache namesCache = GoNamesCache.getInstance(project);
Set<String> imported = new HashSet<String>();
for (GoImportDeclarations ids : file.getImportDeclarations()) {
for (GoImportDeclaration id : ids.getDeclarations()) {
String name = id.getPackageName();
if (name != null && !id.getPackageAlias().isEmpty()) {
imported.add(name);
}
}
}
Data toImport = null;
for (RangeHighlighter highlighter : getAllHighlighters(project)) {
int start = highlighter.getStartOffset();
int end = highlighter.getEndOffset();
TextRange range = new TextRange(start, end);
Object errorStripeTooltip = highlighter.getErrorStripeTooltip();
if (!visibleRange.contains(range) ||
editor.getFoldingModel().isOffsetCollapsed(start) ||
!(errorStripeTooltip instanceof HighlightInfo)) {
continue;
}
// if this a "Unresolved symbol" error
HighlightInfo info = (HighlightInfo) errorStripeTooltip;
if (info.getSeverity() != HighlightSeverity.ERROR ||
!info.getDescription().contains("Unresolved symbol")) {
continue;
}
GoLiteralIdentifier id = findElementOfClassAtRange(file, start, end, GoLiteralIdentifier.class);
if (!isPackageUsage(id)) {
continue;
}
if (id == null) {
continue;
}
// packages exist
String expectedPackage = id.getText();
List<String> sdkPackages = getPackagesByName(
namesCache.getSdkPackages(), expectedPackage);
List<String> projectPackages = getPackagesByName(
namesCache.getProjectPackages(), expectedPackage);
if (imported.contains(expectedPackage) || sdkPackages.size() == 0 && projectPackages.size() == 0) {
continue;
}
toImport = new Data(id, sdkPackages, projectPackages);