@@ -48,12 +48,21 @@ class PicoCodeToolWindowContent(private val project: Project) {
4848 fun getContent (): JComponent {
4949 val panel = JPanel (BorderLayout ())
5050
51- // Server config panel (collapsed by default)
51+ // Server config panel with re-index button
5252 val configPanel = FormBuilder .createFormBuilder()
5353 .addLabeledComponent(" PicoCode Host:" , serverHostField)
5454 .addLabeledComponent(" PicoCode Port:" , serverPortField)
5555 .panel
5656
57+ // Add a re-index button to config panel
58+ val reindexBtn = JButton (" Re-index Project" )
59+ reindexBtn.addActionListener {
60+ reindexProject()
61+ }
62+ val configPanelWithButton = JPanel (BorderLayout ())
63+ configPanelWithButton.add(configPanel, BorderLayout .CENTER )
64+ configPanelWithButton.add(reindexBtn, BorderLayout .SOUTH )
65+
5766 // Chat display area
5867 val chatScrollPane = JBScrollPane (chatArea)
5968 chatScrollPane.border = BorderFactory .createTitledBorder(" Chat" )
@@ -90,7 +99,7 @@ class PicoCodeToolWindowContent(private val project: Project) {
9099 inputPanel.add(buttonPanel, BorderLayout .SOUTH )
91100
92101 // Layout
93- panel.add(configPanel , BorderLayout .NORTH )
102+ panel.add(configPanelWithButton , BorderLayout .NORTH )
94103 panel.add(chatScrollPane, BorderLayout .CENTER )
95104 panel.add(inputPanel, BorderLayout .SOUTH )
96105
@@ -184,6 +193,59 @@ class PicoCodeToolWindowContent(private val project: Project) {
184193 }
185194 }
186195
196+ /* *
197+ * Re-index the current project
198+ */
199+ private fun reindexProject () {
200+ val projectPath = project.basePath ? : return
201+ val host = getServerHost()
202+ val port = getServerPort()
203+
204+ ApplicationManager .getApplication().executeOnPooledThread {
205+ try {
206+ // Get or create project to get project ID
207+ val projectsUrl = URL (" http://$host :$port /api/projects" )
208+ val createConnection = projectsUrl.openConnection() as HttpURLConnection
209+ createConnection.requestMethod = " POST"
210+ createConnection.setRequestProperty(" Content-Type" , " application/json" )
211+ createConnection.doOutput = true
212+
213+ val createBody = gson.toJson(mapOf (
214+ " path" to projectPath,
215+ " name" to project.name
216+ ))
217+ createConnection.outputStream.use { it.write(createBody.toByteArray()) }
218+
219+ val createResponse = createConnection.inputStream.bufferedReader().readText()
220+ val projectData = gson.fromJson(createResponse, JsonObject ::class .java)
221+ val projectId = projectData.get(" id" ).asString
222+
223+ // Trigger re-indexing
224+ val indexUrl = URL (" http://$host :$port /api/projects/index" )
225+ val indexConnection = indexUrl.openConnection() as HttpURLConnection
226+ indexConnection.requestMethod = " POST"
227+ indexConnection.setRequestProperty(" Content-Type" , " application/json" )
228+ indexConnection.doOutput = true
229+
230+ val indexBody = gson.toJson(mapOf (" project_id" to projectId))
231+ indexConnection.outputStream.use { it.write(indexBody.toByteArray()) }
232+
233+ val indexResponse = indexConnection.inputStream.bufferedReader().readText()
234+ val indexData = gson.fromJson(indexResponse, JsonObject ::class .java)
235+
236+ SwingUtilities .invokeLater {
237+ val status = indexData.get(" status" )?.asString ? : " unknown"
238+ appendToChat(" System" , " Re-indexing started. Status: $status " )
239+ }
240+ } catch (e: Exception ) {
241+ SwingUtilities .invokeLater {
242+ appendToChat(" Error" , " Failed to start re-indexing: ${e.message} \n " +
243+ " Make sure PicoCode server is running on http://$host :$port " )
244+ }
245+ }
246+ }
247+ }
248+
187249 /* *
188250 * Clear chat history
189251 */
0 commit comments