🐛 fix(vscode): 代码阅读注释里引用的语言内置名不再标成找不到:代码里写到的(raise ValueError)问那处的定义、点了跳到语言自带的定义,没写到的当普通文字不能点;内置名单由语言插件给(Python 补全 dir(builtins),TypeScript 是 ECMAScript 标准全局对象)
This commit is contained in:
1 parent
49a3854390
commit
e3c8c1b118
14 files changed
+544
-98
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import type { LinkState } from './repoLink'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { commentLinkOf, RepoLinks } from './repoLink'
|
||||
import { onMessage, postMessage } from './vscode'
|
||||
@@ -5,10 +6,14 @@ import { onMessage, postMessage } from './vscode'
|
||||
/** 坏链接悬停上的字,走页面上统一的 data-tooltip,不用原生 title。 */
|
||||
const MISSING = '找不到'
|
||||
|
||||
/** 文件或符号没有的仓库链接、找不到的不带路径的引用:红色波浪线,悬停「找不到」。问到之前先是普通链接。 */
|
||||
function paintLink(anchor: HTMLAnchorElement, broken: boolean): void {
|
||||
/**
|
||||
* 按链接眼下的状态(见 [LinkState])画:文件或符号没有的仓库链接、找不到的不带路径的引用是红色波浪线,悬停「找不到」;
|
||||
* 语言自带的名字画成普通文字。问到之前先是普通链接。
|
||||
*/
|
||||
function paintLink(anchor: HTMLAnchorElement, state: LinkState): void {
|
||||
anchor.classList.toggle('cr-link-plain', state === 'plain')
|
||||
const tip = anchor.getAttribute('data-tooltip')
|
||||
if (broken) {
|
||||
if (state === 'broken') {
|
||||
anchor.classList.add('cr-link-broken')
|
||||
if (tip !== MISSING) {
|
||||
if (tip)
|
||||
@@ -32,12 +37,12 @@ function paintLink(anchor: HTMLAnchorElement, broken: boolean): void {
|
||||
|
||||
function paint(links: RepoLinks): void {
|
||||
for (const anchor of document.querySelectorAll<HTMLAnchorElement>('.cr-markdown a'))
|
||||
paintLink(anchor, links.isBroken(commentLinkOf(anchor)))
|
||||
paintLink(anchor, links.state(commentLinkOf(anchor)))
|
||||
}
|
||||
|
||||
/**
|
||||
* 注释、说明、问 AI 的回答里的仓库路径链接,和注释里不带路径的引用:点了发给扩展端打开(不走 webview 把 http 链接交给外部打开的那条),
|
||||
* 画出来之后把路径、引用发去问哪些文件没有、哪些引用找不到;文档换了版本再问一次(引用跟着源码变)。
|
||||
* 画出来之后把路径、引用发去问哪些文件没有、哪些引用找不到、哪些是语言自带的名字;文档换了版本再问一次(引用跟着源码变)。
|
||||
* 不带路径的引用都带着它写在哪块(见 commentLinkOf),扩展端从那块的声明起找。
|
||||
*/
|
||||
export function useRepoLinks(): void {
|
||||
@@ -50,7 +55,7 @@ export function useRepoLinks(): void {
|
||||
timer = window.setTimeout(() => {
|
||||
const found = [...document.querySelectorAll<HTMLAnchorElement>('.cr-markdown a')].map(anchor => ({ anchor, link: commentLinkOf(anchor) }))
|
||||
for (const { anchor, link } of found)
|
||||
paintLink(anchor, links.isBroken(link))
|
||||
paintLink(anchor, links.state(link))
|
||||
links.scan(found.flatMap(({ link }) => link ?? []))
|
||||
}, 50)
|
||||
}
|
||||
@@ -61,10 +66,15 @@ export function useRepoLinks(): void {
|
||||
return
|
||||
}
|
||||
if (msg.type === 'repoLinksChecked') {
|
||||
if (links.checked(msg.id, msg.missing, msg.unresolved))
|
||||
if (links.checked(msg.id, msg.missing, msg.unresolved, msg.builtin))
|
||||
paint(links)
|
||||
return
|
||||
}
|
||||
if (msg.type === 'repoLinkBuiltin') {
|
||||
links.builtin(msg)
|
||||
paint(links)
|
||||
return
|
||||
}
|
||||
if (msg.type === 'repoLinkBroken') {
|
||||
links.broken(msg)
|
||||
paint(links)
|
||||
|
||||
Reference in new issue
Block a user