PY-36368 update scipy/numpy docs map

adjust to use URI fragments for section, if section exists

reduce URI fragment usage

closes https://github.com/JetBrains/intellij-community/pull/2408

GitOrigin-RevId: 89221e0bfa94c80875c2734408b0d0ccbe342ee7
This commit is contained in:
guoci
2025-09-16 16:33:56 +00:00
committed by intellij-monorepo-bot
parent 82705b4343
commit ed259ab056
2 changed files with 6465 additions and 0 deletions
@@ -0,0 +1,58 @@
// 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