Skip to content

Disable automatic insertion of "---@" on Enter #2861

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

Open
swajj opened this issue Sep 20, 2024 · 5 comments
Open

Disable automatic insertion of "---@" on Enter #2861

swajj opened this issue Sep 20, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@swajj
Copy link

swajj commented Sep 20, 2024

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Annotations, Completion, Formatting

Expected Behaviour

When I hit Enter at the end of a class/parameter/etc. annotation, I get a new blank line.

Actual Behaviour

When I type an annotation and hit Enter, I get ---@ automatically inserted.

Reproduction steps

  1. Type ---@class test
  2. Press Enter

Additional Notes

I know this is an "intentional feature", but I would like a way to disable it. There is no setting that disables this (and only this) - turning "Editor: Auto Indent" to 'brackets' or lower disables this unwanted behavior, but then I lose auto-indent.

See #2786

Log File

No response

@swajj
Copy link
Author

swajj commented Sep 20, 2024

I could also work with something like immediately pressing enter on the lone ---@ causes it to revert to a blank line.

@CppCXY CppCXY added the enhancement New feature or request label Sep 20, 2024
@CppCXY
Copy link
Member

CppCXY commented Sep 20, 2024

I think a better approach would be to provide ---@ completion options after pressing Enter, rather than directly adding ---@.

@swajj
Copy link
Author

swajj commented Sep 20, 2024 via email

@tomlau10
Copy link
Contributor

I could also work with something like immediately pressing enter on the lone ---@ causes it to revert to a blank line.

Great idea 👍 However currently the "feature" of adding ---@ seems to be implemented using the onEnterRule of vscode's api: https://code.visualstudio.com/api/language-extensions/language-configuration-guide#on-enter-rules
And after reading the doc, seems it only supports removing indent on the inserted line, but not removing text on the original line. ☹️


Another Suggestion: shift+enter to trigger doc comment continuation

Just another idea, it would be awesome if vscode supports some modifier key when defining those onEnterRule (unfortunately not...). For example some rules only be triggered when pressing shift+enter. Then we can have something like:

  • normal enter => just insert newline with indent
  • shift+enter => if current line starts with \s*---@, inserts ---@ as well, otherwise acts as normal newline

‼️ And then I found out that rust-analyzer has implemented an onEnter command, which is doing this doc comment continuation when triggering it. And then it lets user set a keybind, say shift+enter to trigger this. Maybe this can be considered as well? 😄
https://rust-analyzer.github.io/manual.html#on-enter

  • if we want normal enter => just press enter
  • if we want doc comment continuation => set the shift+enter keybind once, and press shift+enter
    (or even make this keybinding default / has option to toggle)

Current workaround

I can somewhat achieve this behavior by editing my keybindings.json:
(ref: https://stackoverflow.com/a/73321689)

    {
        "key": "enter",
        "command": "runCommands",
        "args": {
          "commands": [
            { "command": "editor.action.insertSnippet", "args": { "snippet": "\n" } },
            "editor.action.reindentselectedlines",
          ]
        },
        "when": "editorLangId == 'lua' && editorTextFocus && !suggestWidgetVisible"
    },
  • by leveraging insertSnippet with \n, it will skip all those onEnterRules or indent, just adding a plain newline
  • then we reindent the newly inserted line
    • this can then skip the ---@ when just pressing enter
    • while shift+enter will still trigger normal onEnterRules with ---@ insertion (because no action is binded to this key)
  • ⚠️ however the downside is that, it cannot remove empty newlines if the line above is just containing spaces ☹️
    (this function seems to be provided by vscode by hooking the enter action, but now we are just inserting \n)

@sumneko
Copy link
Collaborator

sumneko commented Sep 23, 2024

I will provide a setting in the next version.

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

4 participants