Skip to content

Commit f0820c6

Browse files
committed
GoToSource - fixed external viewer command parameter, fixed parsing subpaths, VIM replaced by Kate
1 parent 66ab5bd commit f0820c6

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

plugins/sources/src/org/graalvm/visualvm/sources/arguments/SourceRootsArgument.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package org.graalvm.visualvm.sources.arguments;
2626

27-
import java.io.File;
2827
import org.graalvm.visualvm.sources.impl.SourceRoots;
2928
import org.netbeans.api.sendopts.CommandException;
3029
import org.netbeans.spi.sendopts.Option;
@@ -50,7 +49,7 @@ static void process(String[] values) throws CommandException {
5049
static final void setValue(String value) {
5150
if (value != null) value = value.trim();
5251
if (value == null || value.isEmpty()) SourceRoots.forceRoots(null);
53-
else SourceRoots.forceRoots(value.split(File.pathSeparator));
52+
else SourceRoots.forceRoots(SourceRoots.splitRoots(value));
5453
}
5554

5655
}

plugins/sources/src/org/graalvm/visualvm/sources/impl/SourceRoots.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package org.graalvm.visualvm.sources.impl;
2626

27+
import java.io.File;
28+
import java.util.ArrayList;
29+
import java.util.List;
2730
import java.util.regex.Pattern;
2831
import org.graalvm.visualvm.sources.SourcesRoot;
2932
import org.openide.util.NbPreferences;
@@ -68,4 +71,37 @@ public static boolean areForcedRoots() {
6871
return FORCED_ROOTS != null;
6972
}
7073

74+
75+
public static String[] splitRoots(String rootsString) {
76+
List<String> roots = new ArrayList();
77+
78+
int position = 0;
79+
int length = rootsString.length();
80+
81+
boolean inBlock = false;
82+
StringBuilder sb = new StringBuilder();
83+
84+
while (position < length) {
85+
char currentChar = rootsString.charAt(position);
86+
87+
if (currentChar == '[') { // NOI18N
88+
inBlock = true;
89+
} else if (currentChar == ']') { // NOI18N
90+
inBlock = false;
91+
}
92+
93+
if (!inBlock && currentChar == File.pathSeparatorChar) {
94+
roots.add(sb.toString());
95+
sb.setLength(0);
96+
} else {
97+
sb.append(currentChar);
98+
if (position == length - 1) roots.add(sb.toString());
99+
}
100+
101+
position++;
102+
}
103+
104+
return roots.toArray(new String[0]);
105+
}
106+
71107
}

plugins/sources/src/org/graalvm/visualvm/sources/viewer/ExternalSourcesViewer.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static enum ToolPreset {
125125
NOTEPADPP("Notepad++", "notepad++ -p" + SourceHandle.Feature.OFFSET.getCode() + " " + SourceHandle.Feature.FILE.getCode()), // NOI18N
126126
GEDIT("Gedit", "gedit +" + SourceHandle.Feature.LINE.getCode() + " " + SourceHandle.Feature.FILE.getCode()), // NOI18N
127127
EMACS("Emacs", "emacs +" + SourceHandle.Feature.LINE.getCode() + ":" + SourceHandle.Feature.COLUMN.getCode() + " " + SourceHandle.Feature.FILE.getCode()), // NOI18N
128-
VIM("Vim", "vim " + SourceHandle.Feature.FILE.getCode() + " +" + SourceHandle.Feature.LINE.getCode()); // NOI18N
128+
KATE("Kate", "kate -l " + SourceHandle.Feature.LINE.getCode() + " -c " + SourceHandle.Feature.COLUMN.getCode() + " " + SourceHandle.Feature.FILE.getCode()); // NOI18N
129129

130130
private final String name;
131131
private final String command;
@@ -216,8 +216,15 @@ private static void executeCommand(SourceHandle handle, String commandS) {
216216

217217
for (int i = 0; i < commandL.size(); i++) {
218218
String commandI = commandL.get(i);
219-
commandI = handle.expandFeatures(commandI);
220-
commandL.set(i, commandI);
219+
if (i == 0) { // first command should be path to viewer executable
220+
if (commandI.startsWith("\"") && commandI.endsWith("\"")) { // NOI18N
221+
commandI = commandI.substring(1, commandI.length() - 1);
222+
commandL.set(i, commandI);
223+
}
224+
} else { // other commands may be feature wildcards
225+
commandI = handle.expandFeatures(commandI);
226+
commandL.set(i, commandI);
227+
}
221228
}
222229

223230
new ExternalViewerLauncher(commandL) {

0 commit comments

Comments
 (0)