Skip to content

Commit

Permalink
changes to make IJ 2022.3 EAP work
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmckinney committed Nov 1, 2022
1 parent f5dfbe5 commit 094832d
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 53 deletions.
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.util.concurrent.TimeUnit

plugins {
id 'org.jetbrains.intellij' version '1.5.2'
id 'org.jetbrains.intellij' version '1.10.0-SNAPSHOT'
}

description = 'Manifold :: IJ'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand All @@ -43,9 +43,11 @@ allprojects {
if(!System.getenv('CI')) {
mavenLocal()
}
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
gradlePluginPortal()
}

// this test block fixes an IJ 2021.3 issue where it won't run tests
Expand Down Expand Up @@ -123,8 +125,8 @@ runIde {
}

patchPluginXml {
sinceBuild = '213.0'
untilBuild = '222.*'
sinceBuild = '223.0'
untilBuild = '223.*'
}

buildSearchableOptions {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
#

version=2022.1.21
manifoldVersion=2022.1.19-SNAPSHOT
version=2022.3.22
manifoldVersion=2022.1.22-SNAPSHOT
org.gradle.jvmargs=-Dfile.encoding=UTF-8
defaultIjVersion=LATEST-EAP-SNAPSHOT
9 changes: 9 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@
*
*/

pluginManagement {
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
gradlePluginPortal()
}
}

rootProject.name = 'manifold-ij'
include 'jps-plugin'
50 changes: 9 additions & 41 deletions src/main/java/manifold/ij/core/ManApplicationLoadListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
*/
public class ManApplicationLoadListener implements ApplicationLoadListener
{
private static volatile boolean Initialized = false;

// @Override in version 2022.x
public void beforeApplicationLoaded( @NotNull Application application, @NotNull Path configPath )
{
Expand Down Expand Up @@ -100,14 +98,15 @@ public void listenToProjectOpenClose()
connection.subscribe( ProjectManager.TOPIC,
new ProjectManagerListener()
{
@Override
public void projectOpened( @NotNull Project project )
{
initForAllProjects();

StartupManagerEx.getInstance( project ).registerStartupActivity( () ->
ApplicationManager.getApplication().runReadAction( () -> ManProject.manProjectFrom( project ).projectOpened() ) );
}
//jetbrains deprecated, see ManStartupActivity
// @Override
// public void projectOpened( @NotNull Project project )
// {
// initForAllProjects();
//
// StartupManagerEx.getInstance( project ).registerStartupActivity( () ->
// ApplicationManager.getApplication().runReadAction( () -> ManProject.manProjectFrom( project ).projectOpened() ) );
// }

@Override
public void projectClosed( @NotNull Project project )
Expand All @@ -121,37 +120,6 @@ public void projectClosed( @NotNull Project project )
} );
}

/**
* Note the timing of calling this method is critical. It must happen *after* the application has loaded, but before
* the first project loads. This used to happen during {@link com.intellij.openapi.components.ProjectComponent#initComponent},
* however JetBrains has deprecated components and there is no equivalent listener event (as far as I know).
*/
public void initForAllProjects()
{
if( !Initialized )
{
synchronized( this )
{
if( !Initialized )
{
Initialized = true;
registerAnnotatorWithAllLanguages();
}
}
}
}

private void registerAnnotatorWithAllLanguages()
{
// effectively adds annotator to ALL languages
LanguageAnnotators.INSTANCE.addExplicitExtension( Language.ANY, new ManifoldPsiClassAnnotator() );

// add brace matcher to templates
LanguageBraceMatching.INSTANCE.addExplicitExtension( ManTemplateLanguage.INSTANCE,
new PairedBraceMatcherAdapter( new ManTemplateBraceMatcher(), ManTemplateLanguage.INSTANCE ) );
}


/**
* Override Java String literals to handle fragments
* <p/>
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/manifold/ij/core/ManStartupActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
*
* * Copyright (c) 2022 - Manifold Systems LLC
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

package manifold.ij.core;

import com.intellij.codeInsight.highlighting.PairedBraceMatcherAdapter;
import com.intellij.lang.Language;
import com.intellij.lang.LanguageAnnotators;
import com.intellij.lang.LanguageBraceMatching;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import manifold.ij.extensions.ManifoldPsiClassAnnotator;
import manifold.ij.template.ManTemplateBraceMatcher;
import manifold.ij.template.ManTemplateLanguage;
import org.jetbrains.annotations.NotNull;

public class ManStartupActivity implements com.intellij.openapi.startup.StartupActivity
{
private static volatile boolean Initialized = false;

@Override
public void runActivity( @NotNull Project project )
{
initForAllProjects();

ApplicationManager.getApplication().runReadAction( () -> ManProject.manProjectFrom( project ).projectOpened() );
}

/**
* Note the timing of calling this method is critical. It must happen *after* the application has loaded, but before
* the first project loads. This used to happen during {@link com.intellij.openapi.components.ProjectComponent#initComponent},
* however JetBrains has deprecated components and there is no equivalent listener event (as far as I know).
*/
public void initForAllProjects()
{
if( !Initialized )
{
synchronized( this )
{
if( !Initialized )
{
Initialized = true;
registerAnnotatorWithAllLanguages();
}
}
}
}

private void registerAnnotatorWithAllLanguages()
{
// effectively adds annotator to ALL languages
LanguageAnnotators.INSTANCE.addExplicitExtension( Language.ANY, new ManifoldPsiClassAnnotator() );

// add brace matcher to templates
LanguageBraceMatching.INSTANCE.addExplicitExtension( ManTemplateLanguage.INSTANCE,
new PairedBraceMatcherAdapter( new ManTemplateBraceMatcher(), ManTemplateLanguage.INSTANCE ) );
}

}
14 changes: 13 additions & 1 deletion src/main/java/manifold/ij/extensions/ManResolveCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StubTextInconsistencyException;
import com.intellij.psi.util.*;

import java.util.*;
Expand Down Expand Up @@ -103,7 +104,18 @@ public <T extends PsiPolyVariantReference> ResolveResult[] resolveWithCaching( @
return results;
}

results = super.resolveWithCaching( ref, resolver, needToPreventRecursion, incompleteCode, containingFile );
try
{
results = super.resolveWithCaching( ref, resolver, needToPreventRecursion, incompleteCode, containingFile );
}
catch( StubTextInconsistencyException stie )
{
//todo: on the surface these don't appear to have any impact. _shrug_
// In any case tracking this down is a lost cause due to ProcessCanceledException, it's brutal. Maybe find a way to raise the timeout?
// For now avoiding the exception as it unnecessarily alarms users.
return ResolveResult.EMPTY_ARRAY;
}

for( ResolveResult result: results )
{
if( result instanceof CandidateInfo )
Expand Down
13 changes: 11 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,16 @@ a discussion, ask questions, provide feedback, etc. Someone is usually there to

<change-notes>
<![CDATA[
<h3>Fixes & Features:</h3>
<h3>Change notes:</h3>
<h4>
The Manifold IntelliJ plugin is FREE now :)<br>
<br>
<a href="https://github.com/manifold-systems/manifold/issues/393">#393</a>: Java 17+: fix $ escape char for string templates
<br>
<a href="https://github.com/manifold-systems/manifold/issues/392">#392</a>: Cast as raw generic type
<br>
<a href="https://github.com/manifold-systems/manifold/issues/387">#387</a>: Tree is null for module-info file, do not process
<br>
<a href="https://github.com/manifold-systems/manifold/issues/380">#380</a>: Fix regression involving fields as structurally equivalent to get/set methods
<br>
<a href="https://github.com/manifold-systems/manifold/issues/382">#382</a>: Fix instanceof pattern matching issue related to parser changes in latest IntelliJ release
<br>
Expand Down Expand Up @@ -480,6 +487,8 @@ Other minor fixes and improvements.
<projectService serviceInterface="com.intellij.psi.impl.source.resolve.JavaResolveCache"
serviceImplementation="manifold.ij.extensions.ManJavaResolveCache" overrides="true"/>

<postStartupActivity implementation="manifold.ij.core.ManStartupActivity"/>

<!-- These application service overrides facilitate file fragments -->
<applicationService serviceInterface="com.intellij.lang.DefaultASTFactory"
serviceImplementation="manifold.ij.extensions.ManDefaultASTFactoryImpl" overrides="true"/>
Expand Down

0 comments on commit 094832d

Please sign in to comment.