🐛 fix(vscode): 注释里不带路径的引用从被注释的声明起一层层往外找,同类的方法、类的成员都能链到
This commit is contained in:
1 parent
15972c0b35
commit
5120e50228
15 files changed
+450
-167
No files matched your search
@@ -1,11 +1,11 @@
|
||||
import type { CommentLink } from './repoLink'
|
||||
import type { DefinitionPeek, WebviewToExtension } from './types'
|
||||
import { parseCommentLink } from './repoLink'
|
||||
|
||||
/** 定义卡片浮窗的根上的属性:浮窗里的名字、链接是别的文件的,页面上管名字的那几处(跳到定义、高亮各处出现、再弹卡片)都不认。 */
|
||||
export const PEEK_ATTRIBUTE = 'data-peek'
|
||||
|
||||
/** 能弹定义卡片的东西:带源码下标的名字,或注释里指到符号的链接(带 #符号 的仓库链接、不带路径的引用)。 */
|
||||
export type PeekSource = { offset: number } | { path?: string, symbol: string }
|
||||
/** 能弹定义卡片的东西:带源码下标的名字,或注释里指到符号的链接(带 #符号 的仓库链接、不带路径的引用,后者带着写在哪块)。 */
|
||||
export type PeekSource = { offset: number } | (CommentLink & { symbol: string })
|
||||
|
||||
/** 指针下能弹定义卡片的一处:页面上的哪个元素(浮窗挂在它旁边),它是什么。 */
|
||||
export interface PeekTarget<A> {
|
||||
@@ -31,12 +31,9 @@ export function documentNameAt(target: EventTarget | null): HTMLElement | null {
|
||||
return name && !inPeek(name) ? name : null
|
||||
}
|
||||
|
||||
/** 注释里一个链接地址能不能弹定义卡片:指到符号的才能(带 #符号 的仓库链接、不带路径的引用),只指到文件、目录的不能。 */
|
||||
export function linkPeekSource(href: string): PeekSource | undefined {
|
||||
const link = parseCommentLink(href)
|
||||
if (link?.symbol === undefined)
|
||||
return undefined
|
||||
return link.path === undefined ? { symbol: link.symbol } : { path: link.path, symbol: link.symbol }
|
||||
/** 注释里一个链接(见 commentLinkOf)能不能弹定义卡片:指到符号的才能(带 #符号 的仓库链接、不带路径的引用),只指到文件、目录的不能。 */
|
||||
export function linkPeekSource(link: CommentLink | undefined): PeekSource | undefined {
|
||||
return link?.symbol === undefined ? undefined : { ...link, symbol: link.symbol }
|
||||
}
|
||||
|
||||
/** 浮窗与名字之间的间距。 */
|
||||
@@ -186,9 +183,8 @@ export class DefinitionPeeks<A> {
|
||||
this.post({ type: 'peekDefinition', id, version, offset: source.offset })
|
||||
return
|
||||
}
|
||||
const link = source.path === undefined ? { symbol: source.symbol } : { path: source.path, symbol: source.symbol }
|
||||
this.asked = { id, anchor, jump: { type: 'openRepoLink', ...link } }
|
||||
this.post({ type: 'peekLink', id, ...link })
|
||||
this.asked = { id, anchor, jump: { type: 'openRepoLink', ...source } }
|
||||
this.post({ type: 'peekLink', id, ...source })
|
||||
}
|
||||
|
||||
private cancelAsk(): void {
|
||||
|
||||
Reference in new issue
Block a user