Skip to content

Commit

Permalink
refactor: split line comments for content
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 17, 2023
1 parent b097741 commit fa921bf
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 6 deletions.
13 changes: 13 additions & 0 deletions code-modules/code-language/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
java
alias(libs.plugins.jvm)
alias(libs.plugins.serialization)
}

dependencies {
implementation(libs.serialization.json)

testImplementation(libs.bundles.test)
testRuntimeOnly(libs.test.junit.engine)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.cf.language
package cc.unitmesh.language

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.cf.language
package cc.unitmesh.language

import kotlinx.serialization.json.Json
import java.io.File
Expand Down Expand Up @@ -46,6 +46,11 @@ class LanguageService {
return languageMap[language]?.lineComment?.get(0)
}

fun isCommentLine(language: String, line: String): Boolean {
val lineComment = guessLineComment(language) ?: return false
return line.trimStart().startsWith(lineComment)
}

/**
* DetermineLanguage given a filename, fallback language, possible languages and content make a guess to the type.
* If multiple possible it will guess based on keywords similar to how https://github.com/vmchale/polyglot does
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.cf.language
package cc.unitmesh.language

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.cf.language;
package cc.unitmesh.language;

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.unitmesh.cf.language
package cc.unitmesh.language

import cc.unitmesh.cf.language.TokenType.*
import cc.unitmesh.language.TokenType.*
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include(":llm-tools:interpreter")
include(":llm-tools:web-tools")

include(":code-modules:code-splitter")
include(":code-modules:code-language")
include(":code-modules:git-differ")
include(":code-modules:git-commit-message")

Expand Down

0 comments on commit fa921bf

Please sign in to comment.