-
Notifications
You must be signed in to change notification settings - Fork 147
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
Support onTypeFormatting to format comment blocks #180
Comments
I do not consider this to be a bag with the langage server. The text editor should hanle this behavior. I will move the discussion to the eclipse issue. 🙂 |
See eclipse-wildwebdeveloper/wildwebdeveloper#599 (comment) , this is a typical LS feature: listening to file change and reacting sending an applyEdit. |
See https://microsoft.github.io/language-server-protocol/specification#textDocument_onTypeFormatting that's actually even more streamlined way to provide such things via LSP. |
@mickaelistria do you have an example of an LSP that currently does this? How do they handle editors that have this functionality built in without conflicting? Please provide any configs that you're using :) I'm personally not aware of any LSP that shoulders this responsibility, instead handing the functionality over to the editor (in VIM we use syntax files to handle indentation and commenting) |
YAML Language Server is currently in the process of adding a similar feature to automatically add whitespaces and dashes at the beginning of lines. See redhat-developer/yaml-language-server#389
I guess they assume that the client doesn't do anything on that matter, since after all it's a language-specific capability. Or they just look at the clientId in capability to disable it for clients that are known to provide a similar functionality.
Yaml, JDT-LS and probably several others (look for |
One could argue that it's not the responsibility of this server to format the documentation comments and I'm fairly sure that tssever has no capability to do that. Many text editors (including VSCode), handle that (comments formatting) itself through internal functionality, not through language servers. |
Documentation are part of the language, they are formatted according to language-specific specification or convention. If it's not the responsibility of the language server to provide support for language-specific parts of the text edition; then whose is it?
My bad, I didn't look carefully at https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L60 says "client".
What other editor than VSCode do you have in mind that support proper comments formatting? |
SublimeText, which is my primary text editor of choice.
My view on that is that LSP is supposed to provide enhancements to the code editor that are hard or impossible to implement in an editor that is not an IDE. LSP doesn't seem to be that well suited for formatting the document on typing as there is an inherent delay to all responses from an LSP server and that would be especially noticeable and potentially distracting when formatting on typing. Also, JSDoc comments are not even typescript specific. |
@mickaelistria thanks for all these information.
After reading all what you said, I would say that it is the proper LSP way to do it,
Here is the reason why I thought that the text editor should implement this. I tried the PR that you linked - redhat-developer/yaml-language-server#389 In both applications(VS Code, Sublime Text), I just held down Comparing both of those approaches(text editor implementation vs language server implementation) can have it's pros and cons. But because this is LSP spec, doing it on the server now make more sense to me. |
Personally I think it's very unlikely that this will get implemented but will keep it as a feature request. |
Actually my bad, the tsserver supports this feature. But not in the case requested in the first comment. It only sets up the following trigger characters: |
The origin of this request (in WWD) has now been solved by proper use on onEnterRules through TM4E, so it's handled clientside, in the editor. I do think however that lsp's shoulds support onTypeFormatting, to take care stuff like Block comments, trimming trailing whitespace or whatever else makes sense in the language at hand. The lsp specification has the onTypeFormatting command (in addition to document and range formatting events) for a reason, so that any editor out of the box has everything that developers expect of an editor. Editors can then enhance the UX by taking care of some things themselves, like the block comments or trimming whitespace. Imho that wouldn't interfere with onTypeFormatting at all, assuming the editor does its formatting magic BEFORE sending the changes to the lsp for the onTypeFormatting command and the clientside formatting results in the lsp not having to do any formatting anymore, as the code is already formatted accordingly |
Once this feature is supported, this server won't be attempting to implement additional logic on top of what |
Hi,
Originally raised this case with Wild Web Developer (eclipse-wildwebdeveloper/wildwebdeveloper#599), but apparently the behavior comes from here.
When I'm in a multiline comment and hit enter, I expect the new line to automatically get an indent + space + asterisk + space. However, I just get an empty line
Example
before hitting enter:
currently after hitting enter:
expected after hitting enter:
The text was updated successfully, but these errors were encountered: