PY-36368 Move scipyNameMapping.tsv to the right resource root

GitOrigin-RevId: fb112a7dabecce82c87a3c9f239fccd4961b5b35
This commit is contained in:
Mikhail Golubev
2025-09-16 16:33:56 +00:00
committed by intellij-monorepo-bot
parent ed259ab056
commit 7df5f2ad48
4 changed files with 6411 additions and 52907 deletions
File diff suppressed because it is too large Load Diff
@@ -1,58 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.numpy.codeInsight
import com.google.common.collect.ImmutableMap
import com.intellij.psi.PsiElement
import com.jetbrains.python.documentation.PythonDocumentationLinkProvider
import com.jetbrains.python.documentation.PythonDocumentationMap
import com.jetbrains.python.documentation.PythonDocumentationProvider
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
class SciPyDocumentationLinkProvider : PythonDocumentationLinkProvider {
private val nameToWebpageName: Map<String, String> by lazy {
val b = ImmutableMap.builder<String, String>()
try {
BufferedReader(
InputStreamReader(
SciPyDocumentationLinkProvider::class.java
.getResourceAsStream("/com/jetbrains/numpy/codeInsight/scipyNameMapping.tsv"), // generated by scipy_doc_mapping.py
Charsets.UTF_8
)
).use { inputStream ->
inputStream.lines().forEach { line ->
val kv = line.split("\t".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
b.put(kv[0], kv[1])
}
}
}
catch (e: IOException) {
throw RuntimeException(e)
}
b.build()
}
override fun getExternalDocumentationUrl(element: PsiElement?, originalElement: PsiElement?): String? {
val qname = PythonDocumentationProvider.getFullQualifiedName(element)
return if (qname != null && qname.firstComponent in listOf("numpy", "scipy") &&
!PythonDocumentationMap.getInstance().entries.containsKey(qname.firstComponent)) {
val webPage = nameToWebpageName.get(qname.toString())
if (webPage != null) {
if (qname.firstComponent == "numpy")
"https://numpy.org/doc/stable/$webPage"
else
"https://docs.scipy.org/doc/scipy/$webPage"
} else {
"https://docs.scipy.org/doc/${qname.firstComponent}/reference/"
}
}
else null
}
}
File diff suppressed because it is too large Load Diff
@@ -43,7 +43,10 @@ class SciPyDocumentationLinkProvider : PythonDocumentationLinkProvider {
!PythonDocumentationMap.getInstance().entries.containsKey(qname.firstComponent)) {
val webPage = nameToWebpageName.get(qname.toString())
if (webPage != null) {
"https://docs.scipy.org/doc/${qname.firstComponent}/reference/generated/$webPage.html"
if (qname.firstComponent == "numpy")
"https://numpy.org/doc/stable/$webPage"
else
"https://docs.scipy.org/doc/scipy/$webPage"
} else {
"https://docs.scipy.org/doc/${qname.firstComponent}/reference/"
}