Skip to content

Commit

Permalink
chore(intellij): bump supported sinceBuild to 231. (#2635)
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Jul 14, 2024
1 parent 8778da4 commit 0e0a882
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 41 deletions.
4 changes: 2 additions & 2 deletions clients/intellij/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version.set("2024.1")
version.set("2023.1")
type.set("IC") // Target IDE Platform
plugins.set(listOf("Git4Idea"))
}
Expand All @@ -35,7 +35,7 @@ tasks {
}

patchPluginXml {
sinceBuild.set("222")
sinceBuild.set("231")
changeNotes.set(provider {
changelog.renderItem(
changelog.getLatest(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.tabbyml.intellijtabby.events.CombinedState
Expand All @@ -19,11 +20,11 @@ import kotlinx.coroutines.launch
class CheckIssueDetail : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getRequiredData(CommonDataKeys.PROJECT)
val combinedState = project.service<CombinedState>()
val combinedState = project.serviceOrNull<CombinedState>() ?: return
val issueName = combinedState.state.agentIssue ?: return

val settings = service<SettingsService>()
val connectionService = project.service<ConnectionService>()
val connectionService = project.serviceOrNull<ConnectionService>() ?: return
val scope = CoroutineScope(Dispatchers.IO)

scope.launch {
Expand Down Expand Up @@ -109,7 +110,7 @@ class CheckIssueDetail : AnAction() {
override fun update(e: AnActionEvent) {
e.presentation.isEnabled = e.project != null && e.getData(CommonDataKeys.PROJECT) != null
val project = e.getData(CommonDataKeys.PROJECT) ?: return
val combinedState = project.service<CombinedState>()
val combinedState = project.serviceOrNull<CombinedState>() ?: return

val muted = mutableListOf<String>()
if (combinedState.state.settings.notificationsMuted.contains("completionResponseTimeIssues")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.tabbyml.intellijtabby.actionPromoter.HasPriority
import com.tabbyml.intellijtabby.completion.InlineCompletionService


class TriggerInlineCompletion : AnAction(), HasPriority {
override fun actionPerformed(e: AnActionEvent) {
val inlineCompletionService = e.getRequiredData(CommonDataKeys.PROJECT).service<InlineCompletionService>()
val inlineCompletionService =
e.getRequiredData(CommonDataKeys.PROJECT).serviceOrNull<InlineCompletionService>() ?: return
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
val offset = editor.caretModel.primaryCaret.offset
inlineCompletionService.provideInlineCompletion(editor, offset, manually = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tabbyml.intellijtabby.actions.inlineCompletion

import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorAction
Expand All @@ -12,12 +12,12 @@ import com.tabbyml.intellijtabby.completion.InlineCompletionService
abstract class InlineCompletionAction(private val inlineCompletionHandler: InlineCompletionActionHandler) :
EditorAction(object : EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
val inlineCompletionService = editor.project?.service<InlineCompletionService>() ?: return
val inlineCompletionService = editor.project?.serviceOrNull<InlineCompletionService>() ?: return
inlineCompletionHandler.doExecute(editor, caret, inlineCompletionService)
}

override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
val inlineCompletionService = editor.project?.service<InlineCompletionService>() ?: return false
val inlineCompletionService = editor.project?.serviceOrNull<InlineCompletionService>() ?: return false
return inlineCompletionService.isInlineCompletionVisibleAt(
editor,
caret.offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class TabAccept : InlineCompletionAction(object : InlineCompletionActionHandler
inlineCompletionService.accept(editor, caret?.offset, InlineCompletionService.AcceptType.FULL_COMPLETION)
}

override fun isEnabledForCaret(editor: Editor, caret: Caret, inlineCompletionService: InlineCompletionService): Boolean {
override fun isEnabledForCaret(
editor: Editor,
caret: Caret,
inlineCompletionService: InlineCompletionService
): Boolean {
return !inlineCompletionService.isInlineCompletionStartWithIndentation()
}
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
Expand Down Expand Up @@ -40,7 +41,7 @@ class InlineCompletionService(private val project: Project) : Disposable {
private val messageBusConnection = project.messageBus.connect()
private val editorManager = FileEditorManager.getInstance(project)
private val scope = CoroutineScope(Dispatchers.IO)
private suspend fun getServer() = project.service<ConnectionService>().getServerAsync()
private suspend fun getServer() = project.serviceOrNull<ConnectionService>()?.getServerAsync()

private val settings = service<SettingsService>()
private val renderer = InlineCompletionRenderer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tabbyml.intellijtabby.events

import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.tabbyml.intellijtabby.completion.InlineCompletionService
Expand All @@ -12,11 +12,11 @@ import kotlinx.coroutines.launch
class StartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
// initialize services
val connectionService = project.service<ConnectionService>()
val connectionService = project.serviceOrNull<ConnectionService>()
CoroutineScope(Dispatchers.IO).launch {
connectionService.getServerAsync()
connectionService?.getServerAsync()
}
project.service<CombinedState>()
project.service<InlineCompletionService>()
project.serviceOrNull<CombinedState>()
project.serviceOrNull<InlineCompletionService>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tabbyml.intellijtabby.lsp

import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.keymap.Keymap
import com.intellij.openapi.keymap.KeymapManagerListener
import com.intellij.openapi.project.Project
Expand All @@ -15,11 +16,11 @@ import com.tabbyml.intellijtabby.settings.SettingsState
class ConfigurationSync(private val project: Project) : Disposable {
private val messageBusConnection = project.messageBus.connect()
private val settings = service<SettingsService>()
private val keymapSettings = project.service<KeymapSettings>()
private val keymapSettings = project.serviceOrNull<KeymapSettings>()

data class SettingsData(
val settings: SettingsService.Settings,
val keymap: KeymapSettings.KeymapStyle,
val keymap: KeymapSettings.KeymapStyle?,
) {
fun withSettings(settings: SettingsService.Settings): SettingsData {
return SettingsData(settings, keymap)
Expand All @@ -32,13 +33,13 @@ class ConfigurationSync(private val project: Project) : Disposable {

private var cached: SettingsData = SettingsData(
settings.settings(),
keymapSettings.getCurrentKeymapStyle(),
keymapSettings?.getCurrentKeymapStyle(),
)

fun getConfiguration(): ClientProvidedConfig {
cached = SettingsData(
settings.settings(),
keymapSettings.getCurrentKeymapStyle(),
keymapSettings?.getCurrentKeymapStyle(),
)
return buildClientProvidedConfig(cached)
}
Expand All @@ -51,11 +52,12 @@ class ConfigurationSync(private val project: Project) : Disposable {
}
})
messageBusConnection.subscribe(KeymapManagerListener.TOPIC, object : KeymapManagerListener {
override fun shortcutsChanged(keymap: Keymap, actionIds: MutableCollection<String>, fromSettings: Boolean) {
val current = keymapSettings.getCurrentKeymapStyle()
if (cached.keymap !== current) {
cached = cached.withKeymap(current)
notifyServer(server)
override fun shortcutChanged(keymap: Keymap, actionId: String, fromSettings: Boolean) {
keymapSettings?.getCurrentKeymapStyle()?.let {
if (cached.keymap !== it) {
cached = cached.withKeymap(it)
notifyServer(server)
}
}
}
})
Expand Down Expand Up @@ -87,6 +89,7 @@ class ConfigurationSync(private val project: Project) : Disposable {
KeymapSettings.KeymapStyle.DEFAULT -> ClientProvidedConfig.Keybindings.DEFAULT
KeymapSettings.KeymapStyle.TABBY_STYLE -> ClientProvidedConfig.Keybindings.TABBY_STYLE
KeymapSettings.KeymapStyle.CUSTOMIZE -> ClientProvidedConfig.Keybindings.CUSTOMIZE
null -> ClientProvidedConfig.Keybindings.DEFAULT
},
anonymousUsageTracking = ClientProvidedConfig.AnonymousUsageTrackingConfig(
disable = settings.isAnonymousUsageTrackingDisabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.progress.runBlockingCancellable
import com.intellij.openapi.project.Project
import com.intellij.util.EnvironmentUtil
import com.intellij.util.messages.Topic
import com.intellij.util.progress.sleepCancellable
import com.tabbyml.intellijtabby.lsp.protocol.server.LanguageServer
import com.tabbyml.intellijtabby.notifications.notifyInitializationFailed
import com.tabbyml.intellijtabby.settings.SettingsService
import kotlinx.coroutines.delay
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import org.eclipse.lsp4j.InitializedParams
Expand Down Expand Up @@ -87,7 +88,11 @@ class ConnectionService(private val project: Project) : Disposable {
} catch (e: InitializationException) {
logger.warn("Failed to initialize connection.", e)
if (retry < 5) {
sleepCancellable(1000)
val initRetryDelay: Long = 1000
@Suppress("UnstableApiUsage")
runBlockingCancellable {
delay(initRetryDelay)
}
initialize(retry + 1)
} else {
publisher.connectionStateChanged(State.INITIALIZATION_FAILED)
Expand Down Expand Up @@ -122,7 +127,7 @@ class ConnectionService(private val project: Project) : Disposable {

private fun getNodeBinary(): File {
val node = settings.nodeBinary.let {
if (!it.isNullOrBlank()) {
if (it.isNotBlank()) {
val path = it.replaceFirst(Regex("^~"), System.getProperty("user.home"))
File(path)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.tabbyml.intellijtabby.lsp
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -35,7 +35,7 @@ class LanguageClient(private val project: Project) : com.tabbyml.intellijtabby.l
private val scope = CoroutineScope(Dispatchers.IO)
private val virtualFileManager = VirtualFileManager.getInstance()
private val psiManager = PsiManager.getInstance(project)
private val gitProvider = project.service<GitProvider>()
private val gitProvider = project.serviceOrNull<GitProvider>()
private val configurationSync = ConfigurationSync(project)
private val textDocumentSync = TextDocumentSync(project)

Expand Down Expand Up @@ -67,7 +67,7 @@ class LanguageClient(private val project: Project) : com.tabbyml.intellijtabby.l
},
tabby = TabbyClientCapabilities(
agent = true,
gitProvider = true,
gitProvider = gitProvider?.isSupported(),
editorOptions = true,
),
), workspaceFolders = getWorkspaceFolders()
Expand Down Expand Up @@ -110,7 +110,7 @@ class LanguageClient(private val project: Project) : com.tabbyml.intellijtabby.l
}

override fun gitRepository(params: GitRepositoryParams): CompletableFuture<GitRepository?> {
val repository = gitProvider.getRepository(params.uri)?.let { repo ->
val repository = gitProvider?.getRepository(params.uri)?.let { repo ->
GitRepository(root = repo.root, remotes = repo.remotes?.map {
GitRepository.Remote(
name = it.name,
Expand All @@ -124,7 +124,7 @@ class LanguageClient(private val project: Project) : com.tabbyml.intellijtabby.l
}

override fun gitDiff(params: GitDiffParams): CompletableFuture<GitDiffResult?> {
val result = gitProvider.diff(params.repository, params.cached)?.let {
val result = gitProvider?.diff(params.repository, params.cached)?.let {
GitDiffResult(diff = it)
}
return CompletableFuture<GitDiffResult?>().apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.tabbyml.intellijtabby.settings

import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import javax.swing.JComponent

class Configurable(private val project: Project) : Configurable {
private val settings = service<SettingsService>()
private var settingsPanel: SettingsPanel? = null
private val keymapSettings = project.service<KeymapSettings>()
private val keymapSettings = project.serviceOrNull<KeymapSettings>()

override fun getDisplayName(): String {
return "Tabby"
Expand All @@ -22,7 +23,12 @@ class Configurable(private val project: Project) : Configurable {

override fun isModified(): Boolean {
val panel = settingsPanel ?: return false
return panel.completionTriggerMode != settings.completionTriggerMode || panel.serverEndpoint != settings.serverEndpoint || panel.serverToken != settings.serverToken || panel.nodeBinary != settings.nodeBinary || panel.isAnonymousUsageTrackingDisabled != settings.isAnonymousUsageTrackingDisabled || (panel.keymapStyle != keymapSettings.getCurrentKeymapStyle() && panel.keymapStyle != KeymapSettings.KeymapStyle.CUSTOMIZE)
return panel.completionTriggerMode != settings.completionTriggerMode ||
panel.serverEndpoint != settings.serverEndpoint ||
panel.serverToken != settings.serverToken ||
panel.nodeBinary != settings.nodeBinary ||
panel.isAnonymousUsageTrackingDisabled != settings.isAnonymousUsageTrackingDisabled ||
(panel.keymapStyle != keymapSettings?.getCurrentKeymapStyle() && panel.keymapStyle != KeymapSettings.KeymapStyle.CUSTOMIZE)
}

override fun apply() {
Expand All @@ -34,7 +40,7 @@ class Configurable(private val project: Project) : Configurable {
settings.isAnonymousUsageTrackingDisabled = panel.isAnonymousUsageTrackingDisabled
settings.notifyChanges(project)

keymapSettings.applyKeymapStyle(panel.keymapStyle)
keymapSettings?.applyKeymapStyle(panel.keymapStyle)
}

override fun reset() {
Expand All @@ -44,7 +50,8 @@ class Configurable(private val project: Project) : Configurable {
panel.serverToken = settings.serverToken
panel.nodeBinary = settings.nodeBinary
panel.isAnonymousUsageTrackingDisabled = settings.isAnonymousUsageTrackingDisabled
panel.keymapStyle = keymapSettings.getCurrentKeymapStyle()

keymapSettings?.let { panel.keymapStyle = it.getCurrentKeymapStyle() }
}

override fun disposeUIResources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tabbyml.intellijtabby.settings
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.keymap.impl.ui.KeymapPanel
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.progress.ProgressIndicator
Expand All @@ -29,7 +30,7 @@ import javax.swing.JPanel

class SettingsPanel(private val project: Project) {
private val settings = service<SettingsService>()
private suspend fun getServer() = project.service<ConnectionService>().getServerAsync()
private suspend fun getServer() = project.serviceOrNull<ConnectionService>()?.getServerAsync()

private val serverEndpointTextField = JBTextField()
private val serverTokenPasswordField = JBPasswordField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.ListPopup
Expand Down Expand Up @@ -38,7 +38,7 @@ class StatusBarWidgetFactory : StatusBarEditorBasedWidgetFactory() {
var tooltip = "Tabby: Initializing"

init {
updateRendering(project.service<CombinedState>().state)
project.serviceOrNull<CombinedState>()?.state?.let { updateRendering(it) }
messageBusConnection.subscribe(CombinedState.Listener.TOPIC, object : CombinedState.Listener {
override fun stateChanged(state: CombinedState.State) {
updateRendering(state)
Expand Down

0 comments on commit 0e0a882

Please sign in to comment.