MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / getTagNameNode

Function getTagNameNode

src/cm/tagAutoRename.ts:20–45  ·  view source on GitHub ↗
(state: EditorState, from: number, to: number)

Source from the content-addressed store, hash-verified

18}
19
20function getTagNameNode(state: EditorState, from: number, to: number): SyntaxNode | null {
21 const tree = syntaxTree(state);
22 const positions = from === to ? [from, from - 1] : [from, to, to - 1];
23
24 for (const pos of positions) {
25 if (pos < 0 || pos > state.doc.length) continue;
26
27 for (const assoc of [-1, 1] as const) {
28 let node: SyntaxNode | null = tree.resolveInner(pos, assoc);
29 for (; node; node = node.parent) {
30 if (node.name === "TagName") return node;
31 if (
32 node.name === "OpenTag" ||
33 node.name === "CloseTag" ||
34 node.name === "SelfClosingTag" ||
35 node.name === "Element" ||
36 node.type.isTop
37 ) {
38 break;
39 }
40 }
41 }
42 }
43
44 return null;
45}
46
47function readNode(doc: Text, node: SyntaxNode): string {
48 return doc.sliceString(node.from, node.to);

Callers 1

getRenameTargetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected