🐛 fix(vscode): React 规则在导入了 react 的 .ts / .js 文件上也启用,自定义钩子和钩子调用照常出卡片

This commit is contained in:
cruldra committed 2026-10-16 20:50:12 +11:00
1 parent 2ccec54747
commit 9f736d92e7
23 files changed
+141 -36

No files matched your search

@@ -12,7 +12,7 @@ const py = createPythonAdapter(WASM_DIR)
const SNAPSHOT = readFixture('celeryApp.py')
function views(source: string): Promise<BlockView[]> {
return withBlocks(py, 'python', source, blocks => toBlockViews(blocks, { source, language: py, markers: [] }, pythonZhTranslator, { rules: [celeryRule], report: () => {} }))
return withBlocks(py, 'python', source, blocks => toBlockViews(blocks, { source, language: py, markers: [] }, pythonZhTranslator, { languageId: 'python', rules: [celeryRule], report: () => {} }))
}
/** 记下问了哪边:规则(引用的键)还是语言扩展(下标)。 */
@@ -80,7 +80,7 @@ export async function documentMessage(
const rules = registry.rulesFor(languageId)
const { blocks, colors, displayNames, symbols, imports, kinds, bindings } = await readBlockViews(runtime, adapter, translator, languageId, source, {
...(document.fileName && { fileName: document.fileName }),
rules: { rules, report, lookup },
rules: { languageId, rules, report, lookup },
calleeKind,
commandRule: commandRuleLookup(registry.commandRulesFor(languageId), report),
embedded: (embeddedId) => {
@@ -97,7 +97,7 @@ describe('react 钩子卡片发给页面', () => {
const ts = createTypeScriptAdapter(WASM_DIR)
const source = ['import { useState } from "react";', 'export function Box() {', ' const [n, setN] = useState(0);', ' return <i>{n}</i>;', '}'].join('\n')
const views = await withBlocks(ts, 'typescriptreact', source, blocks =>
toBlockViews(blocks, { source, language: ts, markers: [] }, typescriptZhTranslator, { rules: [reactRule], report: () => {} }))
toBlockViews(blocks, { source, language: ts, markers: [] }, typescriptZhTranslator, { languageId: 'typescriptreact', rules: [reactRule], report: () => {} }))
const hook = pageBlocks(views, source)[1].children[0]
expect(hook.kind).toBe('react.hook')
expect(hook.tint).toEqual({ dark: '#61dafb', light: '#0a7ea4' })