Skip to content

Commit e6442e9

Browse files
committed
feature: extract code analyzer to its own class
1 parent 459ba43 commit e6442e9

File tree

7 files changed

+504
-26
lines changed

7 files changed

+504
-26
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ dependencies {
6060
// JGit for repository interaction
6161
implementation("org.eclipse.jgit:org.eclipse.jgit:7.2.1.202505142326-r")
6262

63+
implementation("io.github.tree-sitter:ktreesitter-jvm:0.24.1")
64+
6365
// Testing
6466
testImplementation(kotlin("test"))
6567
testImplementation("io.mockk:mockk:1.14.2")

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.kotlin.dsl.maven
2+
13
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" }
24

35
rootProject.name = "mcp-github-code-analyzer"

src/main/kotlin/mcp/code/analysis/service/CodeAnalyzer.kt renamed to src/main/kotlin/mcp/code/analysis/processor/CodeAnalyzer.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package mcp.code.analysis.service
1+
package mcp.code.analysis.processor
22

33
import java.io.File
44
import kotlin.text.lines
5+
import mcp.code.analysis.service.ModelContextService
56
import org.slf4j.Logger
67
import org.slf4j.LoggerFactory
78

@@ -189,15 +190,9 @@ data class CodeAnalyzer(
189190

190191
val shouldIncludeLine = isDefinition(line) || isCommentLine(line) || state.inCommentBlock
191192
val updatedLines =
192-
if (shouldIncludeLine) {
193-
if (isDefinition(line)) {
194-
// Apply processing to definition lines to ensure braces are complete
195-
state.lines + processDefinitionLine(line)
196-
} else {
197-
state.lines + line
198-
}
199-
} else state.lines
200-
193+
if (shouldIncludeLine)
194+
if (isDefinition(line)) state.lines + processDefinitionLine(line) else state.lines + line
195+
else state.lines
201196
State(updatedLines, nextInCommentBlock)
202197
}
203198

src/main/kotlin/mcp/code/analysis/service/RepositoryAnalysisService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package mcp.code.analysis.service
22

3+
import mcp.code.analysis.processor.CodeAnalyzer
4+
35
/** Service for analyzing Git repositories. */
46
data class RepositoryAnalysisService(
57
private val gitService: GitService = GitService(),

src/test/kotlin/mcp/code/analysis/service/CodeAnalyzerPropertyTest.kt renamed to src/test/kotlin/mcp/code/analysis/processor/CodeAnalyzerPropertyTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package mcp.code.analysis.service
1+
package mcp.code.analysis.processor
22

33
import io.kotest.core.spec.style.StringSpec
44
import io.kotest.matchers.string.shouldContain
55
import io.kotest.matchers.string.shouldStartWith
66
import io.kotest.property.Arb
7-
import io.kotest.property.arbitrary.*
7+
import io.kotest.property.arbitrary.arbitrary
8+
import io.kotest.property.arbitrary.map
9+
import io.kotest.property.arbitrary.string
810
import io.kotest.property.checkAll
911
import io.mockk.mockk
1012
import org.slf4j.Logger
@@ -16,7 +18,7 @@ class CodeAnalyzerPropertyTest :
1618

1719
// Generate valid file paths
1820
fun getPathGenerator(language: String) =
19-
Arb.string(1..50).map { base ->
21+
Arb.Companion.string(1..50).map { base ->
2022
val validPath = base.replace(Regex("[^a-zA-Z0-9/._-]"), "_")
2123
val extension =
2224
when (language) {
@@ -326,50 +328,58 @@ class CodeAnalyzerPropertyTest :
326328
result.shouldContain("// This is a comment")
327329
result.shouldContain("/* Block comment")
328330
}
331+
329332
"java" -> {
330333
result.shouldContain("public class TestClass")
331334
result.shouldContain("interface TestInterface")
332335
result.shouldContain("// This is a comment")
333336
result.shouldContain("/* Block comment")
334337
}
338+
335339
"scala" -> {
336340
result.shouldContain("class TestClass")
337341
result.shouldContain("def testMethod")
338342
result.shouldContain("object Singleton")
339343
result.shouldContain("trait TestTrait")
340344
result.shouldContain("// This is a comment")
341345
}
346+
342347
"python" -> {
343348
result.shouldContain("def test_function")
344349
result.shouldContain("class TestClass")
345350
result.shouldContain("# This is a comment")
346351
}
352+
347353
"ruby" -> {
348354
result.shouldContain("def test_method")
349355
result.shouldContain("class TestClass")
350356
result.shouldContain("module TestModule")
351357
result.shouldContain("# This is a comment")
352358
}
359+
353360
"javascript",
354361
"typescript" -> {
355362
result.shouldContain("function testFunction")
356363
result.shouldContain("class TestClass")
357364
result.shouldContain("const arrowFn")
358365
result.shouldContain("// This is a comment")
359366
}
367+
360368
"go" -> {
361369
result.shouldContain("func testFunction")
362370
result.shouldContain("type TestStruct struct")
363371
result.shouldContain("type TestInterface interface")
364372
result.shouldContain("// This is a comment")
365373
}
374+
366375
"c",
367376
"cpp" -> {
368377
result.shouldContain("void testFunction")
369378
result.shouldContain("struct TestStruct")
370379
result.shouldContain("class TestClass")
371380
result.shouldContain("// This is a comment")
372381
}
382+
373383
"rust" -> {
374384
result.shouldContain("fn test_function")
375385
result.shouldContain("struct TestStruct")

0 commit comments

Comments
 (0)