-
Notifications
You must be signed in to change notification settings - Fork 188
fix: respect refactoring_auto_save in more cases
#2643
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
Conversation
plugin/core/protocol.py
Outdated
| The Code Action "kind" includes "other_kind" if "kind" matches "other_kind" exactly or "other_kind" is a subset | ||
| of "kind". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is somewhat misleading. I would say "refactor.rewrite" is a subset of "refactor" (because "refactor.rewrite" is more specific). So it's the other way round. It's a bit confusing because the "bigger" kind string is a substring of the more specific kind string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggle with describing this properly. Hard to make it clear without also describing the whole code action matching logic and how code actions are structured...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the naming for this function might be wrong/confusing.
In JS the language-server libraries have similar logic and they have contains function which actually does the opposite of this function.
/**
* Checks if `other` is a sub-kind of this `CodeActionKind`.
*
* The kind `"refactor.extract"` for example contains `"refactor.extract"` and ``"refactor.extract.function"`,
* but not `"unicorn.refactor.extract"`, or `"refactor.extractAll"` or `refactor`.
*
* @param other Kind to check.
*/
public contains(other: CodeActionKind): boolean {
return this.equals(other) || this.value === '' || other.value.startsWith(this.value + CodeActionKind.sep);
}
CodeActionKind.QuickFix.contains('quickfix.foo') === trueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the code to match those libs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "includes" was from the previous function which had an array of kinds for the input.
Maybe rename like this
def is_subkind(base_kind: str, kind: str) -> bool:
"""
Return `True` if `kind` is a subkind of `base_kind`.
For example "a.b" is a subkind of "a" and of "a.b".
"""There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you happy with matching the Microsoft's libraries?
I find the short is_subkind not ideal for two reasons:
- it doesn't make it clear that it's related to code action kinds unless you see the parameters
- "subkind" is a bit confusing wording in case of kinds. One would think that "a" is a subkind of "a.b" (in the sense that "a.b" includes "a" when thinking about it as a string) but it's the opposite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's okay. But could you move this function out of protocol.py? In my opinion ideally this file should only contain the auto-generated types from the specs (I know there is some other stuff too, but let's not keep it growing if possible). Maybe put it in the "utils" file views.py or in sessions.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils is exactly what I was planning to do first but was a bit afraid of creating a file for any random stuff. Alternatively was also thinking about creating core/code_actions but then there would be two code_actions.
Maybe I'm overthinking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have the utils file, it is just named views.py. So let's just use that for now.
Perhaps some time in the future we can do a bigger refactoring of the files structure. But first we need a proper API for plugins (what currently is LSP/plugin/__init__.py, but then including all of the functionality that can be used by plugins - and then fix all the imports in plugins that currently import some random things from various files directly). And then I would also move (only) the auto-generated types from LSP/plugin/core/protocol.py to LSP/protocol/__init__.py and add a line from ...protocol import * into LSP/plugin/core/protocol.py for backward compatibility. So that we have a clean didvision between "official" LSP protocol types and the custom classes and types defined by this package. Then there would only be two API "endpoints" for imports in helper plugins: e.g. from LSP.protocol import TextDocumentPositionParams for the LSP types and from LSP.plugin import Request for all other things.
Co-authored-by: jwortmann <jwortmann@outlook.com>
Co-authored-by: jwortmann <jwortmann@outlook.com>
code_actions.pySessioncould access it.protocol.pykind_includes_other_kindfunctionsessions.pyrefactoring_auto_saveenabled. It only worked if the code action hadrefactoringkind exactly and not if it had more specific one likerefactoring.move. This is fixed by the newkind_includes_other_kindfunction.is_refactoringtoSession.execute_commandto allow for all edits triggered within this request to be treated as refactoring and trigger therefactoring_auto_savelogic. (see fix(deps): update dependency typescript-language-server to v5 LSP-typescript#278 to see the code that uses that)