Skip to content

Commit

Permalink
fix: java.lang.NoClassDefFoundError: TextMateFile
Browse files Browse the repository at this point in the history
Fixes redhat-developer#815

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Feb 8, 2025
1 parent fc97dde commit 60adee6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/redhat/devtools/lsp4ij/LSPIJTextMateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package com.redhat.devtools.lsp4ij;

import com.intellij.lang.Language;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -24,10 +26,43 @@
@ApiStatus.Internal
public final class LSPIJTextMateUtils {

private static final String TEXTMATE_LANGUAGE_ID = "textmate";

private LSPIJTextMateUtils() {
// Pure utility class
}


/**
* Returns the TextMate language and null otherwise.
*
* @returnthe TextMate language and null otherwise.
*/
@Nullable
public static Language getTextMateLanguage() {
return Language.findLanguageByID(TEXTMATE_LANGUAGE_ID);
}

/**
* Returns true if the given file is a TextMate file and false otherwise.
*
* @param file the file.
* @return true if the given file is a TextMate file and false otherwise.
*/
public static boolean isTextMateFile(@NotNull PsiFile file) {
return TEXTMATE_LANGUAGE_ID.equals(file.getLanguage().getID());
}

/**
* Returns true if the given file is a TextMate file and false otherwise.
*
* @param file the file.
* @return true if the given file is a TextMate file and false otherwise.
*/
public static boolean isTextMateFile(@NotNull VirtualFile file) {
return TEXTMATE_LANGUAGE_ID.equals(file.getFileType().getName());
}

/**
* Returns the simple/single-character brace pairs for the file if it's a TextMate file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.tree.IElementType;
import com.redhat.devtools.lsp4ij.LSPIJTextMateUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateElementType;
import org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateScope;
Expand All @@ -33,7 +34,7 @@ public class TextMateVariableRangeRegistrar implements VariableRangeRegistrar {

@Override
public boolean isApplicable(@NotNull VirtualFile file, @NotNull Project project) {
return "textmate".equals(file.getFileType().getName());
return LSPIJTextMateUtils.isTextMateFile(file);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.textmate.psi.TextMateFile;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -109,7 +108,7 @@ public static Map<Character, Character> getBracePairs(@NotNull PsiFile file) {
@NotNull
private static Map<Character, Character> getBracePairsFwd(@NotNull PsiFile file) {
return CachedValuesManager.getCachedValue(file, () -> {
Map<Character, Character> bracePairs = file instanceof TextMateFile ? LSPIJTextMateUtils.getBracePairs(file) :
Map<Character, Character> bracePairs = LSPIJTextMateUtils.isTextMateFile(file) ? LSPIJTextMateUtils.getBracePairs(file) :
file.getFileType() instanceof AbstractFileType ? getAbstractFileTypeBracePairs(file) :
null;
if (bracePairs == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.redhat.devtools.lsp4ij.LSPIJTextMateUtils;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -29,7 +30,7 @@ public class SimpleLanguageUtils {
// plain/text
languages.add(PlainTextLanguage.INSTANCE);
// textmate
Language textMateLanguage = Language.findLanguageByID("textmate");
Language textMateLanguage = LSPIJTextMateUtils.getTextMateLanguage();
if (textMateLanguage != null) {
languages.add(textMateLanguage);
}
Expand Down

0 comments on commit 60adee6

Please sign in to comment.