Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-04-11 01:49:44 -0400
committerAlexander Kurtakov2017-04-11 01:49:44 -0400
commit21e6a8bce4a082732e06083c677e2c2b16002dda (patch)
tree1e90568eb266151412e5abafa55bbd0a8650c520
parent8db2a7cca0dd18e31e34fcd36f0bd619371756b5 (diff)
downloadorg.eclipse.dltk.sh-21e6a8bce4a082732e06083c677e2c2b16002dda.tar.gz
org.eclipse.dltk.sh-21e6a8bce4a082732e06083c677e2c2b16002dda.tar.xz
org.eclipse.dltk.sh-21e6a8bce4a082732e06083c677e2c2b16002dda.zip
Bug 515054 - Shelled hangs for a minute once in a while
For shell builtins try using help output (aka 'bash help cd'). This prevents loading the huge manpage for shell builtins while also displaing more targetted output as what we had now was almost useless. Additionally prevents empty hover help by returning null when no content is found. Change-Id: Ib45d5ba6f756ce05765bbc074b59906bb4ba6f66 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
index 8269ba2..1376164 100644
--- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
+++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Red Hat Inc. and others.
+ * Copyright (c) 2009, 2017 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,8 +10,13 @@
*******************************************************************************/
package org.eclipse.dltk.sh.internal.ui.selection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.dltk.core.IMember;
import org.eclipse.dltk.ui.documentation.IScriptDocumentationProvider;
@@ -21,7 +26,38 @@ public class ShellDocumentationProvider implements IScriptDocumentationProvider
@Override
public Reader getInfo(String content) {
- return new StringReader(new ManPage(content).getStrippedHtmlPage().toString());
+ String helpInfo = getHelp(content);
+ if (!helpInfo.isEmpty()) {
+ return new StringReader("<pre>" + helpInfo + "</pre>");
+ }
+ String info = new ManPage(content).getStrippedHtmlPage().toString();
+ if (info.equals("<pre></pre>")) {
+ return null;
+ }
+ return new StringReader(info);
+ }
+
+ public static String getHelp(String command) {
+ List<String> commands = new ArrayList<>();
+ commands.add("bash");
+ commands.add("-c");
+ commands.add("help " + command);
+ ProcessBuilder process = new ProcessBuilder(commands);
+ final StringBuilder out = new StringBuilder();
+ try (InputStream stream = process.start().getInputStream()) {
+ final char[] buffer = new char[1024];
+ Reader in = new InputStreamReader(stream);
+ for (;;) {
+ int rsz = in.read(buffer, 0, buffer.length);
+ if (rsz < 0) {
+ break;
+ }
+ out.append(buffer, 0, rsz);
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ return out.toString();
}
@Override

Back to the top