-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into yair/expose_capabilities_to_chat
- Loading branch information
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v2.22.0 | ||
v2.24.0 |
17 changes: 17 additions & 0 deletions
17
Common/src/main/java/com/tabnineCommon/binary/requests/fileLifecycle/Workspace.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tabnineCommon.binary.requests.fileLifecycle | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.tabnineCommon.binary.BinaryRequest | ||
import com.tabnineCommon.binary.requests.EmptyResponse | ||
|
||
data class Workspace( | ||
@SerializedName("root_paths") private val rootPaths: List<String> | ||
) : BinaryRequest<EmptyResponse> { | ||
override fun response(): Class<EmptyResponse> { | ||
return EmptyResponse::class.java | ||
} | ||
|
||
override fun serialize(): Any { | ||
return mapOf("Workspace" to this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Common/src/main/java/com/tabnineCommon/chat/commandHandlers/WorkspaceFoldersHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import com.google.gson.Gson | ||
import com.google.gson.JsonElement | ||
import com.intellij.openapi.components.ServiceManager | ||
import com.intellij.openapi.project.Project | ||
import com.tabnineCommon.chat.commandHandlers.ChatMessageHandler | ||
import com.tabnineCommon.lifecycle.WorkspaceListenerService | ||
|
||
data class WorkspaceFoldersPayload(private val rootPaths: List<String>) | ||
|
||
class WorkspaceFoldersHandler(gson: Gson) : ChatMessageHandler<Unit, WorkspaceFoldersPayload>(gson) { | ||
private val workspaceService = ServiceManager.getService(WorkspaceListenerService::class.java) | ||
|
||
override fun handle(payload: Unit?, project: Project): WorkspaceFoldersPayload? { | ||
val rootPaths = workspaceService.getWorkspaceRootPaths(project) ?: return null | ||
return WorkspaceFoldersPayload(rootPaths) | ||
} | ||
|
||
override fun deserializeRequest(data: JsonElement?) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Common/src/main/java/com/tabnineCommon/lifecycle/WorkspaceListenerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.tabnineCommon.lifecycle | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.openapi.roots.ProjectRootManager | ||
import com.intellij.util.concurrency.AppExecutorUtil | ||
import com.tabnineCommon.binary.requests.fileLifecycle.Workspace | ||
import com.tabnineCommon.general.DependencyContainer | ||
import java.net.URL | ||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
const val UPDATE_WORKSPACE_INITIAL_DELAY = 5L | ||
const val UPDATE_WORKSPACE_INTERVAL = 30L | ||
|
||
@Service | ||
class WorkspaceListenerService { | ||
private val binaryRequestFacade = DependencyContainer.instanceOfBinaryRequestFacade() | ||
private val scheduler = AppExecutorUtil.getAppScheduledExecutorService() | ||
private val started = AtomicBoolean(false) | ||
|
||
fun start() { | ||
if (started.getAndSet(true)) return | ||
|
||
scheduler.scheduleWithFixedDelay( | ||
{ updateWorkspaceRootPaths() }, | ||
UPDATE_WORKSPACE_INITIAL_DELAY, | ||
UPDATE_WORKSPACE_INTERVAL, | ||
TimeUnit.SECONDS | ||
) | ||
} | ||
|
||
private fun updateWorkspaceRootPaths() { | ||
val rootPaths = ProjectManager.getInstance() | ||
.openProjects | ||
.map { getWorkspaceRootPaths(it) ?: emptyList() } | ||
.reduceOrNull { acc, cur -> acc.plus(cur) } | ||
|
||
if (rootPaths.isNullOrEmpty()) return | ||
Logger.getInstance(javaClass).info("All root paths collected: $rootPaths") | ||
|
||
binaryRequestFacade.executeRequest(Workspace(rootPaths)) | ||
} | ||
|
||
fun getWorkspaceRootPaths(project: Project): List<String>? { | ||
if (project.isDisposed) { | ||
Logger.getInstance(javaClass).warn("Project ${project.name} is disposed, skipping root paths resolution") | ||
return null | ||
} | ||
|
||
val rootPaths = mutableListOf<String>() | ||
for (contentRootUrl in ProjectRootManager.getInstance(project).contentRootUrls) { | ||
val url = URL(contentRootUrl) | ||
if (url.protocol != "file") { | ||
Logger.getInstance(javaClass).debug("$url in project ${project.name} has unsupported protocol (${url.protocol})") | ||
continue | ||
} | ||
rootPaths.add(url.path) | ||
} | ||
|
||
Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $rootPaths") | ||
return rootPaths | ||
} | ||
} |