Skip to content

Commit b237c81

Browse files
committed
fix: onEnter rules inconsistencies between API and JSON properties.
Fixes #13 VScode has inconsistencies between it's API and the language configuration JSON files. In the onEnter rules, JSON files have the property `action.indent` whereas the API has `action.indentAction`. When merging the auto-found language config files and the extension's onEnter comment rules, VScode couldn't handle the mixed formats properly, causing the brace malfunction in #13. Fixed by normalizing the property to the API format and converting it's values. - Added new `normalizeOnEnterRules` to normalize onEnter rules to use the API format, and added the method call at the end of the `setLanguageConfiguration` method.
1 parent fadcff5 commit b237c81

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/configuration.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ export class Configuration {
856856
};
857857
}
858858

859+
// Normalize all onEnter rules to use consistent API format (for all languages)
860+
if (langConfig.onEnterRules) {
861+
this.normalizeOnEnterRules(langConfig.onEnterRules);
862+
}
863+
859864
this.logger.debug(`The language config for ${langId}:`, langConfig);
860865

861866
return vscode.languages.setLanguageConfiguration(langId, langConfig);
@@ -1010,4 +1015,42 @@ export class Configuration {
10101015
this.logger.debug("The supported languages for multi-line blocks:", utils.readJsonFile(this.multiLineLangDefinitionFilePath));
10111016
this.logger.debug("The supported languages for single-line blocks:", utils.readJsonFile(this.singleLineLangDefinitionFilePath));
10121017
}
1018+
1019+
/**
1020+
* Normalize onEnter rules to use consistent API format.
1021+
* Converts JSON format (indent: "string") to API format (indentAction: enum).
1022+
*
1023+
* This prevents the inconsistent format between language configurations in JSON files
1024+
* and the dynamically using the API from causing issues with onEnterRules not working properly.
1025+
*
1026+
* @param {vscode.OnEnterRule[]} rules The onEnter rules to normalize.
1027+
*/
1028+
private normalizeOnEnterRules(rules: vscode.OnEnterRule[]): void {
1029+
if (!rules) return;
1030+
1031+
rules.forEach((rule) => {
1032+
if (rule.action && "indent" in rule.action) {
1033+
// Convert JSON format to API format
1034+
const indentValue = (rule.action as any).indent;
1035+
delete (rule.action as any).indent;
1036+
1037+
// Map string values to IndentAction enum values
1038+
switch (indentValue) {
1039+
case "indent":
1040+
rule.action.indentAction = vscode.IndentAction.Indent;
1041+
break;
1042+
case "outdent":
1043+
rule.action.indentAction = vscode.IndentAction.Outdent;
1044+
break;
1045+
case "indentOutdent":
1046+
rule.action.indentAction = vscode.IndentAction.IndentOutdent;
1047+
break;
1048+
case "none":
1049+
default:
1050+
rule.action.indentAction = vscode.IndentAction.None;
1051+
break;
1052+
}
1053+
}
1054+
});
1055+
}
10131056
}

0 commit comments

Comments
 (0)