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

Implement Structural Search And Replace #76

Open
lucypero opened this issue Aug 29, 2022 · 2 comments
Open

Implement Structural Search And Replace #76

lucypero opened this issue Aug 29, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@lucypero
Copy link

RA has a great feature for refactoring that I'd like to use in ST. How much work would it take to make an interface for this functionality? I believe you can only use this on VS Code for now. I'd love to make a PR if someone can give me some pointers.

Link to docs

@rchl
Copy link
Member

rchl commented Aug 29, 2022

There are various examples of custom commands in plugin.py. For example this one:

LSP-rust-analyzer/plugin.py

Lines 467 to 501 in 0e9264f

class RustAnalyzerSyntaxTree(RustAnalyzerCommand):
def is_enabled(self) -> bool:
selection = self.view.sel()
if len(selection) == 0:
return False
return super().is_enabled()
def run(self, edit: sublime.Edit) -> None:
params = text_document_position_params(self.view, self.view.sel()[0].b)
session = self.session_by_name(self.session_name)
if session is None:
return
session.send_request(
Request("rust-analyzer/syntaxTree", params),
lambda response: sublime.set_timeout(functools.partial(self.on_result, response))
)
def on_result(self, out: Optional[str]) -> None:
window = self.view.window()
if window is None:
return
if out is None:
return
sheets = window.selected_sheets()
view = window.new_file(flags=sublime.TRANSIENT)
view.set_scratch(True)
view.set_name("Syntax Tree")
# Resource Aware Session Types Syntax highlighting not available
view.run_command("append", {"characters": out})
view.set_read_only(True)
sheet = view.sheet()
if sheet is not None:
sheets.append(sheet)
window.select_sheets(sheets)

One for this feature would likely need to trigger an input (or two) to ask for a specific input but it shouldn't be that hard. You can check ST API at http://www.sublimetext.com/docs/api_reference.html .

BTW. It seems like RA also supports this feature through a custom comment:

Also available as an assist, by writing a comment containing the structural search and replace rule. You will only see the assist if the comment can be parsed as a valid structural search and replace rule.

I feel like this could work already in ST but haven't tried.

@lucypero
Copy link
Author

I feel like this could work already in ST but haven't tried.

Yes, you are right. I just tried it. It already works by writing the query in a comment. It would still be great to have another interface for it. I might take a look later. Thanks.

@rchl rchl added the enhancement New feature or request label Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants