Search in sources :

Example 36 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project flutter-intellij by flutter.

the class PositionMapperTest method shouldGetPositionInFileUnderRemoteSourceRoot.

@Test
public void shouldGetPositionInFileUnderRemoteSourceRoot() throws Exception {
    tmp.writeFile("root/pubspec.yaml", "");
    tmp.ensureDir("root/lib");
    final VirtualFile main = tmp.writeFile("root/lib/main.dart", "");
    final VirtualFile hello = tmp.writeFile("root/lib/hello.dart", "");
    final PositionMapper mapper = setUpMapper(main, null);
    mapper.onLibrariesDownloaded(ImmutableList.of(makeLibraryRef("some/stuff/to/ignore/lib/main.dart")));
    assertEquals("some/stuff/to/ignore", mapper.getRemoteSourceRoot());
    scripts.addScript("1", "2", "some/stuff/to/ignore/lib/hello.dart", ImmutableList.of(new Line(10, 123, 1)));
    final XSourcePosition pos = mapper.getSourcePosition("1", makeScriptRef("2", "some/stuff/to/ignore/lib/hello.dart"), 123);
    assertNotNull(pos);
    assertEquals(pos.getFile(), hello);
    // zero-based
    assertEquals(pos.getLine(), 9);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Test(org.junit.Test)

Example 37 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method registerMockBreakpoint.

@SuppressWarnings("unchecked")
private XLineBreakpointImpl<CloudLineBreakpointProperties> registerMockBreakpoint(String[] watches, String condition, int sourceLine, String shortFileName, String packageName, boolean createdByServer, String desiredResultId) {
    this.desiredResultId = desiredResultId;
    addedBp.set(null);
    removedBp.set(null);
    CloudLineBreakpointProperties properties = new CloudLineBreakpointProperties();
    properties.setWatchExpressions(watches);
    properties.setCreatedByServer(createdByServer);
    XLineBreakpointImpl<CloudLineBreakpointProperties> lineBreakpoint = mock(XLineBreakpointImpl.class);
    XExpression expression = mock(XExpression.class);
    when(expression.getExpression()).thenReturn(condition);
    when(lineBreakpoint.getConditionExpression()).thenReturn(expression);
    when(lineBreakpoint.getProperties()).thenReturn(properties);
    when(lineBreakpoint.isEnabled()).thenReturn(Boolean.TRUE);
    when(lineBreakpoint.getType()).thenReturn(CloudLineBreakpointType.getInstance());
    VirtualFile mockFile = mock(VirtualFile.class);
    XSourcePosition sourcePosition = mock(XSourcePosition.class);
    when(sourcePosition.getLine()).thenReturn(sourceLine);
    when(sourcePosition.getFile()).thenReturn(mockFile);
    when(mockFile.isValid()).thenReturn(Boolean.TRUE);
    when(lineBreakpoint.getSourcePosition()).thenReturn(sourcePosition);
    PsiJavaFile psiJavaFile = mock(PsiJavaFile.class);
    when(psiJavaFile.getPackageName()).thenReturn(packageName);
    when(psiJavaFile.getName()).thenReturn(shortFileName);
    when(psiManager.findFile(mockFile)).thenReturn(psiJavaFile);
    handler.setPsiManager(psiManager);
    CloudLineBreakpointType.CloudLineBreakpoint javaBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) CloudLineBreakpointType.getInstance().createJavaBreakpoint(project, lineBreakpoint);
    when(lineBreakpoint.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(javaBreakpoint);
    when(lineBreakpoint.getUserData(CloudBreakpointHandler.CLOUD_ID)).thenReturn(desiredResultId);
    handler.registerBreakpoint(lineBreakpoint);
    return lineBreakpoint;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XExpression(com.intellij.xdebugger.XExpression) PsiJavaFile(com.intellij.psi.PsiJavaFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 38 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project ballerina by ballerina-lang.

the class BallerinaDebugProcess method findBreakPoint.

private XBreakpoint<BallerinaBreakpointProperties> findBreakPoint(@NotNull BreakPoint breakPoint) {
    String fileName = breakPoint.getFileName();
    String packagePath = breakPoint.getPackagePath();
    String relativeFilePathInProject;
    // If the package is ".", full path of the file will be sent as the filename.
    if (".".equals(packagePath)) {
        // Then we need to get the actual filename from the path.
        int index = fileName.lastIndexOf("/");
        if (index <= -1) {
            return null;
        }
        relativeFilePathInProject = fileName.substring(index);
    } else {
        // If the absolute path is not sent, we need to construct the relative file path in the project.
        relativeFilePathInProject = packagePath.replaceAll("\\.", "/") + "/" + fileName;
    }
    int lineNumber = breakPoint.getLineNumber();
    for (XBreakpoint<BallerinaBreakpointProperties> breakpoint : breakpoints) {
        XSourcePosition breakpointPosition = breakpoint.getSourcePosition();
        if (breakpointPosition == null) {
            continue;
        }
        VirtualFile fileInBreakpoint = breakpointPosition.getFile();
        int line = breakpointPosition.getLine() + 1;
        if (fileInBreakpoint.getPath().endsWith(relativeFilePathInProject) && line == lineNumber) {
            return breakpoint;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) BallerinaBreakpointProperties(org.ballerinalang.plugins.idea.debugger.breakpoint.BallerinaBreakpointProperties) BreakPoint(org.ballerinalang.plugins.idea.debugger.dto.BreakPoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 39 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project Perl5-IDEA by Camelcade.

the class PerlStackFrame method getEvaluator.

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

        @Override
        public void evaluate(@NotNull String expression, @NotNull final XEvaluationCallback callback, @Nullable XSourcePosition expressionPosition) {
            PerlDebugThread thread = myPerlExecutionStack.getSuspendContext().getDebugThread();
            thread.sendCommandAndGetResponse("e", new PerlEvalRequestDescriptor(expression), new PerlDebuggingTransactionHandler() {

                @Override
                public void run(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
                    PerlEvalResponseDescriptor descriptor = jsonDeserializationContext.deserialize(jsonObject.getAsJsonObject("data"), PerlEvalResponseDescriptor.class);
                    if (descriptor == null) {
                        callback.errorOccurred("Something bad happened on Perl side. Report to plugin devs.");
                    } else if (descriptor.isError()) {
                        callback.errorOccurred(descriptor.getResult().getValue());
                    } else {
                        callback.evaluated(new PerlXNamedValue(descriptor.getResult(), PerlStackFrame.this));
                    }
                }
            });
        }
    };
}
Also used : XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) JsonObject(com.google.gson.JsonObject) NotNull(org.jetbrains.annotations.NotNull) PerlXNamedValue(com.perl5.lang.perl.idea.run.debugger.values.PerlXNamedValue) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition 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)

Aggregations

XSourcePosition (com.intellij.xdebugger.XSourcePosition)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 Project (com.intellij.openapi.project.Project)9 Nullable (org.jetbrains.annotations.Nullable)8 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)6 PsiFile (com.intellij.psi.PsiFile)5 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 XDebugSession (com.intellij.xdebugger.XDebugSession)4 PsiElement (com.intellij.psi.PsiElement)3 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)3 Editor (com.intellij.openapi.editor.Editor)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManagerImpl (com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl)2 Ref (com.intellij.openapi.util.Ref)2 TextRange (com.intellij.openapi.util.TextRange)2 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)2 XValue (com.intellij.xdebugger.frame.XValue)2 VMPausedException (org.intellij.plugins.xsltDebugger.VMPausedException)2