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

[feature] Allow automatically selecting FixIt action by pattern #4083

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filipelbc
Copy link

@filipelbc filipelbc commented Nov 19, 2022

PR Prelude

Thank you for working on YCM! :)

Please complete these steps and check these boxes (by putting an x inside
the brackets) before filing your PR:

  • I have read and understood YCM's CONTRIBUTING document.
  • I have read and understood YCM's CODE_OF_CONDUCT document.
  • I have included tests for the changes in my PR. If not, I have included a
    rationale for why I haven't.
  • I understand my PR may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Why this change is necessary and useful

Currently, it is difficult to automate application of some fixits, because it requires manual input to select a fixit.

For instance, suppose I want to frequently "organize imports" or "replace var by the type name" (in Java). I know the action is available, but I still need to wait for the list to show up and then select the option...

This PR adds support for selecting a FixIt based on a regex pattern provided when running the command:

:YcmCompleter FixIt <some-pattern>

Eg:

:YcmCompleter FixIt Change\ type

If this change makes sense, let me know, and I can try to also update the docs for it.


This change is Reviewable

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm
Thanks

I feel like this is better implemented in the server than the client. Ie the second argument to fix it can be used to filter the results server side.

I’m also unsure if regex is ideal. Any reason not to use an exact match?

Reviewable status: 0 of 2 LGTMs obtained

@codecov
Copy link

codecov bot commented Nov 19, 2022

Codecov Report

Merging #4083 (4da74f4) into master (2d1de48) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4083      +/-   ##
==========================================
+ Coverage   86.46%   86.49%   +0.02%     
==========================================
  Files          33       33              
  Lines        4337     4346       +9     
==========================================
+ Hits         3750     3759       +9     
  Misses        587      587              

@filipelbc
Copy link
Author

filipelbc commented Nov 19, 2022

@puremourning

I feel like this is better implemented in the server than the client. Ie the second argument to fix it can be used to filter the results server side.

Makes sense. I could try submitting a patch on the server side if you would give me some pointers as where the changes would need to be.

I’m also unsure if regex is ideal. Any reason not to use an exact match?

Matching exactly "the entire" text is not feasible because it varies. For instance, if I want to replace var by the specific type, I'd need to know the type ahead of time (for the match) and then there would be no point in running the command in the first place.

Matching exactly "a part of" the text would work as far as my current use-case goes, which is quite limited. Using a regex makes it more flexible, but I can't say for sure it is "necessary".

Also, I don't know if there are other fields besides text that might be better suited for the matching.

@puremourning
Copy link
Member

if you would give me some pointers as where the changes would need to be.

we'd probably do this in ycmd/completers/language_server/language_server_completer.py in GetCodeActions. The arguments to the command are passed in the request_data object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants