<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="354182" data-post-id="354182">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachdaniel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/120/31980_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachdaniel
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Ash</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hm… Interesting. I don’t see refactorings provided for either actually, but I do see what you mean about the AST structure there. I imagine something could be done for operators specifically which is the only place you’d have this problem, but it may not be worth the effort to make it work.</p>
<p>Specifically, the associativity of the operators is known, and so before attempting to provide a refactoring you could attempt to rewrite nested operator calls in some equivalent way to cover the range. Like in this case</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">+
|- +
|  |- x
|   \- y
 \- z
</code></pre>
<p>is equivalent to</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">+
|- +
|  |- x
|   \- +
|     | y
|     | z
</code></pre>
<p>The interesting thing (and I’m actually surprised the Elixir formatter doesn’t step in here to solve this ambiguity, <a class="mention" href="/u/josevalim" rel="nofollow">@josevalim</a>)</p>
<p>If you were to highlight <code>y - z</code> in <code>x - y - z</code> you definitely could <em>not</em> extract <code>y - z</code> into a variable as it would actually change the outcome of that statement. I’m pretty surprised that the formatter doesn’t turn <code>x - y - z</code> into <code>(x - y) - z</code> automatically, because then selecting <code>y) - z</code> would not even appear to be something you could refactor.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354182" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/52">Post #51</a>
	                </div>
	            </div>
              <div id="likers-container-354182" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354182"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #51"></div>
  </section>
</div>
    <div class="postbit" id="354183" data-post-id="354183">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="xpressgetaway" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  xpressgetaway
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Going to try this. Thanks!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354183" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/53">Post #52</a>
	                </div>
	            </div>
              <div id="likers-container-354183" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354183"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #52"></div>
  </section>
</div>
    <div class="postbit" id="354201" data-post-id="354201">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sodapopcan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/120/34668_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sodapopcan
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Ash-Core-Team" data-username="zachdaniel" data-post="52" data-topic="67759">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/48/31980_2.png" class="avatar"> zachdaniel:</div>
<blockquote>
<p>I’m pretty surprised that the formatter doesn’t turn <code>x - y - z</code> into <code>(x - y) - z</code> automatically,</p>
</blockquote>
</aside>
<p>Adding a tangential and self-serving comment here: this would be nice.  I dislike how the formatter is operator precedent aware.  Even though I did just fine in math, <code>(3 * 2) + 1</code> is a lot nicer in code.  Just like you say: it makes it clear what <em>could</em> be extracted.</p>
<p>EDIT: I can see how this would be a deal-breaker for math-heavy projects.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354201" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/54">Post #53</a>
	                </div>
	            </div>
              <div id="likers-container-354201" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354201"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #53"></div>
  </section>
</div>
    <div class="postbit" id="354211" data-post-id="354211">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gpereira" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gpereira/120/26636_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gpereira
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Ash-Core-Team" data-username="zachdaniel" data-post="52" data-topic="67759">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/48/31980_2.png" class="avatar"> zachdaniel:</div>
<blockquote>
<p>I don’t see refactorings provided for either actually</p>
</blockquote>
</aside>
<p>That’s weird. I just installed neovim (which I didn’t have before), lazynvim and refactorex via the plugin by synic and the refactorings show up for me.<br>
</p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/c/0/c0f6dc64ab898e39065403a83d1eaab0a0aefcbc.png" data-download-href="https://forum.elixirforum.com/uploads/default/c0f6dc64ab898e39065403a83d1eaab0a0aefcbc" title="Screenshot 2025-01-25 at 10.42.19" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/c/0/c0f6dc64ab898e39065403a83d1eaab0a0aefcbc.png" alt="Screenshot 2025-01-25 at 10.42.19" data-base62-sha1="rx2zqpZZRppVjJcxnSmbeZWCdQw" width="690" height="381" data-dominant-color="26282D"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2025-01-25 at 10.42.19</span><span class="informations">842×465 32.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>I had to explicitly set the keybindings in the <code>init.lua</code> though.</p>
<pre data-code-wrap="lua"><code class="lang-lua">...
vim.keymap.set('v', '&lt;space&gt;r', vim.lsp.buf.code_action)  
vim.keymap.set('n', '&lt;space&gt;r', vim.lsp.buf.code_action)  
vim.keymap.set('v', '&lt;F2&gt;', vim.lsp.buf.rename)        
vim.keymap.set('n', '&lt;F2&gt;', vim.lsp.buf.rename)        
</code></pre>
<p>After setting them and doing valid selections, I could choose between the refactorings. Is that setup something every new neovim user must do <a class="mention" href="/u/synic" rel="nofollow">@synic</a>? If so, we should include it in the docs. Btw, super easy to install and switch versions using the plugin. Great work, man!</p>
<aside class="quote group-Ash-Core-Team" data-username="zachdaniel" data-post="52" data-topic="67759">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/48/31980_2.png" class="avatar"> zachdaniel:</div>
<blockquote>
<p>Specifically, the associativity of the operators is known, and so before attempting to provide a refactoring you could attempt to rewrite nested operator calls in some equivalent way to cover the range.</p>
</blockquote>
</aside>
<p>I’ve been thinkering with ideas on how to make this work. Since I look for the selection subtree inside the complete AST, I’d have to generate the combinatory equivalences on the AST, like the example you showed. So when it found some <code>+</code> containing another <code>+</code>, it would compare both orderings. The only operators that fall in this category are <code>+</code> and <code>*</code>, right? However, this can become quite computationally expensive depending on how it is implemented.</p>
<p>EDIT: Sorry, I just now understood your problem, visual block is a different mode (not sure) in neovim and on it the refactorings aren’t working. I did some testing and apparently the payload sent to the LSP is different from visual mode</p>
<pre data-code-wrap="json"><code class="lang-json">visual block mode
{  
  id = 4, 
  ..., 
  range = {
    ["end"] = &lt;1&gt;{        
      character = 9,
      line = 9
    },
    start = &lt;table 1&gt; 
  }    
}

visual mode
{  
  id = 5, 
  ..., 
  range = {
    ["end"] = {        
      character = 9,
      line = 9
    },
    start = {   
      character = 4,
      line = 9
    }   
  }    
}
</code></pre>
<p>I have no clue why they seem different and couldn’t check if they don’t end up being the same value after some conversion of this table thing. What I can confirm is that only renaming and same line refactorings work on this mode, as you stated.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354211" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/55">Post #54</a>
	                </div>
	            </div>
              <div id="likers-container-354211" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354211"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #54"></div>
  </section>
</div>
    <div class="postbit" id="354228" data-post-id="354228">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="synic" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/synic/120/37068_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  synic
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="gpereira" data-post="55" data-topic="67759">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gpereira/48/26636_2.png" class="avatar"> gpereira:</div>
<blockquote>
<p>After setting them and doing valid selections, I could choose between the refactorings. Is that setup something every new neovim user must do <a class="mention" href="/u/synic" rel="nofollow">@synic</a>? If so, we should include it in the docs. Btw, super easy to install and switch versions using the plugin. Great work, man!</p>
</blockquote>
</aside>
<p>Sort of, it’s more of a general LSP thing though and not refactorex.nvim specific. People generally set up their own keybinds (that’s the vim way) or just run <code>:lua vim.lsp.buf.code_action()</code></p>
<p>That being said, couldn’t hurt to throw something in the docs saying that those are the two commands they should use with some examples! I’ll add something later today</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354228" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/56">Post #55</a>
	                </div>
	            </div>
              <div id="likers-container-354228" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354228"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #55"></div>
  </section>
</div>
    <div class="postbit" id="358273" data-post-id="358273">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>Zed</code> team made again a great job! <img src="https://forum.elixirforum.com/images/emoji/apple/tada.png?v=15" title=":tada:" class="emoji" alt=":tada:" loading="lazy" width="20" height="20"></p>
<p><a href="https://zed.dev/blog/edit-prediction" class="onebox" target="_blank" rel="noopener nofollow ugc">https://zed.dev/blog/edit-prediction</a></p>
<p>I wonder if project like that can be integrated with this <code>zed</code> feature to provide better <code>Elixir</code> predictions. <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358273" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/57">Post #56</a>
	                </div>
	            </div>
              <div id="likers-container-358273" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358273"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #56"></div>
  </section>
</div>
    <div class="postbit" id="365503" data-post-id="365503">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bellesamways" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bellesamways/120/23736_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bellesamways
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>hey <a class="mention" href="/u/gpereira" rel="nofollow">@gpereira</a></p>
<p>I’m getting this error all the times that I started my VScode. not sure what I can do on my end, can you take a look please?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">[Info  - 11:03:25 AM] Client is waiting server
[Info  - 11:03:26 AM] 
[Info  - 11:03:28 AM] Server started on port 39929
[Error - 11:03:59 AM] Refactorex client: couldn't create connection to server.
Error: Client could not connect to the server.
    at Socket.&lt;anonymous&gt; (/home/isabelle/.vscode-server/extensions/gp-pereira.refatorex-0.1.44/src/extension.ts:138:13)
    at Socket.emit (node:events:524:28)
    at Socket.emit (node:domain:489:12)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
</code></pre>
<p>if you need something else, let me know</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="365503" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/58">Post #57</a>
	                </div>
	            </div>
              <div id="likers-container-365503" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="365503"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #57"></div>
  </section>
</div>
    <div class="postbit" id="389531" data-post-id="389531">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Kalamar" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Kalamar
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I managed to install it into Codium, downloading the extension file through undocumented urls, since it didn’t appear in the list of plugins.</p>
<p>Newbie question: how can I change the keyboard mappings? I don’t see anything related in the “Keyboard Shortcuts” window (granted, I haven’t used Codium for a long time)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="389531" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/refactorex-effortless-elixir-refactoring-in-vs-code/67759/59">Post #58</a>
	                </div>
	            </div>
              <div id="likers-container-389531" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="389531"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>