Merge branch 'PR_scipy_numpy_external_docs' of https://github.com/guoci/intellij-community into guoci-PR_scipy_numpy_external_docs

This commit is contained in:
Dmitry Trofimov
2018-11-05 17:28:44 +01:00
2 changed files with 46477 additions and 2 deletions
@@ -2,6 +2,7 @@
package com.jetbrains.python.documentation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
@@ -16,10 +17,17 @@ import com.jetbrains.python.psi.PyFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author yole
@@ -38,6 +46,28 @@ public class PythonDocumentationMap implements PersistentStateComponent<PythonDo
return ServiceManager.getService(PythonDocumentationMap.class);
}
private static class ScipyExternalDocumentationMap {
private static final Map<String, String> nameToWebpageName = ((Supplier<Map<String, String>>)() -> {
final ImmutableMap.Builder<String, String> b = ImmutableMap.builder();
try (final BufferedReader inputStream = new BufferedReader(
new InputStreamReader(
ScipyExternalDocumentationMap.class
.getResourceAsStream("/com/jetbrains/python/documentation/scipyNameMapping.tsv"),
StandardCharsets.US_ASCII
)
)) {
inputStream.lines().forEach(line -> {
final String[] kv = line.split("\t");
b.put(kv[0], kv[1]);
});
}
catch (final IOException e) {
throw new RuntimeException(e);
}
return b.build();
}).get();
}
public static class Entry {
private String myPrefix;
private String myUrlPattern;
@@ -96,8 +126,8 @@ public class PythonDocumentationMap implements PersistentStateComponent<PythonDo
addEntry("PySide", "http://pyside.github.io/docs/pyside/{module.name.slashes}/{class.name}.html#{module.name}.{element.qname}");
addEntry("gtk", "http://library.gnome.org/devel/pygtk/stable/class-gtk{class.name.lower}.html#method-gtk{class.name.lower}--{function.name.dashes}");
addEntry("wx", "http://www.wxpython.org/docs/api/{module.name}.{class.name}-class.html#{function.name}");
addEntry("numpy", "http://docs.scipy.org/doc/numpy/reference/generated/{module.name}.{element.name}.html");
addEntry("scipy", "http://docs.scipy.org/doc/scipy/reference/generated/{module.name}.{element.name}.html");
addEntry("numpy", "https://docs.scipy.org/doc/numpy/reference/generated/{module.name}.{element.name}.html");
addEntry("scipy", "https://docs.scipy.org/doc/scipy/reference/generated/{module.name}.{element.name}.html");
addEntry("kivy", "http://kivy.org/docs/api-{module.name}.html");
addEntry("matplotlib", "http://matplotlib.org/api/{module.basename}_api.html#{element.qname}");
addEntry("pyramid", "http://docs.pylonsproject.org/projects/pyramid/en/latest/api/{module.basename}.html#{element.qname}");
@@ -209,6 +239,10 @@ public class PythonDocumentationMap implements PersistentStateComponent<PythonDo
if (pattern == null) {
return rootForPattern(urlPattern);
}
final Matcher match = Pattern.compile("\\A(.+/)((?:numpy|scipy)\\..+)\\.html\\Z").matcher(pattern);
if (match.find()) {
return match.group(1) + ScipyExternalDocumentationMap.nameToWebpageName.getOrDefault(match.group(2), match.group(2)) + ".html";
}
return pattern;
}
File diff suppressed because it is too large Load Diff