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);
}
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;
}
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;
}
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));
}
}
});
}
};
}
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();
}
};
}
Aggregations