diff --git a/pom.xml b/pom.xml
index eece9e5..8b9ae98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -314,6 +314,7 @@
true
+ ${project.build.directory}/test-userdir
diff --git a/src/main/java/org/netbeans/modules/python/PythonLspClient.java b/src/main/java/org/netbeans/modules/python/PythonLspClient.java
index cd87ffc..c2177da 100644
--- a/src/main/java/org/netbeans/modules/python/PythonLspClient.java
+++ b/src/main/java/org/netbeans/modules/python/PythonLspClient.java
@@ -5,6 +5,7 @@
*/
import java.io.IOException;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.project.Project;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
@@ -28,9 +29,16 @@ public LanguageServerDescription startServer(Lookup lkp) {
)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
- return LanguageServerDescription.create(p.getInputStream(),
+ LanguageServerDescription description = LanguageServerDescription.create(p.getInputStream(),
p.getOutputStream(), p
);
+ try {
+ PythonLspConfiguration.serverStarted(lkp.lookup(Project.class), description);
+ } catch (RuntimeException | LinkageError ex) {
+ // The server still works, only without the project's interpreter.
+ Exceptions.printStackTrace(ex);
+ }
+ return description;
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return null;
diff --git a/src/main/java/org/netbeans/modules/python/PythonLspConfiguration.java b/src/main/java/org/netbeans/modules/python/PythonLspConfiguration.java
new file mode 100644
index 0000000..99327ec
--- /dev/null
+++ b/src/main/java/org/netbeans/modules/python/PythonLspConfiguration.java
@@ -0,0 +1,266 @@
+package org.netbeans.modules.python;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.ToNumberPolicy;
+import com.google.gson.reflect.TypeToken;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.event.ChangeListener;
+import org.eclipse.lsp4j.DidChangeConfigurationParams;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.lsp.client.LSPBindings;
+import org.netbeans.modules.lsp.client.LanguageServerProviderAccessor;
+import org.netbeans.modules.lsp.client.spi.LanguageServerProvider.LanguageServerDescription;
+import org.netbeans.modules.python.project.PythonProject;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.RequestProcessor;
+
+/**
+ * Sends pylsp its settings together with the interpreter of the project it
+ * serves, so that Jedi completes the packages installed in that interpreter
+ * instead of those of the plugin's own pylsp environment (#144).
+ */
+public final class PythonLspConfiguration {
+
+ private static final Logger LOG = Logger.getLogger(PythonLspConfiguration.class.getName());
+ private static final RequestProcessor WORKER = new RequestProcessor(PythonLspConfiguration.class.getName(), 1);
+ /** Running Python servers and the project each was started for (null for files outside projects). */
+ private static final Map SERVERS = new WeakHashMap<>();
+ /** Started servers that NetBeans has not initialized yet. */
+ private static final Map PENDING = new ConcurrentHashMap<>();
+ private static final Gson GSON = new GsonBuilder()
+ .setObjectToNumberStrategy(ToNumberPolicy.BIG_DECIMAL).create();
+ private static final Type SETTINGS_TYPE = new TypeToken