Search in sources :

Example 1 with GoCompositeElement

use of com.goide.psi.GoCompositeElement 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;
}
Also used : GoImportPackageQuickFix(com.goide.codeInsight.imports.GoImportPackageQuickFix) GoCompositeElement(com.goide.psi.GoCompositeElement) PsiReference(com.intellij.psi.PsiReference) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GoImportPackageQuickFix (com.goide.codeInsight.imports.GoImportPackageQuickFix)1 GoCompositeElement (com.goide.psi.GoCompositeElement)1 Document (com.intellij.openapi.editor.Document)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1