donkirkby / live-py-plugin

Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
https://donkirkby.github.io/live-py-plugin
MIT License
292 stars 57 forks source link

PyCharm 2024.2 incompatibility #627

Open donkirkby opened 5 months ago

donkirkby commented 5 months ago

JetBrains compatibility scans started complaining about version 2024.2:

IntelliJ IDEA Ultimate 2024.2 eap (242.12881.66)4 compatibility problems. 1 usage of deprecated API. 6 usages of experimental API (Restart)
4 compatibility problems
Live Coding in Python 4.11.4 is binary incompatible with IntelliJ IDEA Ultimate IU-242.12881.66 due to the following problems
Class not found (4 problems)
Access to unresolved class PythonCommandLineState (3 problems)
Method LiveCodingAnalyst.start(Project, DataContext) references an unresolved class PythonCommandLineState. This can lead to NoSuchClassError exception at runtime.
Field LiveCodingAnalyst.commandLineState references an unresolved class PythonCommandLineState. This can lead to NoSuchClassError exception at runtime.
Method LiveCodingAnalyst.lambda$startProcess$8() references an unresolved class PythonCommandLineState. This can lead to NoSuchClassError exception at runtime.
Access to unresolved class PythonRunConfiguration (1 problem)
Method LiveCodingAnalyst.start(Project, DataContext) references an unresolved class PythonRunConfiguration. This can lead to NoSuchClassError exception at runtime.

Looks like the classes PythonCommandLineState and PythonRunConfiguration have been replaced, so figure out what to use instead.

donkirkby commented 5 months ago

Trying to reproduce the problem locally can't find the latest version of IDEA. I posted a question on the IntelliJ support forum.

donkirkby commented 3 months ago

Looks like I need to upgrade the IntelliJ platform gradle plugin to v2.0 to support newer versions of IDEA. That page also contains a migration guide.

A good source of help is the JetBrains slack, particularly the #intellij-platform-gradle-plugin channel.

So far, I upgraded Gradle to v8.9, and started following the migration guide.

donkirkby commented 1 month ago

After the gradle and Plugin DevKit upgrades, I can reproduce the problem with these settings:

dependencies {
    intellijPlatform {
        intellijIdeaCommunity("2024.2.2")

        plugin("PythonCore:243.15521.24")

        pluginVerifier()
    }
}

I can successfully run the old version with these settings:

dependencies {
    intellijPlatform {
        intellijIdeaCommunity("2023.2.7")

        plugin("PythonCore:232.10300.40")

        pluginVerifier()
        instrumentationTools()
    }
}

I did need to remove a couple of nulls to make that work, though.

donkirkby commented 1 month ago

I tried stepping through the source code of the old version and copying it into my plugin, but I couldn't import TextEditorImplKt.createAsyncEditorLoader. For the record, here's what I tried:

        return TasksKt.runWithModalProgressBlocking(
                project,
                "Opening " + file.getName(),
                ((coroutineScope, continuation) -> (
                        createEditorBuilder(project, file, asyncProvider, coroutineScope))));
    }

    private static Builder createEditorBuilder(
            Project project,
            VirtualFile file,
            AsyncFileEditorProvider asyncProvider,
            CoroutineScope coroutineScope) {
        if ( ! (asyncProvider instanceof TextEditorProvider)) {
            throw new IllegalArgumentException("Async editor provider is not a TextEditorProvider.");
        }
        var textEditorProvider = (TextEditorProvider) asyncProvider;
        var asyncLoader = createAsyncEditorLoader(textEditorProvider, project, file, coroutineScope);

        var fileDocumentManager = FileDocumentManager.getInstance();
        var document = fileDocumentManager.getCachedDocument(file);
        if (document == null) {
            document = ApplicationManager.getApplication().runReadAction(
                    (Computable<? extends Document>) () -> fileDocumentManager.getDocument(file, project));
        }

        var factory = (EditorFactoryImpl)(EditorFactory.getInstance());
        var highlighter = asyncLoader.createHighlighterAsync(document, file);
        return new AsyncFileEditorProvider.Builder() {
            public @NotNull FileEditor build() {
                var editor = factory.createMainEditor(document, project, file);
                var textEditor = new PsiAwareTextEditorImpl(project, file, editor, asyncLoader);
                asyncLoader.start(textEditor, highlighter);
                return textEditor;
            }
        };
    }

The next thing to try is to step through the diff tool in the new version.

donkirkby commented 2 weeks ago

Looks like some good example code in the Markdown Navigator plugin.

donkirkby commented 2 weeks ago

Markdown Navigator has the same incompatibility issues that I do. :-(

donkirkby commented 1 week ago

The Markdown plugin seems out of date, so maybe the AsciiDoc plugin is a better choice.