✨ feat(vscode): 代码阅读加 Celery 库规则,定时任务表里的任务名能跳到任务函数
This commit is contained in:
1 parent
905d7845b5
commit
68104e2cba
22 files changed
+2228
-139
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import type { BlockView } from '../blockView'
|
||||
import type { RuleReference } from '../contract'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { toBlockViews } from '../blockView'
|
||||
import { createPythonAdapter } from '../languages/python'
|
||||
import { celeryRule } from '../rules/celery'
|
||||
import { readFixture, WASM_DIR, withBlocks } from '../testSupport'
|
||||
import { pythonZhTranslator } from '../translators/pythonZh'
|
||||
import { DefinitionSources, referencesIn } from './definitionSources'
|
||||
|
||||
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, py, pythonZhTranslator, { rules: [celeryRule], report: () => {} }))
|
||||
}
|
||||
|
||||
/** 记下问了哪边:规则(引用的键)还是语言扩展(下标)。 */
|
||||
function recorder(): { asked: string[], sources: DefinitionSources<string> } {
|
||||
const asked: string[] = []
|
||||
const sources = new DefinitionSources<string>({
|
||||
rule: async (reference: RuleReference) => {
|
||||
asked.push(`规则 ${reference.rule} ${reference.key}`)
|
||||
return ['tasks.py']
|
||||
},
|
||||
language: async (offset: number) => {
|
||||
asked.push(`语言扩展 ${offset}`)
|
||||
return []
|
||||
},
|
||||
})
|
||||
return { asked, sources }
|
||||
}
|
||||
|
||||
describe('名字的定义去哪儿查', () => {
|
||||
it('视图数据里规则标了引用的名字:下标 → 引用(任务表里的任务名)', async () => {
|
||||
const references = referencesIn(await views(SNAPSHOT))
|
||||
expect(references.size).toBe(12)
|
||||
const offset = SNAPSHOT.indexOf('commerce.retry_failed_fulfillments",\n "schedule"')
|
||||
expect(references.get(offset)).toEqual({ rule: 'celery', key: 'commerce.retry_failed_fulfillments' })
|
||||
})
|
||||
|
||||
it('规则标了引用的问规则,其余(同一张卡片里的应用名、别的块里的名字)问语言扩展', async () => {
|
||||
const blocks = await views(SNAPSHOT)
|
||||
const { asked, sources } = recorder()
|
||||
sources.remember(3, blocks)
|
||||
const task = SNAPSHOT.indexOf('commerce.retry_failed_fulfillments",\n "schedule"')
|
||||
const app = SNAPSHOT.indexOf('celery_app.conf.beat_schedule')
|
||||
|
||||
expect(await sources.locate(3, task)).toEqual(['tasks.py'])
|
||||
expect(await sources.locate(3, app)).toEqual([])
|
||||
expect(asked).toEqual([`规则 celery commerce.retry_failed_fulfillments`, `语言扩展 ${app}`])
|
||||
})
|
||||
|
||||
it('引用只对记下它的那个文档版本有效;没记过文档时都问语言扩展', async () => {
|
||||
const blocks = await views(SNAPSHOT)
|
||||
const task = SNAPSHOT.indexOf('commerce.retry_failed_fulfillments",\n "schedule"')
|
||||
const { asked, sources } = recorder()
|
||||
await sources.locate(1, task)
|
||||
sources.remember(3, blocks)
|
||||
await sources.locate(4, task)
|
||||
sources.remember(4, [])
|
||||
await sources.locate(4, task)
|
||||
expect(asked).toEqual([`语言扩展 ${task}`, `语言扩展 ${task}`, `语言扩展 ${task}`])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user