Skip to content
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

Align onEnterRule#indent JSON loading with vscode specification #438

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ public enum IndentAction {
* indentation).
*/
Outdent;

public static IndentAction get(@Nullable String value) {
// see
// https://github.com/microsoft/vscode/blob/13ba7bb446a638d37ebccb1a7d74e31c32bb9790/src/vs/workbench/contrib/codeEditor/browser/languageConfigurationExtensionPoint.ts#L341
if (value == null) {
return IndentAction.None;
}
switch (value) {
case "none":
return IndentAction.None;
case "indent":
return IndentAction.Indent;
case "indentOutdent":
return IndentAction.IndentOutdent;
case "outdent":
return IndentAction.Outdent;
default:
return IndentAction.None;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

/**
* The language configuration interface defines the contract between extensions and various editor features, like
Expand Down Expand Up @@ -62,10 +63,10 @@ public static LanguageConfiguration load(@NonNull final Reader reader) {
final var actionElem = jsonObj.get("action"); //$NON-NLS-1$
if (actionElem != null && actionElem.isJsonObject()) {
final var actionJsonObj = actionElem.getAsJsonObject();
final var indentActionString = getAsString(actionJsonObj.get("indentAction")); //$NON-NLS-1$
final var indentActionString = getAsString(actionJsonObj.get("indent")); //$NON-NLS-1$
if (indentActionString != null) {
final var afterText = getAsPattern(jsonObj.get("afterText")); //$NON-NLS-1$
final var indentAction = IndentAction.valueOf(indentActionString);
final var indentAction = IndentAction.get(indentActionString);
final var removeText = getAsInteger(actionJsonObj.get("removeText")); //$NON-NLS-1$
final var appendText = getAsString(actionJsonObj.get("appendText")); //$NON-NLS-1$
final var action = new EnterAction(indentAction);
Expand Down Expand Up @@ -206,10 +207,28 @@ public static LanguageConfiguration load(@NonNull final Reader reader) {

@Nullable
private static Pattern getAsPattern(@Nullable final JsonElement element) {
final var pattern = getAsString(element);
final var pattern = getPattern(element);
return pattern == null ? null : RegExpUtils.create(pattern);
}

@Nullable
private static String getPattern(@Nullable final JsonElement element) {
if (element == null) {
return null;
}
if (element.isJsonObject()) {
// ex : { "pattern": "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>", "flags": "i" }
var pattern = getAsString(((JsonObject) element).get("pattern"));
if (pattern == null) {
return null;
}
var flags = getAsString(((JsonObject) element).get("flags"));
return flags != null ? pattern + "(?" + flags + ")" : pattern;
}
// ex : "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>"
return getAsString(element);
}

@Nullable
private static String getAsString(@Nullable final JsonElement element) {
if (element == null) {
Expand Down