Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we try to grab Ruby syntax tree from bundle? #635

Open
SamSaffron opened this issue Jan 30, 2025 · 1 comment
Open

Should we try to grab Ruby syntax tree from bundle? #635

SamSaffron opened this issue Jan 30, 2025 · 1 comment
Labels
P2 Not a priority. PRs welcome

Comments

@SamSaffron
Copy link

I made this in my local config:

			local function create_stree_formatter()
				-- Check if Gemfile.lock exists and contains syntax_tree using grep
				local has_stree_in_bundle = function()
					local gemfile_lock = vim.fn.findfile("Gemfile.lock", ".;")
					if gemfile_lock ~= "" then
						local grep_result = vim.fn.system("grep -q syntax_tree " .. vim.fn.shellescape(gemfile_lock))
						return vim.v.shell_error == 0
					end
					return false
				end

				return {
					command = function()
						if has_stree_in_bundle() then
							return "bundle"
						else
							return "stree"
						end
					end,
					args = function()
						if has_stree_in_bundle() then
							return { "exec", "stree", "write", "$FILENAME" }
						else
							return { "write", "$FILENAME" }
						end
					end,
					stdin = false,
					cwd = util.root_file({ ".streerc" }),
				}
			end

Idea is to look in Gemfile.lock to see if syntax tree is there, if it is then use it via bundle exec, otherwise fallback to the installed gem.

should we make this default behavior ? It seems similar to a degree to what we do for node but the downside with ruby is that we need to grep inside a file (and it makes conform info a bit ugly cause it says:

syntax_tree ready (ruby) /home/sam/.gem/ruby/3.3.6/bin/bundle

vs this which would be a bit nicer

syntax_tree ready (ruby) /home/sam/.gem/ruby/3.3.6/bin/bundle exec stree

@SamSaffron SamSaffron changed the title Should we try to grap syntax tree from bundle? Should we try to grab syntax tree from bundle? Jan 30, 2025
@SamSaffron SamSaffron changed the title Should we try to grab syntax tree from bundle? Should we try to grab Ruby syntax tree from bundle? Jan 30, 2025
@stevearc
Copy link
Owner

I would be open to doing something like this as the default behavior. Shelling out to grep isn't great, though. If you want to try making a PR take a look at what we did for yew-fmt https://github.com/stevearc/conform.nvim/blob/master/lua/conform/formatters/yew-fmt.lua

@stevearc stevearc added the P2 Not a priority. PRs welcome label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Not a priority. PRs welcome
Projects
None yet
Development

No branches or pull requests

2 participants