diff options
author | 2021-10-31 02:06:07 +0100 | |
---|---|---|
committer | 2021-10-31 19:26:15 +0100 | |
commit | d933f00be208a586143b35d06e689f94a6a6f7e6 (patch) | |
tree | d9d1eddd6058a48f5c5189a2d8bb1b77f2ab5579 /language-web/src/main/js/language/folding.ts | |
parent | fix(web): fix server-side content assist filtering (diff) | |
download | refinery-d933f00be208a586143b35d06e689f94a6a6f7e6.tar.gz refinery-d933f00be208a586143b35d06e689f94a6a6f7e6.tar.zst refinery-d933f00be208a586143b35d06e689f94a6a6f7e6.zip |
feat(web): client support for transformation rules
Diffstat (limited to 'language-web/src/main/js/language/folding.ts')
-rw-r--r-- | language-web/src/main/js/language/folding.ts | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/language-web/src/main/js/language/folding.ts b/language-web/src/main/js/language/folding.ts index 54c7294d..5d51f796 100644 --- a/language-web/src/main/js/language/folding.ts +++ b/language-web/src/main/js/language/folding.ts | |||
@@ -75,18 +75,22 @@ export function foldDeclaration(node: SyntaxNode, state: EditorState): FoldRange | |||
75 | * @param node the node to fold | 75 | * @param node the node to fold |
76 | * @returns the folding range or `null` is there is nothing to fold | 76 | * @returns the folding range or `null` is there is nothing to fold |
77 | */ | 77 | */ |
78 | export function foldConjunction(node: SyntaxNode): FoldRange | null { | 78 | function foldWithSibling(node: SyntaxNode): FoldRange | null { |
79 | const { parent } = node; | 79 | const { parent } = node; |
80 | if (parent === null) { | 80 | if (parent === null) { |
81 | return null; | 81 | return null; |
82 | } | 82 | } |
83 | const { cursor } = parent; | 83 | const { firstChild } = parent; |
84 | let nConjunctions = 0; | 84 | if (firstChild === null) { |
85 | while (cursor.next()) { | 85 | return null; |
86 | } | ||
87 | const { cursor } = firstChild; | ||
88 | let nSiblings = 0; | ||
89 | while (cursor.nextSibling()) { | ||
86 | if (cursor.type === node.type) { | 90 | if (cursor.type === node.type) { |
87 | nConjunctions += 1; | 91 | nSiblings += 1; |
88 | } | 92 | } |
89 | if (nConjunctions >= 2) { | 93 | if (nSiblings >= 2) { |
90 | return { | 94 | return { |
91 | from: node.from, | 95 | from: node.from, |
92 | to: node.to, | 96 | to: node.to, |
@@ -95,3 +99,17 @@ export function foldConjunction(node: SyntaxNode): FoldRange | null { | |||
95 | } | 99 | } |
96 | return null; | 100 | return null; |
97 | } | 101 | } |
102 | |||
103 | export function foldWholeNode(node: SyntaxNode): FoldRange { | ||
104 | return { | ||
105 | from: node.from, | ||
106 | to: node.to, | ||
107 | }; | ||
108 | } | ||
109 | |||
110 | export function foldConjunction(node: SyntaxNode): FoldRange | null { | ||
111 | if (node.parent?.type?.name === 'PredicateBody') { | ||
112 | return foldWithSibling(node); | ||
113 | } | ||
114 | return foldWholeNode(node); | ||
115 | } | ||