Skip to content

Allow LanguageConfiguration.onEnterRules to be defined in the language configuration file #114348

@alexdima

Description

@alexdima

Currently, onEnterRules can only be defined imperatively, via vscode.languages.setLanguageConfiguration. Most of the other language configuration properties can already today be defined descriptively, in the language configuration file (contributes.languages.configuration).

It would make sense to allow onEnterRules to be defined in the language configuration file to align with the other properties.

The only problematic thing is the schema for such rules because in the imperative version an enum is used, IndentAction and it might make sense to use a string value with the enum name in JSON.

For example (imperative variant):

vscode.languages.setLanguageConfiguration('python', {
  onEnterRules: [
		{
			beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\s*$/,
			action: { indentAction: vscode.IndentAction.Indent }
		}
	]
});

language-configuration.json proposal:

{
  "onEnterRules": [
    {
      "beforeText": "^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$",
      // regexes can also explicitly define flags with this format: { "pattern": "...", "flags": "iu" }
      // "afterText": "", // optional regex for the text after the cursor on the current line
      // "oneLineAboveText": "", // optional regex for the text one line above
      "action": {
        "indent": "indent", // other values "none","indent", "indentoutdent", "outdent"
        "appendText": "", // optional text to be appended after the enter
        "removeText": 0 // optional char count to delete
      }
    }
  ]
}

cc @dbaeumer

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions