Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosemoe committed Aug 3, 2024
2 parents 3be55c2 + 72a267c commit 1e4a884
Show file tree
Hide file tree
Showing 8 changed files with 561 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;

import java.io.Reader;
import java.util.Objects;

import io.github.rosemoe.sora.lang.EmptyLanguage;
import io.github.rosemoe.sora.lang.analysis.AnalyzeManager;
Expand All @@ -51,7 +50,6 @@
import io.github.rosemoe.sora.text.CharPosition;
import io.github.rosemoe.sora.text.ContentReference;
import io.github.rosemoe.sora.util.MyCharacter;
import io.github.rosemoe.sora.widget.SymbolPairMatch;

public class TextMateLanguage extends EmptyLanguage {

Expand Down Expand Up @@ -237,7 +235,10 @@ public void updateLanguage(GrammarDefinition grammarDefinition) {
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
return Objects.requireNonNullElse(textMateAnalyzer, EmptyAnalyzeManager.INSTANCE);
if (textMateAnalyzer == null) {
return EmptyAnalyzeManager.INSTANCE;
}
return textMateAnalyzer;
}

@Override
Expand Down Expand Up @@ -270,6 +271,10 @@ public TextMateNewlineHandler getNewlineHandler() {
return newlineHandler;
}

public LanguageConfiguration getLanguageConfiguration() {
return languageConfiguration;
}

@Override
public TextMateSymbolPairMatch getSymbolPairs() {
return symbolPairMatch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,24 +414,27 @@ public CompleteEnterAction getEnterAction(final Content content, final CharPosit
return null;
}

final EnterAction.IndentAction indentAction = enterResult.indentAction;
String appendText = enterResult.appendText;
final Integer removeText = enterResult.removeText;
// Here we add `\t` to appendText first because enterAction is leveraging
// appendText and removeText to change indentation.
if (enterResult.appendText == null) {
if (enterResult.indentAction == EnterAction.IndentAction.Indent || enterResult.indentAction == EnterAction.IndentAction.IndentOutdent) {
enterResult.appendText = "\t";
if (appendText == null) {
if (indentAction == EnterAction.IndentAction.Indent
|| indentAction == EnterAction.IndentAction.IndentOutdent) {
appendText = "\t";
} else {
enterResult.appendText = "";
appendText = "";
}
} else if (enterResult.indentAction == EnterAction.IndentAction.Indent) {
enterResult.appendText = "\t" + enterResult.appendText;
} else if (indentAction == EnterAction.IndentAction.Indent) {
appendText = "\t" + appendText;
}

final var removeText = enterResult.removeText;
if (removeText != null) {
indentation = indentation.substring(0, indentation.length() - removeText);
}

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

}

Expand All @@ -454,7 +457,7 @@ private String outdentString(final String str) {


private String normalizeIndentation(final String str) {
return TextUtils.normalizeIndentation(str, language.getTabSize(), language.useTab());
return TextUtils.normalizeIndentation(str, language.getTabSize(), !language.useTab());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ IToken[] getResult(final StateStack stack, final int lineLength) {
this._tokens.getLast().setStartIndex(0);
}

return this._tokens.toArray(IToken[]::new);
return this._tokens.toArray(new IToken[0]);
}

int[] getBinaryResult(final StateStack stack, final int lineLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private static CompilePatternsResult _compilePatterns(@Nullable final Collection
}
}

return new CompilePatternsResult(r.toArray(RuleId[]::new), patterns.size() != r.size());
return new CompilePatternsResult(r.toArray(new RuleId[0]), patterns.size() != r.size());
}

private RuleFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -110,7 +111,9 @@ public static String toStringWithIndex(final List<?> list) {
* @return a new list without null elements
*/
public static <T> List<T> noNulls(final @Nullable List<T> coll) {
return coll == null || coll.isEmpty() ? Collections.emptyList() : coll.stream().filter(Objects::nonNull).toList();
return coll == null || coll.isEmpty() ? Collections.emptyList() : coll.stream()
.filter(t -> t != null)
.collect(Collectors.toList());
}

private MoreCollections() {
Expand Down
Loading

0 comments on commit 1e4a884

Please sign in to comment.