use of com.goide.codeInsight.imports.GoImportPackageQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAutoImportInsertHandler method autoImport.
private static void autoImport(@NotNull InsertionContext context, @NotNull GoNamedElement element) {
PsiFile file = context.getFile();
boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(ModuleUtilCore.findModuleForPsiElement(file));
String importPath = element.getContainingFile().getImportPath(vendoringEnabled);
if (StringUtil.isEmpty(importPath))
return;
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
PsiReference reference = file.findReferenceAt(context.getStartOffset());
if (reference != null) {
PsiElement referenceElement = reference.getElement();
GoImportPackageQuickFix fix = new GoImportPackageQuickFix(referenceElement, importPath);
fix.invoke(context.getProject(), file, context.getEditor(), referenceElement, referenceElement);
}
}
use of com.goide.codeInsight.imports.GoImportPackageQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoReferenceImporter method autoImportReferenceAtCursor.
@Override
public boolean autoImportReferenceAtCursor(@NotNull Editor editor, @NotNull PsiFile file) {
if (!file.getViewProvider().getLanguages().contains(GoLanguage.INSTANCE) || !DaemonListeners.canChangeFileSilently(file)) {
return false;
}
int caretOffset = editor.getCaretModel().getOffset();
Document document = editor.getDocument();
int lineNumber = document.getLineNumber(caretOffset);
int startOffset = document.getLineStartOffset(lineNumber);
int endOffset = document.getLineEndOffset(lineNumber);
List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffset);
for (PsiElement element : elements) {
if (element instanceof GoCompositeElement) {
for (PsiReference reference : element.getReferences()) {
GoImportPackageQuickFix fix = new GoImportPackageQuickFix(reference);
if (fix.doAutoImportOrShowHint(editor, false)) {
return true;
}
}
}
}
return false;
}
Aggregations