Qawaz / compose-code-editor

Display & Edit code with syntax highlighting in jetpack compose
https://qawaz.github.io/compose-code-editor
MIT License
68 stars 7 forks source link

Crashing with null language providers #18

Open jakepurple13 opened 7 months ago

jakepurple13 commented 7 months ago

I'm trying to show XML but I keep running into:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Missing language for extension : 
    at com.wakaztahir.codeeditor.prettify.parser.Prettify.getLangFromExtension(Prettify.kt:137)
    at com.wakaztahir.codeeditor.prettify.parser.Prettify.getLexerForExtension(Prettify.kt:404)
    at com.wakaztahir.codeeditor.prettify.parser.Prettify$CreateSimpleLexer.decorate(Prettify.kt:792)
    at com.wakaztahir.codeeditor.prettify.PrettifyParser.parse(PrettifyParser.kt:25)
    at com.wakaztahir.codeeditor.prettify.PrettifyParser.parse(PrettifyParser.kt:21)
wakaztahir commented 7 months ago

You should use html as xml may not be supported. XML is like HTML but not supported at the moment. Its very hard to develop a code editor or syntax highlighter that works with all languages and is small, If you are looking for something special you may have to write it.

jakepurple13 commented 7 months ago

I'm getting the same thing when I use HTML:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Missing language for extension : 
    at com.wakaztahir.codeeditor.prettify.parser.Prettify.getLangFromExtension(Prettify.kt:137)
    at com.wakaztahir.codeeditor.prettify.parser.Prettify.getLexerForExtension(Prettify.kt:404)
    at com.wakaztahir.codeeditor.prettify.parser.Prettify$CreateSimpleLexer.decorate(Prettify.kt:792)
    at com.wakaztahir.codeeditor.prettify.PrettifyParser.parse(PrettifyParser.kt:25)
    at com.wakaztahir.codeeditor.prettify.PrettifyParser.parse(PrettifyParser.kt:18)
    at com.wakaztahir.codeeditor.utils.AnnotationKt.parseCodeAsAnnotatedString(Annotation.kt:21)
    at com.wakaztahir.codeeditor.utils.AnnotationKt.parseCodeAsAnnotatedString(Annotation.kt:30)
wakaztahir commented 7 months ago

Could you please try using the Enum instead of extension, I'm pretty sure it contains HTML entry. Otherwise you can use extension default-markup

defined here https://github.com/Qawaz/compose-code-editor/blob/5b3cb2c9f4340b1a7aa7053f6acdbb2e926d71a4/codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/model/CodeLang.kt#L8

This will probably succeed.

XML extension should succeed as well. Could you try using the enum if that doesn't work, please let me know. https://github.com/Qawaz/compose-code-editor/blob/5b3cb2c9f4340b1a7aa7053f6acdbb2e926d71a4/codeeditor/src/commonMain/kotlin/com/wakaztahir/codeeditor/model/CodeLang.kt#L25

jakepurple13 commented 7 months ago

That is what I'm doing.

val parsedCode = remember(svgText, language) {
                            parseCodeAsAnnotatedString(
                                parser = parser,
                                theme = theme,
                                lang = CodeLang.XML,
                                code = svgText
                            )
}

And it still crashes. Even when using HTML.