-
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.
DEV2-4218 add support for multi-repo workspace (#685)
* DEV2-4218 add update workspace service * remove workspace folders from init response * remove workspace folders from init response * add "workspace_folders" command
- Loading branch information
Showing
5 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
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() ?: 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
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
package com.tabnineCommon.lifecycle | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.diagnostic.Logger | ||
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 | ||
|
||
@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( | ||
{ | ||
val rootPaths = getWorkspaceRootPaths() ?: return@scheduleWithFixedDelay | ||
binaryRequestFacade.executeRequest(Workspace(rootPaths)) | ||
}, | ||
5, 30, TimeUnit.SECONDS | ||
) | ||
} | ||
|
||
fun getWorkspaceRootPaths(): List<String>? { | ||
val project = ProjectManager.getInstance().openProjects.firstOrNull() ?: return null | ||
if (project.isDisposed) { | ||
Logger.getInstance(javaClass).warn("Project ${project.name} is disposed, skipping workspace update") | ||
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("Skipping workspace update for project ${project.name}, unsupported protocol ${url.protocol}") | ||
continue | ||
} | ||
rootPaths.add(url.path) | ||
} | ||
|
||
Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $rootPaths") | ||
return rootPaths | ||
} | ||
} |