Search in sources :

Example 26 with IndexNotReadyException

use of com.intellij.openapi.project.IndexNotReadyException in project go-lang-idea-plugin by go-lang-plugin-org.

the class DlvStackFrame method getEvaluator.

@Nullable
@Override
public XDebuggerEvaluator getEvaluator() {
    return new XDebuggerEvaluator() {

        @Override
        public void evaluate(@NotNull String expression, @NotNull XEvaluationCallback callback, @Nullable XSourcePosition expressionPosition) {
            myProcessor.send(new DlvRequest.EvalSymbol(expression, myId)).done(variable -> callback.evaluated(createXValue(variable, AllIcons.Debugger.Watch))).rejected(throwable -> callback.errorOccurred(throwable.getMessage()));
        }

        @Nullable
        private PsiElement findElementAt(@Nullable PsiFile file, int offset) {
            return file != null ? file.findElementAt(offset) : null;
        }

        @Nullable
        @Override
        public TextRange getExpressionRangeAtOffset(@NotNull Project project, @NotNull Document document, int offset, boolean sideEffectsAllowed) {
            Ref<TextRange> currentRange = Ref.create(null);
            PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
                try {
                    PsiElement elementAtCursor = findElementAt(PsiDocumentManager.getInstance(project).getPsiFile(document), offset);
                    GoTypeOwner e = PsiTreeUtil.getParentOfType(elementAtCursor, GoExpression.class, GoVarDefinition.class, GoConstDefinition.class, GoParamDefinition.class);
                    if (e != null) {
                        currentRange.set(e.getTextRange());
                    }
                } catch (IndexNotReadyException ignored) {
                }
            });
            return currentRange.get();
        }
    };
}
Also used : AllIcons(com.intellij.icons.AllIcons) com.goide.psi(com.goide.psi) GoIcons(com.goide.GoIcons) DlvApi(com.goide.dlv.protocol.DlvApi) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DlvRequest(com.goide.dlv.protocol.DlvRequest) XValueChildrenList(com.intellij.xdebugger.frame.XValueChildrenList) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Promise(org.jetbrains.concurrency.Promise) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) XValue(com.intellij.xdebugger.frame.XValue) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) XCompositeNode(com.intellij.xdebugger.frame.XCompositeNode) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) StringUtil(com.intellij.openapi.util.text.StringUtil) RunProfile(com.intellij.execution.configurations.RunProfile) TextRange(com.intellij.openapi.util.TextRange) SystemInfo(com.intellij.openapi.util.SystemInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ColoredTextContainer(com.intellij.ui.ColoredTextContainer) GoSdkService(com.goide.sdk.GoSdkService) Nullable(org.jetbrains.annotations.Nullable) XSourcePosition(com.intellij.xdebugger.XSourcePosition) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) XDebuggerUtil(com.intellij.xdebugger.XDebuggerUtil) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) javax.swing(javax.swing) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DlvRequest(com.goide.dlv.protocol.DlvRequest) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Nullable(org.jetbrains.annotations.Nullable) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with IndexNotReadyException

use of com.intellij.openapi.project.IndexNotReadyException in project smali by JesusFreke.

the class SmaliFieldElementType method createStub.

@Override
public SmaliFieldStub createStub(@NotNull SmaliField psi, StubElement parentStub) {
    try {
        String fieldSmaliTypeName;
        SmaliTypeElement typeElement = psi.getTypeElement();
        if (typeElement != null) {
            fieldSmaliTypeName = typeElement.getSmaliName();
        } else {
            fieldSmaliTypeName = "Ljava/lang/Object;";
        }
        return new SmaliFieldStub(parentStub, psi.getName(), fieldSmaliTypeName);
    } catch (IndexNotReadyException ex) {
        System.out.println(psi.getName());
        throw ex;
    }
}
Also used : SmaliFieldStub(org.jf.smalidea.psi.stub.SmaliFieldStub) SmaliTypeElement(org.jf.smalidea.psi.impl.SmaliTypeElement) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 28 with IndexNotReadyException

use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.

the class AddExternalLibraryToDependenciesQuickFix method invoke.

@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
    DependencyScope scope = suggestScopeByLocation(myCurrentModule, myReference.getElement());
    JavaProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, myLibraryDescriptor, scope).done(aVoid -> new WriteAction() {

        protected void run(@NotNull final Result result) {
            try {
                importClass(myCurrentModule, editor, myReference, myQualifiedClassName);
            } catch (IndexNotReadyException e) {
                LOG.info(e);
            }
        }
    }.execute());
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) WriteAction(com.intellij.openapi.application.WriteAction) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 29 with IndexNotReadyException

use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.

the class TemplateState method focusCurrentExpression.

private void focusCurrentExpression() {
    if (isFinished() || isDisposed()) {
        return;
    }
    PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
    final int currentSegmentNumber = getCurrentSegmentNumber();
    lockSegmentAtTheSameOffsetIfAny();
    if (currentSegmentNumber < 0)
        return;
    final int start = mySegments.getSegmentStart(currentSegmentNumber);
    final int end = mySegments.getSegmentEnd(currentSegmentNumber);
    if (end >= 0) {
        myEditor.getCaretModel().moveToOffset(end);
        myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        myEditor.getSelectionModel().removeSelection();
        myEditor.getSelectionModel().setSelection(start, end);
    }
    DumbService.getInstance(myProject).withAlternativeResolveEnabled(() -> {
        Expression expressionNode = getCurrentExpression();
        List<TemplateExpressionLookupElement> lookupItems = getCurrentExpressionLookupItems();
        final PsiFile psiFile = getPsiFile();
        if (!lookupItems.isEmpty()) {
            if (((TemplateManagerImpl) TemplateManager.getInstance(myProject)).shouldSkipInTests()) {
                insertSingleItem(lookupItems);
            } else {
                for (LookupElement lookupItem : lookupItems) {
                    assert lookupItem != null : expressionNode;
                }
                AsyncEditorLoader.performWhenLoaded(myEditor, () -> runLookup(lookupItems, expressionNode.getAdvertisingText()));
            }
        } else {
            try {
                Result result = expressionNode.calculateResult(getCurrentExpressionContext());
                if (result != null) {
                    result.handleFocused(psiFile, myDocument, mySegments.getSegmentStart(currentSegmentNumber), mySegments.getSegmentEnd(currentSegmentNumber));
                }
            } catch (IndexNotReadyException ignore) {
            }
        }
    });
    focusCurrentHighlighter(true);
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile)

Example 30 with IndexNotReadyException

use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.

the class TodoPackageNode method update.

@Override
protected void update(PresentationData data) {
    super.update(data);
    final PackageElement packageElement = getValue();
    try {
        if (packageElement == null || !packageElement.getPackage().isValid()) {
            setValue(null);
            return;
        }
        int fileCount = getFileCount(packageElement);
        if (fileCount == 0) {
            setValue(null);
            return;
        }
        PsiPackage aPackage = packageElement.getPackage();
        String newName;
        if (getStructure().areFlattenPackages()) {
            newName = aPackage.getQualifiedName();
        } else {
            newName = myPresentationName != null ? myPresentationName : "";
        }
        int nameEndOffset = newName.length();
        int todoItemCount = getTodoItemCount(packageElement);
        newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
        myHighlightedRegions.clear();
        TextAttributes textAttributes = new TextAttributes();
        Color newColor = null;
        if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
            newColor = CopyPasteManager.CUT_COLOR;
        }
        textAttributes.setForegroundColor(newColor);
        myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
        EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
        myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
        data.setPresentableText(newName);
    } catch (IndexNotReadyException e) {
        LOG.info(e);
        data.setPresentableText("N/A");
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) PsiPackage(com.intellij.psi.PsiPackage) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Aggregations

IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)70 Nullable (org.jetbrains.annotations.Nullable)14 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)12 PsiElement (com.intellij.psi.PsiElement)11 Project (com.intellij.openapi.project.Project)10 PsiFile (com.intellij.psi.PsiFile)10 TextRange (com.intellij.openapi.util.TextRange)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 Document (com.intellij.openapi.editor.Document)6 Editor (com.intellij.openapi.editor.Editor)6 LocalQuickFixAndIntentionActionOnPsiElement (com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)5 Ref (com.intellij.openapi.util.Ref)4 LightweightHint (com.intellij.ui.LightweightHint)4 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)3 Module (com.intellij.openapi.module.Module)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 PsiClass (com.intellij.psi.PsiClass)3 javax.swing (javax.swing)3