Skip to content

Commit

Permalink
feat(lang-textmate): merge upstream of tm4e update & fix #537
Browse files Browse the repository at this point in the history
Update taken from eclipse-tm4e/tm4e@1d2beb8
  • Loading branch information
dingyi222666 authored and Rosemoe committed Jan 30, 2024
1 parent 23cb421 commit b781789
Show file tree
Hide file tree
Showing 70 changed files with 3,848 additions and 3,719 deletions.
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jcodings = { module = "org.jruby.jcodings:jcodings", version = "1.0.58" }
joni = { module = "org.jruby.joni:joni", version = "2.2.1" }
snakeyaml-engine = { module = "org.snakeyaml:snakeyaml-engine", version = "2.2" }
jdt-annotation = { module = "org.eclipse.jdt:org.eclipse.jdt.annotation", version = "2.2.800" }
guava = { module = "com.google.guava:guava", version = "33.0.0-android" }

tests-google-truth = { module = "com.google.truth:truth", version = "1.3.0" }
tests-robolectric = { module = "org.robolectric:robolectric", version = "4.11.1" }
Expand Down
1 change: 0 additions & 1 deletion language-textmate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dependencies {

implementation(libs.snakeyaml.engine)
implementation(libs.jdt.annotation)
implementation(libs.guava)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@

import androidx.annotation.NonNull;

import org.eclipse.tm4e.core.grammar.IGrammar;
import org.eclipse.tm4e.core.internal.grammar.tokenattrs.EncodedTokenAttributes;
import org.eclipse.tm4e.core.internal.grammar.tokenattrs.StandardTokenType;
import org.eclipse.tm4e.core.internal.oniguruma.OnigRegExp;
import org.eclipse.tm4e.core.internal.oniguruma.OnigResult;
import org.eclipse.tm4e.core.internal.oniguruma.OnigString;
import org.eclipse.tm4e.core.internal.theme.FontStyle;
import org.eclipse.tm4e.core.internal.theme.Theme;
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;

import java.time.Duration;
import java.util.Collections;
import java.util.List;
Expand All @@ -47,18 +57,6 @@
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel;
import io.github.rosemoe.sora.langs.textmate.utils.StringUtils;
import io.github.rosemoe.sora.text.Content;

import org.eclipse.tm4e.core.grammar.IGrammar;

import org.eclipse.tm4e.core.internal.grammar.tokenattrs.EncodedTokenAttributes;
import org.eclipse.tm4e.core.internal.grammar.tokenattrs.StandardTokenType;
import org.eclipse.tm4e.core.internal.oniguruma.OnigRegExp;
import org.eclipse.tm4e.core.internal.oniguruma.OnigResult;
import org.eclipse.tm4e.core.internal.oniguruma.OnigString;
import org.eclipse.tm4e.core.internal.theme.FontStyle;
import org.eclipse.tm4e.core.internal.theme.Theme;
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration;

import io.github.rosemoe.sora.text.ContentLine;
import io.github.rosemoe.sora.text.ContentReference;
import io.github.rosemoe.sora.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ public void applyDefault() {
RawTheme rawSubTheme;

if (settings == null) {
Log.e("theme", "load vscode theme");
rawSubTheme = ((RawTheme) ((RawTheme) rawTheme).get("colors"));

applyVSCTheme(rawSubTheme);
} else {
Log.e("theme", "load default theme");
rawSubTheme = (RawTheme) ((List<?>) settings).get(0);
rawSubTheme = (RawTheme) rawSubTheme.getSetting();

Expand All @@ -127,8 +125,6 @@ public void applyDefault() {


private void applyVSCTheme(RawTheme RawTheme) {
Log.e("vsc theme",
Arrays.toString(Collections.singletonList(RawTheme).toArray()));
setColor(LINE_DIVIDER, Color.TRANSPARENT);

String caret = (String) RawTheme.get("editorCursor.foreground");
Expand All @@ -153,8 +149,6 @@ private void applyVSCTheme(RawTheme RawTheme) {
}

String background = (String) RawTheme.get("editor.background");
Log.e("vsc forge", RawTheme.toString());
Log.e("vsc ??", background + "??");
if (background != null) {
setColor(WHOLE_BACKGROUND, Color.parseColor(background));
setColor(LINE_NUMBER_BACKGROUND, Color.parseColor(background));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.eclipse.tm4e.core.grammar.IGrammar;
import org.eclipse.tm4e.core.registry.IGrammarSource;
import org.eclipse.tm4e.core.registry.IThemeSource;
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration;
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;

import java.io.Reader;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.eclipse.tm4e.languageconfiguration.model.CompleteEnterAction;
import org.eclipse.tm4e.languageconfiguration.model.EnterAction;
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration;
import org.eclipse.tm4e.languageconfiguration.supports.IndentRulesSupport;
import org.eclipse.tm4e.languageconfiguration.supports.OnEnterSupport;
import org.eclipse.tm4e.languageconfiguration.utils.TabSpacesInfo;

import org.eclipse.tm4e.languageconfiguration.internal.model.CompleteEnterAction;
import org.eclipse.tm4e.languageconfiguration.internal.model.EnterAction;
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;
import org.eclipse.tm4e.languageconfiguration.internal.supports.IndentRulesSupport;
import org.eclipse.tm4e.languageconfiguration.internal.supports.OnEnterSupport;
import org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils;

import java.util.Arrays;
import java.util.regex.Pattern;

import io.github.rosemoe.sora.lang.smartEnter.NewlineHandleResult;
import io.github.rosemoe.sora.lang.smartEnter.NewlineHandler;
import io.github.rosemoe.sora.lang.styling.Styles;

import org.eclipse.tm4e.languageconfiguration.utils.TextUtils;

import io.github.rosemoe.sora.text.CharPosition;
import io.github.rosemoe.sora.text.Content;

Expand Down Expand Up @@ -149,7 +146,7 @@ public NewlineHandleResult handleNewline(@NonNull Content text, @NonNull CharPos
return new NewlineHandleResult(typeText, caretOffset);
}
case Outdent:
final var indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, getTabSpaces());
final var indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, language.getTabSize(), language.useTab());
final var outdentedText = outdentString(normalizeIndentation(indentation + enterAction.appendText));

var caretOffset = outdentedText.length() + 1;
Expand Down Expand Up @@ -179,7 +176,6 @@ protected Pair<String, String> getIndentForEnter(Content text, CharPosition posi

var afterEnterAction = getInheritIndentForLine(new WrapperContentImp(text, position.line, beforeEnterText), true, position.line + 1);

var tabSpaces = TextUtils.getTabSpaces(language);

if (afterEnterAction == null) {
return new Pair<>(beforeEnterIndent, beforeEnterIndent);
Expand All @@ -188,8 +184,8 @@ protected Pair<String, String> getIndentForEnter(Content text, CharPosition posi
var afterEnterIndent = afterEnterAction.indentation;
var indent = "";

if (tabSpaces.isInsertSpaces()) {
indent = " ".repeat(tabSpaces.getTabSize());
if (language.useTab()) {
indent = " ".repeat(language.getTabSize());
} else {
indent = "\t";
}
Expand Down Expand Up @@ -435,7 +431,7 @@ public CompleteEnterAction getEnterAction(final Content content, final CharPosit
indentation = indentation.substring(0, indentation.length() - removeText);
}

return new CompleteEnterAction(enterResult, indentation);
return new CompleteEnterAction(enterResult.indentAction, enterResult.appendText, enterResult.removeText, indentation);

}

Expand All @@ -444,9 +440,9 @@ private String outdentString(final String str) {
if (str.startsWith("\t")) { // $NON-NLS-1$
return str.substring(1);
}
final TabSpacesInfo tabSpaces = getTabSpaces();
if (tabSpaces.isInsertSpaces()) {
final char[] chars = new char[tabSpaces.getTabSize()];

if (language.useTab()) {
final char[] chars = new char[language.getTabSize()];
Arrays.fill(chars, ' ');
final String spaces = new String(chars);
if (str.startsWith(spaces)) {
Expand All @@ -458,12 +454,7 @@ private String outdentString(final String str) {


private String normalizeIndentation(final String str) {
final TabSpacesInfo tabSpaces = getTabSpaces();
return TextUtils.normalizeIndentation(str, tabSpaces.getTabSize(), tabSpaces.isInsertSpaces());
}

private TabSpacesInfo getTabSpaces() {
return TextUtils.getTabSpaces(language);
return TextUtils.normalizeIndentation(str, language.getTabSize(), language.useTab());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@
*/
package io.github.rosemoe.sora.langs.textmate;

import org.eclipse.tm4e.core.internal.grammar.tokenattrs.EncodedTokenAttributes;
import org.eclipse.tm4e.core.internal.grammar.tokenattrs.StandardTokenType;
import org.eclipse.tm4e.languageconfiguration.model.AutoClosingPairConditional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import io.github.rosemoe.sora.lang.styling.Span;
import io.github.rosemoe.sora.text.Content;
import io.github.rosemoe.sora.text.ContentLine;
import io.github.rosemoe.sora.widget.CodeEditor;
import io.github.rosemoe.sora.widget.SymbolPairMatch;

import org.eclipse.tm4e.languageconfiguration.internal.model.AutoClosingPairConditional;

public class TextMateSymbolPairMatch extends SymbolPairMatch {

private static final String surroundingPairFlag = "surroundingPair";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.tm4e.core.registry.IGrammarSource;
import org.eclipse.tm4e.core.registry.IThemeSource;
import org.eclipse.tm4e.core.registry.Registry;
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration;
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;

import java.io.InputStreamReader;
import java.io.Reader;
Expand Down
Loading

0 comments on commit b781789

Please # to comment.