Skip to content

Commit 472d81f

Browse files
committed
refactor(cpp): improve CLionWorkspaceContextProvider logic
The CLionWorkspaceContextProvider logic was refactored to improve readability and maintainability. The code now checks for the existence of the CMakeLists.txt file before proceeding. Additionally, the code now uses a single if statement to check for the presence of "gtest" or "gmock" in the text, and another if statement to check for the presence of "catch" or "Catch". These changes make the code more concise and efficient.
1 parent 5b374c4 commit 472d81f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

cpp/src/main/kotlin/cc/unitmesh/cpp/provider/CLionWorkspaceContextProvider.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,24 @@ class CLionWorkspaceContextProvider : ChatContextProvider {
6666
return null
6767
}
6868

69-
cmakeWorkspace.cMakeResourceFiles.forEach { file ->
70-
val text = file.readText()
71-
if (text.contains("gtest") || text.contains("gmock")) {
72-
return ChatContextItem(
73-
CLionWorkspaceContextProvider::class,
74-
"The project uses Google Test framework."
75-
)
76-
}
69+
val cmakeLists = File(project.basePath, "CMakeLists.txt")
70+
if (!cmakeLists.exists()) {
71+
return null
72+
}
7773

78-
if (text.contains("catch")) {
79-
return ChatContextItem(
80-
CLionWorkspaceContextProvider::class,
81-
"The project uses Catch2 framework."
82-
)
83-
}
74+
val text = cmakeLists.readText()
75+
if (text.contains("gtest") || text.contains("gmock")) {
76+
return ChatContextItem(
77+
CLionWorkspaceContextProvider::class,
78+
"The project uses Google Test framework."
79+
)
80+
}
81+
82+
if (text.contains("catch") || text.contains("Catch")) {
83+
return ChatContextItem(
84+
CLionWorkspaceContextProvider::class,
85+
"The project uses Catch2 framework."
86+
)
8487
}
8588

8689
return null

0 commit comments

Comments
 (0)