Sublime Forum

Plugin for RipGrep

#1

Hi Plugin Experts,

I am writing a plugin to integrate ripgrep search into sublime. I have everything working (you can righclick, the seach shows up in a new window, similar to find in files option, only much much faster).
I am using view.setstatus to set the status message. I also have a 100ms timer that calls my view.setstatus to update status bar animation while workers are still active.
my update_status function looks like this:

def update_status(self, workers, msgStr, showResults, count=0, dir=1):
	count = count + dir
	found = False

	for worker in workers:
		if worker.is_alive():
			found = True
			if count == 7:
				dir = -1
			elif count == 0:
				dir = 1
			self.view.set_status("RipGrepSublime", "RipGrep Fetching results for '%s' [%s=%s]" %
								(msgStr, ' ' * count, ' ' * (7 - count)))
			# StatusBarIndicator.on_activated(self, self.view, "RipGrepSublime", "RipGrep Fetching results for '%s' [%s=%s]" %
			# 					(msgStr, ' ' * count, ' ' * (7 - count)))
			sublime.set_timeout(lambda: self.update_status(workers, msgStr, showResults, count, dir), 100)
			break

	if not found:
		self.view.erase_status("RipGrepSublime")
		output = ""
		if showResults:
			for worker in workers:
				self.display_results(worker.symbol, worker.output)

I am running into an issue with the status bar message.
When a search is active, the message is visible in the view context, once I change the view, the status bar message is not active anymore. I want the status bar message to be active across views. This way even if you switch views, you can still see if your search is still active. I tried to useeventlistner, however, I am unable to pass it a parameter (status bar message string). What am I missing?

Thanks in advance
Rajah

1 Like

#2

As you’ve noticed, each view has its own set of status keys, so if you want it to be visible in all views, you need to add it to all views. Technically though it really only needs to be in whatever view is currently the active view; otherwise you’re always doing a ton of updates.

Although you could try to catch when a view is activated and deactivated and update the status keys as appropriate, probably an easier way to go would just be to have your update_status track what view it thinks it added the status key to and see if the current view is the same or not. Unless the interval between updates is excessively large, the user probably won’t notice that there is a fraction of a second delay before the spinner appears in the new view.

So basically use sublime.active_window().active_view() to see what the active view is. If you’ve never updated the status before, then update it there and save that view. If you have updated before and the view is the same, keep updating it. If you have updated before and the view is different, erase the key from the old view and add it to this view instead.

I do a similar thing in my status line spinner in OverrideAudit, although there it doesn’t let the spinner wander out of the window you activated the command in, since that’s the window the results will eventually show up in.

1 Like

#3

Or use Window.status_message, if the spinner isn’t visible for too long because there can only be one status message at a time and you would occupy that for a longish time.

1 Like

#4

OdatNurd and FichteFoll, thank you very much for both your responses. I went with FicheFolls method as it was much simpler to implement. OdatNurd, you method is a little more involved, but gives me lot more flexibility, I will probably use it in a future plugin.

1 Like

#5

Hi Rajah,

I was just looking for a RipGrep plugin for Sublime. Is there anywhere I can keep an eye out for it? I’d be happy to beta-test too.

Thanks!

0 Likes

#6

FWIW, in this other thread, the Search in Project package was mentioned, which has ripgrep support. However, it shows results in a quick panel and not in a separate buffer, which may or may not be to your liking.

Maybe a different frontend could be added to that?

0 Likes

#8

Hi Codazzo, I have it all working, I have not figured out how to make it all available as a package for everyone to install.
I can just zip it up for you extract into your plugins folder, I am not sure how to exchange emails on open forum, maybe some cloud storage where I can drop the files?

0 Likes

#9

My current plugin is specific to RipGrep and opens in new widow with hot links to search window. I like this better than quick panel. I have my plugin working just like I want it to now. However, I am not familiar with packaging it for everyones use. Even if I go through the effort now, will it be accepted as there is already something very similar?

If so, I can just add support to the ‘Search in Projects’ plugin to show results in a new buffer.

0 Likes

#10

I can just zip it up for you extract into your plugins folder, I am not sure how to exchange emails on open forum, maybe some cloud storage where I can drop the files?

That would be great! Maybe something like wetransfer.com?

0 Likes

#11

The existing package is quite similar in its scope and in that it uses external tools to provide a folder search capability. I would suggest adding the additional representation to the existing package, if possible. That way a user can utilize multiple search backends and choose from the UI representation they prefer.

If either you or the other package’s author wouldn’t agree to this collaboration (or the other package is abandoned), the new package would be accepted regardless.

0 Likes

#12

Sounds good, I will try and integrate it.

Thanks,
Rajah

0 Likes

#13

Sent it your email on github.Ping me if you run into issues.

0 Likes

#14

Hi @FichteFoll, I looked at the search in project plugin, While it integrates many search engines, I feel that the interface is clunky. It opens a command window for every search and sublime widows is non responsive for the duration of the search. I think my plugin has a better interface. I may even extend support for other search engines and rename the plugin down the line.

0 Likes