Skip to content

Commit

Permalink
fix(inlay): fix compatibility issue with IDEA 241 version for #109
Browse files Browse the repository at this point in the history
Handle LLMEditorSaveVetoer to properly interact with document save veto. Update handling of document save veto in LLMEditorSaveVetoer to address extension point and ensure proper application of the save veto.
  • Loading branch information
phodal committed Mar 21, 2024
1 parent a5d5e4d commit 2ff3c17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Expand Up @@ -2,10 +2,9 @@ package com.intellij.temporary.inlay.codecomplete

import com.intellij.openapi.editor.Document
import com.intellij.openapi.fileEditor.FileDocumentSynchronizationVetoer
import com.intellij.openapi.util.UserDataHolder

class LLMEditorSaveVetoer : FileDocumentSynchronizationVetoer() {
override fun maySaveDocument(document: Document, isSaveExplicit: Boolean): Boolean {
return !LLMInlayManagerImpl.KEY_DOCUMENT_SAVE_VETO.isIn(document as UserDataHolder)
return !LLMInlayManagerImpl.KEY_DOCUMENT_SAVE_VETO.isIn(document)
}
}
Expand Up @@ -26,6 +26,7 @@ interface LLMInlayManager : Disposable {
fun editorModified(editor: Editor, changeOffset: Int)

fun editorModified(editor: Editor)

fun countCompletionInlays(editor: Editor, tabRange: TextRange) : Int

companion object {
Expand Down
Expand Up @@ -14,6 +14,7 @@ import com.intellij.openapi.editor.EditorCustomElementRenderer
import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.impl.ImaginaryEditor
import com.intellij.openapi.extensions.ExtensionPoint
import com.intellij.openapi.fileEditor.FileDocumentSynchronizationVetoer
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
Expand All @@ -38,7 +39,7 @@ class LLMInlayManagerImpl : LLMInlayManager {

@RequiresEdt
override fun isAvailable(editor: Editor): Boolean {
var isAvailable= KEY_EDITOR_SUPPORTED[editor]
var isAvailable = KEY_EDITOR_SUPPORTED[editor]
if (isAvailable == null) {
isAvailable = editor !is EditorWindow && editor !is ImaginaryEditor && (
editor !is EditorEx || !editor.isEmbeddedIntoDialogWrapper) &&
Expand Down Expand Up @@ -79,11 +80,12 @@ class LLMInlayManagerImpl : LLMInlayManager {
return true
}

@Suppress("UnstableApiUsage")
private fun wrapWithTemporarySaveVetoHandler(runnable: Runnable) {
val disposable = Disposer.newDisposable()
try {
val extensionArea = ApplicationManager.getApplication().extensionArea
val ep = extensionArea.getExtensionPoint(FileDocumentSynchronizationVetoer.EP_NAME)
val ep = ApplicationManager.getApplication().getExtensionArea()
.getExtensionPoint(FileDocumentSynchronizationVetoer.EP_NAME)
ep.registerExtension(LLMEditorSaveVetoer(), disposable)
runnable.run()
} finally {
Expand Down

0 comments on commit 2ff3c17

Please sign in to comment.