Skip to content

Commit 838d5c4

Browse files
committed
Update projectType in some files, leverage PythonOptions for python location.
1 parent f2de33d commit 838d5c4

5 files changed

Lines changed: 28 additions & 12 deletions

File tree

src/main/java/org/apache/netbeans/modules/python4nb/editor/lsp/PythonLsp.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@
2828
//import org.apache.netbeans.api.project.Project;
2929
//import org.netbeans.modules.cpplite.editor.Utils;
3030
import org.apache.netbeans.modules.python4nb.editor.file.MIMETypes;
31+
import org.apache.netbeans.modules.python4nb.editor.options.PythonOptions;
32+
import static org.apache.netbeans.modules.python4nb.exec.PythonExecutable.getDefault;
33+
import org.apache.netbeans.modules.python4nb.platform.PythonSupport;
34+
import org.apache.netbeans.modules.python4nb.preferences.PythonPreferences;
3135
import org.openide.util.Exceptions;
3236
import org.openide.util.Pair;
3337
import org.netbeans.api.project.Project;
3438
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider;
3539
import org.openide.util.Lookup;
40+
import org.openide.util.NbPreferences;
3641

3742
/**
3843
*
@@ -62,17 +67,23 @@ public LanguageServerDescription startServer(Lookup lookup) {
6267
}
6368

6469
try {
65-
/* TODO: Retrieve location of python based on global configuration
66-
or per project configuration.
67-
*/
68-
// final String python = "C:\\Apps\\python\\Python39\\python.exe";
69-
final String python = "C:\\Python310\\python.exe";
70+
// get python location
71+
PythonOptions options = PythonOptions.getInstance();
72+
final String python = options.getPython();
73+
// TODO: get python support from project
74+
// PythonSupport support = PythonSupport.forProject(prj);
75+
// support = PythonSupport.forProject(prj);
76+
// PythonPreferences pyPreferences = support.getPreferences();
77+
7078
LOG.log(Level.INFO, "Starting up Python LSP Server using {0}", python);
7179

7280
// TODO: Check if Python LSP available to be run
7381
Process pythonServer = new ProcessBuilder(python,
7482
"-m", "pyls").start();
75-
LOG.log(Level.INFO, "Started up Python LSP Server");
83+
84+
// TODO: If unable to start pyls support need to error out and/or notify user for setup
85+
86+
LOG.log(Level.INFO, "Started up Python LSP Server" );
7687

7788
LOG.log(Level.INFO, "Python LSP establish input-output for server.");
7889
return LanguageServerDescription.create(pythonServer.getInputStream(),

src/main/java/org/apache/netbeans/modules/python4nb/editor/options/PythonOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public final class PythonOptions {
3838

3939
// Do not change arbitrary - consult with layer's folder OptionsExport
4040
// Path to Preferences node for storing these preferences
41-
private static final String PREFERENCES_PATH = "python"; // NOI18N
41+
public static final String PREFERENCES_PATH = "python.preferences"; // NOI18N
4242

4343
private static final PythonOptions INSTANCE = new PythonOptions();
4444

4545
private final Preferences preferences;
4646

4747
private volatile boolean nodeSearched = false;
4848
private volatile boolean pipSearched = false;
49-
private volatile boolean expressSearched = false;
49+
// private volatile boolean expressSearched = false;
5050

5151

5252
private PythonOptions() {

src/main/java/org/apache/netbeans/modules/python4nb/platform/PythonSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.openide.filesystems.FileChangeListener;
5454
import org.openide.filesystems.FileEvent;
5555
import org.openide.filesystems.FileUtil;
56+
import org.openide.util.Lookup;
5657
import org.openide.util.NbBundle;
5758
import org.openide.util.Pair;
5859
import org.openide.util.RequestProcessor;
@@ -85,7 +86,7 @@ private PythonSupport(Project project) {
8586
pythonPackage = new PythonPackage(project.getProjectDirectory());
8687
}
8788

88-
@ProjectServiceProvider(service = PythonSupport.class, projectType = "org-netbeans-modules-web-clientproject") // NOI18N
89+
@ProjectServiceProvider(service = PythonSupport.class, projectType = "org-netbeans-modules-python4nb-project") // NOI18N
8990
public static PythonSupport create(Project project) {
9091
PythonSupport support = new PythonSupport(project);
9192
// listeners
@@ -95,7 +96,10 @@ public static PythonSupport create(Project project) {
9596
}
9697

9798
public static PythonSupport forProject(Project project) {
98-
PythonSupport support = project.getLookup().lookup(PythonSupport.class);
99+
// TODO: FIgure out why lookup not working right
100+
Lookup lookup = project.getLookup();
101+
PythonSupport support = lookup.lookup(PythonSupport.class);
102+
// PythonSupport support = project.getLookup().lookup(PythonSupport.class);
99103
if (support == null) {
100104
throw new IllegalArgumentException("Python Support not available or configured.");
101105
}

src/main/java/org/apache/netbeans/modules/python4nb/project/node/PythonNodeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939

40-
@NodeFactory.Registration(projectType = "python-project", position = 10)
40+
@NodeFactory.Registration(projectType = "org-netbeans-modules-python4nb-project", position = 10)
4141
public class PythonNodeFactory implements NodeFactory {
4242

4343
@Override

src/main/java/org/apache/netbeans/modules/python4nb/ui/PythonCustomizerProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public JComponent createComponent(ProjectCustomizer.Category category, Lookup co
4949
}
5050

5151
@ProjectCustomizer.CompositeCategoryProvider.Registration(
52-
projectType = "org.netbeans.modules.web.clientproject", // NOI18N
52+
projectType = "org-netbeans-modules-python4nb-project", // NOI18N
53+
5354
position = 320)
5455
public static PythonCustomizerProvider createCustomizer() {
5556
return new PythonCustomizerProvider();

0 commit comments

Comments
 (0)