Added extension point to allow extend functionality of Python PreferredSdkComparator
authorKiryl Chetyrbak <kirylchetyrbak@gmail.com>
Wed, 29 Mar 2017 19:42:07 +0000 (15:42 -0400)
committerKiryl Chetyrbak <kirylchetyrbak@gmail.com>
Wed, 29 Mar 2017 19:42:07 +0000 (15:42 -0400)
python/src/META-INF/python-core-common.xml
python/src/com/jetbrains/python/sdk/PreferredSdkComparator.java
python/src/com/jetbrains/python/sdk/PySdkWeightProvider.java [new file with mode: 0644]

index 7af2fee357a49d4f4f0e4b2f0aed775c38bc4b79..677150ca366068663689dc0fb57f5d2cc89ab131 100644 (file)
     <extensionPoint qualifiedName="Pythonid.pythonFlavorProvider" interface="com.jetbrains.python.sdk.flavors.PythonFlavorProvider"/>
     <extensionPoint qualifiedName="Pythonid.debugSessionFactory" interface="com.jetbrains.python.debugger.PyDebugSessionFactory"/>
     <extensionPoint qualifiedName="Pythonid.customPackageIdentifier" interface="com.jetbrains.python.psi.PyCustomPackageIdentifier"/>
+    <extensionPoint qualifiedName="Pythonid.pythonSdkWeightProvider" interface="com.jetbrains.python.sdk.PySdkWeightProvider" />
   </extensionPoints>
 
   <extensions defaultExtensionNs="Pythonid">
index 4466b2f3d4b4b918293aabe938d735fd4d898421..85a68932962b3eddc491501d48903ba78d9374cc 100644 (file)
  */
 package com.jetbrains.python.sdk;
 
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.util.Comparing;
 import com.jetbrains.python.sdk.flavors.CPythonSdkFlavor;
+import com.jetbrains.python.sdk.flavors.PythonFlavorProvider;
 import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
 
 import java.util.Comparator;
@@ -54,6 +56,14 @@ public class PreferredSdkComparator implements Comparator<Sdk> {
       return flavor2weight - flavor1weight;
     }
 
+    for (PySdkWeightProvider provider : Extensions.getExtensions(PySdkWeightProvider.EP_NAME)) {
+      int weight1 = provider.getWeight(o1);
+      int weight2 = provider.getWeight(o2);
+      if(weight1 != weight2) {
+        return weight2 - weight1;
+      }
+    }
+
     return -Comparing.compare(o1.getVersionString(), o2.getVersionString());
   }
-}
+}
\ No newline at end of file
diff --git a/python/src/com/jetbrains/python/sdk/PySdkWeightProvider.java b/python/src/com/jetbrains/python/sdk/PySdkWeightProvider.java
new file mode 100644 (file)
index 0000000..b319aa7
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2017 JetBrains s.r.o.
+ *
+ * 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 com.jetbrains.python.sdk;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.projectRoots.Sdk;
+
+/**
+ * Created by kirylch on 3/29/2017.
+ */
+public interface PySdkWeightProvider {
+  ExtensionPointName<PySdkWeightProvider> EP_NAME = ExtensionPointName.create("Pythonid.pythonSdkWeightProvider");
+
+  int getWeight(Sdk sdk);
+}