How to implement complicated auto-indentation in VScode

后端 未结 2 1374
星月不相逢
星月不相逢 2021-01-19 15:59

I am working on a language extension for SAS for VScode. I previously worked on the SAS language extension for Atom (https://github.com/akanosora/language-sas) as well as Vi

相关标签:
2条回答
  • 2021-01-19 16:26

    You can add the data and proc keywords themselves to the "decreaseIndentPattern" rule. This way, these keywords will serve for both un-indenting the current line, and starting a new indentation block on the next line.

    Consider this, for example:

    "indentationRules": {
        "increaseIndentPattern": "^\\s*(proc|data)\\s+.*;\\s*$",
        "decreaseIndentPattern": "^\\s*(run|((proc|data)\\s+.*))\\s*;"
    }
    
    0 讨论(0)
  • 2021-01-19 16:34

    For more advanced indentation, you could look into using a formatter alongside the regular expression based indentation rules. To add a custom formatter, your extension should implement DocumentRangeFormattingEditProvider and then register the with VS Code by calling registerDocumentRangeFormattingEditProvider

    Formatters must normally be invoked by the user. However users can also enable formatting as they type by setting "editor.formatOnType": true. For this case, your extension should also implement OnTypeFormattingEditProvider and register the on-type formatter by calling registerOnTypeFormattingEditProvider

    0 讨论(0)
提交回复
热议问题