✨ feat(vscode): 代码阅读的词可以讲源码里别处的名字(Segment.refers):FastAPI 路径里的 {user_id} 讲函数的参数,单击参数时跟着高亮,⌘ + 点击跳到参数
This commit is contained in:
1 parent
25569fa506
commit
15790ce7c8
9 files changed
+82
-22
No files matched your search
@@ -6,7 +6,7 @@ import { createPythonAdapter } from '../../../src/codeReader/languages/python'
|
||||
import { WASM_DIR, withBlocks } from '../../../src/codeReader/testSupport'
|
||||
import { pythonZhTranslator } from '../../../src/codeReader/translators/pythonZh'
|
||||
import { DefinitionLinks } from './definitionLinks'
|
||||
import { clickAction, isCurrent, KEY_SCROLL_MS, KEY_TO_COMMAND_MS, KeyScroll, occurrenceCount, OccurrenceHighlight, OccurrenceNavigation, occurrenceStyle, segmentOccurrence, stepIndex } from './occurrences'
|
||||
import { clickAction, isCurrent, KEY_SCROLL_MS, KEY_TO_COMMAND_MS, KeyScroll, occurrenceCount, OccurrenceHighlight, OccurrenceNavigation, occurrenceStyle, segmentOccurrence, sourceOf, stepIndex } from './occurrences'
|
||||
|
||||
function name(text: string, offset: number): Segment {
|
||||
return { text, role: 'variable', offset }
|
||||
@@ -54,6 +54,16 @@ describe('occurrences:哪些段画高亮', () => {
|
||||
expect(segmentOccurrence(name('a', 0), [at(0, 1, 'read'), at(0, 1, 'write')])).toBe('strong')
|
||||
})
|
||||
|
||||
it('讲别处名字的段(refers,写在字符串里的参数名)按那个名字算:那个名字的出现盖住它就画、能是当前那一处,自己照抄的位置不算', () => {
|
||||
const param: Segment = { text: 'user_id', role: 'variable', offset: 40, refers: { startIndex: 100, endIndex: 107 } }
|
||||
expect(sourceOf(param)).toEqual({ start: 100, end: 107 })
|
||||
expect(segmentOccurrence(param, [at(100, 107, 'write')])).toBe('strong')
|
||||
expect(segmentOccurrence(param, [at(40, 47)])).toBeUndefined()
|
||||
expect(isCurrent(param, { name: 'user_id', occurrences: [at(100, 107)], current: 0 })).toBe(true)
|
||||
expect(sourceOf(name('x', 3))).toEqual({ start: 3, end: 4 })
|
||||
expect(sourceOf({ text: '常量', role: 'storage' })).toBeUndefined()
|
||||
})
|
||||
|
||||
it('真实的 Python 译文和属性表:定义处按写入、用到的地方按读取画;点分模块名每一节各按自己的范围认', async () => {
|
||||
const source = [
|
||||
'import luffy_agent.core.db',
|
||||
|
||||
Reference in new issue
Block a user