🐛 fix(vscode): 注释里不带路径的引用从被注释的声明起一层层往外找,同类的方法、类的成员都能链到

This commit is contained in:
cruldra committed 2026-10-12 16:56:31 +11:00
1 parent 15972c0b35
commit 5120e50228
15 files changed
+450 -167

No files matched your search

@@ -2,6 +2,7 @@ import type { PeekTarget, ShownPeek } from './definitionPeek'
import type { DefinitionPeek, WebviewToExtension } from './types'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { DefinitionPeeks, linkPeekSource, placePeek } from './definitionPeek'
import { parseCommentLink } from './repoLink'
const DELAY = 300
const HIDING = 500
@@ -99,6 +100,17 @@ describe('定义卡片什么时候弹', () => {
expect(shown()).toBeUndefined()
})
it('不带路径的引用:问 peekLink 和点标题时都带着它写在哪块', () => {
const { peeks, sent } = setup()
const anchor = { name: 'reference' }
peeks.point({ anchor, source: { symbol: 'get_agent_admitted', block: 'class AgentService > function get_default_agent' } })
vi.advanceTimersByTime(DELAY)
expect(sent).toEqual([{ type: 'peekLink', id: 1, symbol: 'get_agent_admitted', block: 'class AgentService > function get_default_agent' }])
peeks.answer(1, PEEK)
peeks.jump()
expect(sent.at(-1)).toEqual({ type: 'openRepoLink', symbol: 'get_agent_admitted', block: 'class AgentService > function get_default_agent' })
})
it('还没收到 VS Code 的悬停延迟:不弹', () => {
const sent: WebviewToExtension[] = []
const peeks = new DefinitionPeeks<Anchor>(msg => sent.push(msg), () => {})
@@ -208,15 +220,16 @@ describe('定义卡片什么时候收', () => {
})
describe('链接能不能弹定义卡片', () => {
it('指到符号的才能:带 #符号 的仓库链接、不带路径的引用', () => {
expect(linkPeekSource('app/devices.py#Repo.find')).toEqual({ path: 'app/devices.py', symbol: 'Repo.find' })
expect(linkPeekSource('symbol:DesktopOnly')).toEqual({ symbol: 'DesktopOnly' })
it('指到符号的才能:带 #符号 的仓库链接、不带路径的引用(带着写在哪块)', () => {
expect(linkPeekSource(parseCommentLink('app/devices.py#Repo.find'))).toEqual({ path: 'app/devices.py', symbol: 'Repo.find' })
expect(linkPeekSource(parseCommentLink('symbol:DesktopOnly'))).toEqual({ symbol: 'DesktopOnly' })
expect(linkPeekSource({ symbol: 'DesktopOnly', block: 'function gate' })).toEqual({ symbol: 'DesktopOnly', block: 'function gate' })
})
it('只指到文件、目录的,网址:不能', () => {
expect(linkPeekSource('app/devices.py')).toBeUndefined()
expect(linkPeekSource('app/')).toBeUndefined()
expect(linkPeekSource('https://example.com#x')).toBeUndefined()
expect(linkPeekSource(parseCommentLink('app/devices.py'))).toBeUndefined()
expect(linkPeekSource(parseCommentLink('app/'))).toBeUndefined()
expect(linkPeekSource(parseCommentLink('https://example.com#x'))).toBeUndefined()
})
})