snipmedev / highlights Goto Github PK
View Code? Open in Web Editor NEWKotlin Multiplatform (KMM) syntax highlighting engine
License: Apache License 2.0
Kotlin Multiplatform (KMM) syntax highlighting engine
License: Apache License 2.0
It appears that perhaps something is wrong with snapshots or analyzePartial
. The first test here fails, and the second one passes by avoiding using snapshots altogether. (The second appears to be the way that KodeView
is working currently).
@Test
fun basic_getHighlights_location() {
val highlighter = Highlights.Builder()
.language(SyntaxLanguage.JAVASCRIPT)
.build()
highlighter.setCode("const foo = 'bar';")
val highlights1 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
highlights1.size shouldEqual 4
highlights1[0].location shouldEqual PhraseLocation(start=0, end=5)
highlights1[1].location shouldEqual PhraseLocation(start=10, end=11)
highlights1[2].location shouldEqual PhraseLocation(start=12, end=17)
highlights1[3].location shouldEqual PhraseLocation(start=17, end=18)
highlighter.setCode("const foo = 'barrr';")
val highlights2 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
highlights2.size shouldEqual 4
highlights2[0].location shouldEqual PhraseLocation(start=0, end=5)
highlights2[1].location shouldEqual PhraseLocation(start=10, end=11)
// FAILS HERE:
highlights2[2].location shouldEqual PhraseLocation(start=12, end=19)
highlights2[3].location shouldEqual PhraseLocation(start=19, end=20)
}
@Test
fun basic_getHighlights_location_alt() {
var highlighter = Highlights.Builder()
.language(SyntaxLanguage.JAVASCRIPT)
.build()
highlighter = highlighter
.getBuilder()
.code("const foo = 'bar';")
.build()
val highlights1 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
highlights1.size shouldEqual 4
highlights1[0].location shouldEqual PhraseLocation(start=0, end=5)
highlights1[1].location shouldEqual PhraseLocation(start=10, end=11)
highlights1[2].location shouldEqual PhraseLocation(start=12, end=17)
highlights1[3].location shouldEqual PhraseLocation(start=17, end=18)
highlighter = highlighter
.getBuilder()
.code("const foo = 'barrr';")
.build()
val highlights2 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
highlights2.size shouldEqual 4
highlights2[0].location shouldEqual PhraseLocation(start=0, end=5)
highlights2[1].location shouldEqual PhraseLocation(start=10, end=11)
highlights2[2].location shouldEqual PhraseLocation(start=12, end=19)
highlights2[3].location shouldEqual PhraseLocation(start=19, end=20)
}
private infix fun Any?.shouldEqual(expected: Any?) {
assertEquals(expected, this)
}
To reproduce:
Use Kotlin language,
Highlight
val intent = 0
Highlights "int" which is incorrect
You can reproduce the issue here: https://opensource.respawn.pro/FlowMVI/sample/ (Decompose integration item)
What's interesting, it seems that if the comment is not indented, then the bug does not occur. This started happening after the update from 0.8 to 0.9
Expression
val KOTLIN_KEYWORDS = JAVA_KEYWORDS + (...)
Is incorrect
There are no byte, extends, implements, instanceof, native, strictfp, synchronized, throws, transient
keywords
Using c keywords for java (and Kotlin) is incorrect
Using common keywords for java (Kotlin) is incorrect for the same reason
Many themes, including OneDark proposed in #33 contain highlighting of variables. We can find variables by assignment, val
or other keyword preceding the declaration, or lack of braces after usage.
In kotlin, ?
, !!
, !
, _
should be highlighted as punctuation, but they use code
color right now. I can't unfortunately search for what marks are missing in other languages, as I'm not familiar with those, but I'm sure there are other missing punct chars
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.