Fix IDEA debugger issues

This commit is contained in:
Alexey Andreev 2017-07-01 23:41:21 +03:00
parent f86e498898
commit 434a3dd207
16 changed files with 300 additions and 23 deletions

View File

@ -74,7 +74,7 @@ class PropertyMap extends AbstractMap<String, Variable> {
}
}
Value value = new Value(debugger, jsVar.getValue());
vars.put(entry.getKey(), new Variable(name, value));
vars.put(name, new Variable(name, value));
}
backingMap.compareAndSet(null, vars);
}

View File

@ -91,6 +91,27 @@
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<target>
<mkdir dir="${basedir}/dependencies/"/>
<get src="https://download.plugins.jetbrains.com/1347/34745/scala-intellij-bin-SNAPSHOT.zip?updateId=34745&amp;pluginId=1347"
dest="${basedir}/dependencies/scala.zip"/>
<unzip src="${basedir}/dependencies/scala.zip" dest="${basedir}/dependencies"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
@ -262,6 +283,28 @@
<artifactId>commons-logging</artifactId>
</configuration>
</execution>
<execution>
<id>kotlin</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<file>dependencies/idea/plugins/Kotlin/lib/kotlin-plugin.jar</file>
<artifactId>kotlin-plugin</artifactId>
</configuration>
</execution>
<execution>
<id>scala</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<file>dependencies/Scala/lib/scala-plugin.jar</file>
<artifactId>scala-plugin</artifactId>
</configuration>
</execution>
</executions>
<configuration>
<localRepositoryPath>dependencies/maven</localRepositoryPath>

View File

@ -34,9 +34,7 @@
<profile>
<id>download-dependencies</id>
<activation>
<file>
<missing>dependencies/teavm.jar</missing>
</file>
<activeByDefault>true</activeByDefault>
</activation>
<build>

View File

@ -94,6 +94,20 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm.idea</groupId>
<artifactId>kotlin-plugin</artifactId>
<version>${idea.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm.idea</groupId>
<artifactId>scala-plugin</artifactId>
<version>${idea.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jps-common</artifactId>

View File

@ -0,0 +1,23 @@
/*
* Copyright 2017 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.idea.debug;
import com.intellij.xdebugger.breakpoints.XBreakpointProperties;
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
public interface TeaVMBreakpointProvider<T extends XBreakpointProperties<T>> {
Class<? extends XLineBreakpointType<T>> getBreakpointType();
}

View File

@ -15,12 +15,17 @@
*/
package org.teavm.idea.debug;
import com.intellij.debugger.ui.breakpoints.JavaLineBreakpointType;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.Key;
import com.intellij.xdebugger.XDebugProcess;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.teavm.chromerdp.ChromeRDPDebugger;
import org.teavm.chromerdp.ChromeRDPServer;
@ -33,7 +38,7 @@ public class TeaVMDebugProcess extends XDebugProcess {
public static final Key<Breakpoint> INNER_BREAKPOINT_KEY = new Key<>("TeaVM breakpoint");
private TeaVMDebuggerEditorsProvider editorsProvider;
private final Debugger innerDebugger;
private final TeaVMLineBreakpointHandler breakpointHandler;
private final List<TeaVMLineBreakpointHandler<?>> breakpointHandlers = new ArrayList<>();
private final int port;
private ChromeRDPServer debugServer;
@ -64,7 +69,17 @@ public class TeaVMDebugProcess extends XDebugProcess {
}
});
breakpointHandler = new TeaVMLineBreakpointHandler(session.getProject(), innerDebugger);
breakpointHandlers.add(new TeaVMLineBreakpointHandler<>(JavaLineBreakpointType.class, session.getProject(),
innerDebugger));
ExtensionPoint<TeaVMBreakpointProvider<?>> breakpointProvider = Extensions.getArea(
session.getProject()).getExtensionPoint("org.teavm.extensions.breakpointProvider");
if (breakpointProvider != null) {
for (TeaVMBreakpointProvider<?> provider : breakpointProvider.getExtensions()) {
breakpointHandlers.add(new TeaVMLineBreakpointHandler<>(provider.getBreakpointType(),
session.getProject(), innerDebugger));
}
}
}
private Debugger initDebugger() {
@ -121,6 +136,6 @@ public class TeaVMDebugProcess extends XDebugProcess {
@NotNull
@Override
public XBreakpointHandler<?>[] getBreakpointHandlers() {
return new XBreakpointHandler[] { breakpointHandler };
return breakpointHandlers.toArray(new XBreakpointHandler<?>[0]);
}
}

View File

@ -22,6 +22,7 @@ import com.intellij.xdebugger.frame.XExecutionStack;
import com.intellij.xdebugger.frame.XStackFrame;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.teavm.debugging.CallFrame;
@ -66,7 +67,10 @@ public class TeaVMExecutionStack extends XExecutionStack {
@Nullable
VirtualFile findVirtualFile(@NotNull String partialPath) {
return Arrays.stream(rootManager.getContentSourceRoots())
Stream<VirtualFile> roots = Stream.concat(
Arrays.stream(rootManager.getContentSourceRoots()),
Arrays.stream(rootManager.orderEntries().getAllSourceRoots()));
return roots
.map(sourceRoot -> sourceRoot.findFileByRelativePath(partialPath))
.filter(Objects::nonNull)
.findFirst()

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.idea.debug;
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinLineBreakpointType;
public class TeaVMKotlinBreakpointProvider implements TeaVMBreakpointProvider<JavaLineBreakpointProperties> {
@Override
public Class<? extends XLineBreakpointType<JavaLineBreakpointProperties>> getBreakpointType() {
return KotlinLineBreakpointType.class;
}
}

View File

@ -15,7 +15,6 @@
*/
package org.teavm.idea.debug;
import com.intellij.debugger.ui.breakpoints.JavaLineBreakpointType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
@ -23,31 +22,32 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
import com.intellij.xdebugger.breakpoints.XBreakpointType;
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
import org.teavm.debugging.Breakpoint;
import org.teavm.debugging.Debugger;
public class TeaVMLineBreakpointHandler extends XBreakpointHandler<XLineBreakpoint<JavaLineBreakpointProperties>> {
public class TeaVMLineBreakpointHandler<B extends XLineBreakpoint<?>> extends XBreakpointHandler<B> {
private Debugger innerDebugger;
private VirtualFileManager vfs;
private ProjectFileIndex fileIndex;
@SuppressWarnings("unchecked")
public TeaVMLineBreakpointHandler(Project project, Debugger innerDebugger) {
super(JavaLineBreakpointType.class);
public TeaVMLineBreakpointHandler(Class<? extends XBreakpointType<B, ?>> breakpointType,
Project project, Debugger innerDebugger) {
super(breakpointType);
this.innerDebugger = innerDebugger;
vfs = VirtualFileManager.getInstance();
fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
}
@Override
public void registerBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
public void registerBreakpoint(@NotNull B breakpoint) {
VirtualFile virtualFile = vfs.findFileByUrl(breakpoint.getFileUrl());
if (virtualFile == null) {
return;
@ -81,8 +81,7 @@ public class TeaVMLineBreakpointHandler extends XBreakpointHandler<XLineBreakpoi
}
@Override
public void unregisterBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint,
boolean temporary) {
public void unregisterBreakpoint(@NotNull B breakpoint, boolean temporary) {
Breakpoint innerBreakpoint = breakpoint.getUserData(TeaVMDebugProcess.INNER_BREAKPOINT_KEY);
if (innerBreakpoint != null) {
breakpoint.putUserData(TeaVMDebugProcess.INNER_BREAKPOINT_KEY, null);

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.idea.debug;
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
import org.jetbrains.plugins.scala.debugger.breakpoints.ScalaLineBreakpointType;
public class TeaVMScalaBreakpointProvider implements TeaVMBreakpointProvider<JavaLineBreakpointProperties> {
@Override
public Class<? extends XLineBreakpointType<JavaLineBreakpointProperties>> getBreakpointType() {
return ScalaLineBreakpointType.class;
}
}

View File

@ -16,6 +16,7 @@
package org.teavm.idea.debug;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.frame.XCompositeNode;
@ -26,6 +27,8 @@ import org.jetbrains.annotations.Nullable;
import org.teavm.debugging.CallFrame;
import org.teavm.debugging.Variable;
import org.teavm.debugging.information.SourceLocation;
import org.teavm.debugging.javascript.JavaScriptCallFrame;
import org.teavm.debugging.javascript.JavaScriptLocation;
class TeaVMStackFrame extends XStackFrame {
private TeaVMExecutionStack stack;
@ -50,6 +53,18 @@ class TeaVMStackFrame extends XStackFrame {
}
line = innerLocation.getLine() - 1;
}
if (virtualFile == null) {
JavaScriptCallFrame jsFrame = innerFrame.getOriginalCallFrame();
if (jsFrame != null) {
JavaScriptLocation jsLocation = jsFrame.getLocation();
if (jsLocation != null) {
virtualFile = VirtualFileManager.getInstance().findFileByUrl(jsLocation.getScript());
if (virtualFile != null) {
line = jsLocation.getLine();
}
}
}
}
position = XDebuggerUtil.getInstance().createPosition(virtualFile, line);
}
return position;

View File

@ -21,6 +21,8 @@ import com.intellij.xdebugger.frame.XNamedValue;
import com.intellij.xdebugger.frame.XValueChildrenList;
import com.intellij.xdebugger.frame.XValueNode;
import com.intellij.xdebugger.frame.XValuePlace;
import java.util.Arrays;
import java.util.Objects;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import org.teavm.debugging.Value;
@ -39,8 +41,51 @@ public class TeaVMValue extends XNamedValue {
@Override
public void computePresentation(@NotNull XValueNode node, @NotNull XValuePlace place) {
Icon icon = root ? PlatformIcons.VARIABLE_ICON : PlatformIcons.FIELD_ICON;
node.setPresentation(icon, innerValue.getType(), innerValue.getRepresentation(),
!innerValue.getProperties().isEmpty());
String representation = innerValue.getRepresentation();
if (representation == null) {
representation = "null";
}
if (Objects.equals(innerValue.getType(), "java.lang.String")) {
representation = getStringRepresentation();
}
node.setPresentation(icon, innerValue.getType(), representation, !innerValue.getProperties().isEmpty());
}
private String getStringRepresentation() {
Variable charactersProperty = innerValue.getProperties().get("characters");
if (charactersProperty != null) {
Variable dataProperty = charactersProperty.getValue().getProperties().get("data");
if (dataProperty != null) {
Value dataValue = dataProperty.getValue();
int[] indexes = dataValue.getProperties().keySet().stream()
.filter(t -> isDigits(t))
.mapToInt(Integer::parseInt)
.toArray();
int maxIndex = Math.min(Arrays.stream(indexes).max().orElse(-1) + 1, 256);
char[] chars = new char[maxIndex];
for (int i = 0; i < maxIndex; ++i) {
Variable charProperty = dataValue.getProperties().get(Integer.toString(i));
if (charProperty != null) {
String charRepr = charProperty.getValue().getRepresentation();
if (isDigits(charRepr)) {
chars[i] = (char) Integer.parseInt(charRepr);
}
}
}
return new String(chars);
}
}
return "<could not calculate string value>";
}
private static boolean isDigits(String str) {
for (int i = 0; i < str.length(); ++i) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
@Override

View File

@ -0,0 +1,21 @@
<!--
~ Copyright 2017 Alexey Andreev.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<idea-plugin>
<extensions defaultExtensionNs="org.teavm.extensions">
<breakpointProvider implementation="org.teavm.idea.debug.TeaVMKotlinBreakpointProvider"/>
</extensions>
</idea-plugin>

View File

@ -0,0 +1,21 @@
<!--
~ Copyright 2017 Alexey Andreev.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<idea-plugin>
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
<importer implementation="org.teavm.idea.maven.TeaVMMavenImporter"/>
</extensions>
</idea-plugin>

View File

@ -1,10 +1,13 @@
<idea-plugin version="2">
<idea-plugin>
<id>org.teavm.idea</id>
<name>TeaVM IDEA plugin</name>
<version>${project.version}</version>
<vendor email="info@teavm.org" url="http://teavm.org">TeaVM community</vendor>
<depends>org.jetbrains.idea.maven</depends>
<depends>com.intellij.modules.java</depends>
<depends optional="true" config-file="maven.xml">org.jetbrains.idea.maven</depends>
<depends optional="true" config-file="kotlin.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="scala.xml">org.intellij.scala</depends>
<description><![CDATA[
Plugin that allows to run TeaVM compiler and debug applications generated by TeaVM.
@ -42,7 +45,8 @@
<facetType implementation="org.teavm.idea.TeaVMWebAssemblyFacetType"/>
</extensions>
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
<importer implementation="org.teavm.idea.maven.TeaVMMavenImporter"/>
</extensions>
<extensionPoints>
<extensionPoint qualifiedName="org.teavm.extensions.breakpointProvider" area="IDEA_PROJECT"
interface="org.teavm.idea.debug.TeaVMBreakpointProvider"/>
</extensionPoints>
</idea-plugin>

View File

@ -0,0 +1,21 @@
<!--
~ Copyright 2017 Alexey Andreev.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<idea-plugin>
<extensions defaultExtensionNs="org.teavm.extensions">
<breakpointProvider implementation="org.teavm.idea.debug.TeaVMScalaBreakpointProvider"/>
</extensions>
</idea-plugin>