✨ feat(vscode): 代码阅读库规则卡片不再吞掉字段中间的方法,编辑时收起子块
This commit is contained in:
1 parent
c803fd457f
commit
2251e67ef8
15 files changed
+280
-54
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { CodeBlock, ImportFacts, Inline, LibraryRule, Node, PropertyItem, PropertyRow, RuleBlock, RuleContext, RuleLocation, RuleReference, RuleWorkspace, Segment } from './contract'
|
||||
import type { CodeBlock, ImportFacts, Inline, LibraryRule, Node, PropertyItem, PropertyRow, RuleBlock, RuleContext, RuleLocation, RuleReference, RuleWorkspace, Segment, SourceSpan } from './contract'
|
||||
|
||||
/** 宿主这边怎么用库规则:什么时候启用、问哪个规则、认领了之后哪些子块并进去。规则本身只经 contract 拿信息。 */
|
||||
/** 宿主这边怎么用库规则:什么时候启用、问哪个规则、认领了之后编辑哪一段、留下哪些子块。规则本身只经 contract 拿信息。 */
|
||||
|
||||
/** 这份源码里各处导入的 facts,照源码顺序(先父块、再子块)。 */
|
||||
export function importsIn(blocks: readonly CodeBlock[]): ImportFacts[] {
|
||||
@@ -82,13 +82,23 @@ export function claimBlock(block: CodeBlock, rules: readonly LibraryRule[], cont
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** 源码里一个节点占的那段。 */
|
||||
function nodeSpan(node: Node): SourceSpan {
|
||||
return { startIndex: node.startIndex, endIndex: node.endIndex, startRow: node.startPosition.row, endRow: node.endPosition.row }
|
||||
}
|
||||
|
||||
/**
|
||||
* 替身并进了哪几行、留下哪些子块:编辑范围从原块头部开始,到最后一个并进来的子块(整条语句)结束;
|
||||
* 起始行落在这段里的子块都并进来(包括夹在中间、规则没点名的),之后的留下。
|
||||
* 认领的块的编辑范围和留下的子块:编辑范围是原块整条语句(从头部开始,到它连同各子块的最后一行,类就是整个类),「编辑」时整段一起改;
|
||||
* 规则没并进来的子块(方法、别的成员)不管写在哪,都照源码顺序留作它的子块。
|
||||
* 这些子块的行也在这段里:webview 在这块编辑时不画它们,同一行不会同时在两处能改。
|
||||
*/
|
||||
export function absorbedRange(block: CodeBlock, absorbs: readonly CodeBlock[]): { endRow: number, kept: CodeBlock[] } {
|
||||
const endRow = Math.max(block.header.endRow, ...absorbs.map(child => Math.max(child.header.endRow, child.node.endPosition.row)))
|
||||
return { endRow, kept: block.children.filter(child => child.header.startRow > endRow) }
|
||||
export function claimedShape(block: CodeBlock, absorbs: readonly CodeBlock[]): { span: SourceSpan, kept: CodeBlock[] } {
|
||||
const ends = [block.header, nodeSpan(block.node), ...block.children.flatMap(child => [child.header, nodeSpan(child.node)])]
|
||||
const last = ends.reduce((end, span) => span.endIndex > end.endIndex ? span : end)
|
||||
return {
|
||||
span: { ...block.header, endIndex: last.endIndex, endRow: last.endRow },
|
||||
kept: block.children.filter(child => !absorbs.includes(child)),
|
||||
}
|
||||
}
|
||||
|
||||
/** 文字里(连框里)带引用的段。 */
|
||||
|
||||
Reference in new issue
Block a user