Conversation
The response is of type What do you think about making |
I've just changed the argument to existing |
I feel like this should be implemented actually. The whole point of this feature (at least in case of basedpyright) is kinda lost without it. VSCode handles it, Zed doesn't. |
|
I agree that it would be very useful, and the specs exlicitly mention the automatic brace completion, so I think we should try to support this. You could also check the penultimate character position via Maybe something like if last_str := changes[-1].str:
if (ch := last_str[-1]) in self._on_type_formatting_trigger_characters \
or len(last_str) >= 2 and (ch := last_str[-2]) in self._on_type_formatting_trigger_characters:
return {
**text_document_position_params(view, selection.a),
'options': formatting_options(view.settings()),
'ch': ch,
}I haven't tested whether that works or if there is a way to simplify that more. Ideally we want to keep this |
|
I would actually try to make it a bit more specific and less error-prone by only checking second-to-last character if the last two characters match a specific pair ([], (), '', "" etc). But yes, I think it's doable. |
Yes, sounds like a useful idea. Another aspect that could be used is that such matched chars are always (I believe) inserted via |
That's true but it might be overkill in this case and even less functional because there can be cases where user just inserts |
|
I would suggest that we add a global setting I know that we can still always disable features via By the way, similarly I am thinking about adding a new setting |
|
The counterargument for adding a setting is that in case of basedpyright it provides a setting for enabling this functionality and it's not enabled by default. So I would say that it would be more confusing for user to find this basedpyright setting, enable it and see that nothing is happening. If we're adding a setting then I would be more for having it enabled by default. I believe that it would be better for the user to notice the functionality and look for how to disable it if it's not wanted than to never notice it and potentially miss out on something useful. (That said, it wouldn't apply to basedpyright anyway since its setting is disabled by default). |
A lot of servers provide settings to enable/disable various features like inlay hints or semantic highlighting on the servers side. So that is already the case for those features, and I think it is reasonable for a new user who freshly installed LSP to go through all settings in the LSP settings file and configure it to their liking. I would take the fact that it's disabled in basedpyright by default also as a hint that this feature can be controversal (personally I think I will not use it, because I don't like the editor interfering too much in what I typed) and should rather be opt-in. Note that we have I'm planning a moderate revision of the features page of the docs website, and I could add an info box there about that format-on-type has to be enabled in the user settings. That said, in case everyone other than me would be in favor of having it enabled by default, I would give in and say having a setting for it that is enabled by default is still better than having no setting at all. P.S: I was contemplating whether it should be |
|
@predragnikolic would you like to add something? :) |
|
Tomorrow in the evening I will try to find some time to have a look at this. |
Co-authored-by: Предраг Николић <idmpepe@gmail.com>
Co-authored-by: Предраг Николић <idmpepe@gmail.com>
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Would be nice if docs were added for this feature. (does not have to be in this PR) |
Add support for Document on Type Formatting Request.
For this functionality it's essential that we ignore edits triggered by undo/redo/paste since in that case formatting shouldn't trigger. Of course ST doesn't tell us explicitly how the edit was triggered so I'm listening for those specific commands and annotating the next TextChange with that command name. This should be pretty reliable given that we only consider change to be triggered by that command if it happened "right after" the command (within next tick).
LSP-basedpyright implements this functionality to automatically add
fin front a string when typing{. It advertises this capability:Some thoughts that I had while implementing this:
{. Spec mentions that the reportedchshould not necessarily be the last character for cases exactly like this but implementing such logic without some help from ST would rely on heuristics so not sure we should do it. Not handling it makes the feature a lot less useful though as ST often does match brace depending on where in the string we insert it.fbut might not be safe in general. We currently ignore the edit if document has changed.