|
69 | 69 | import org.scijava.code.api.Signatures; |
70 | 70 | import org.scijava.code.lsp.LspClient; |
71 | 71 | import org.scijava.code.lsp.LspServers; |
72 | | -import org.scijava.log.LogService; |
73 | | -import org.scijava.log.StderrLogService; |
| 72 | +import org.scijava.code.lsp.LspService; |
| 73 | +import org.scijava.code.lsp.PythonLspClient; |
74 | 74 | import org.scijava.plugin.Plugin; |
75 | 75 | import org.scijava.plugins.scripting.appose.python._internal.InlineMetadata; |
76 | 76 | import org.scijava.plugins.scripting.appose.python._internal.ResidentWorker; |
77 | 77 | import org.scijava.plugins.scripting.appose.python._internal.ResidentWorkerService; |
78 | 78 | import org.scijava.plugins.scripting.appose.python.completion.ApposePythonDialect; |
79 | 79 | import org.scijava.plugins.scripting.appose.python.completion.DependencyOverlays; |
80 | 80 | import org.scijava.plugins.scripting.appose.python.completion.JediLanguageServerSpec; |
81 | | -import org.scijava.plugins.scripting.appose.python.completion.PythonLspClient; |
82 | 81 | import org.scijava.plugins.scripting.appose.python.completion.PythonSyntax; |
83 | 82 | import org.scijava.plugins.scripting.appose.python.completion.PythonSyntax.Kind; |
84 | 83 | import org.scijava.script.ScriptLanguage; |
@@ -124,14 +123,6 @@ public class ApposePythonCodeCompleter extends AbstractCodeCompleterPlugin { |
124 | 123 | /** How many completions get signatures, once a word is begun. */ |
125 | 124 | private static final int SIGNATURES = 30; |
126 | 125 |
|
127 | | - /** How long a language server may go unused before it stops, in ms. */ |
128 | | - private static final long SERVER_IDLE = 10 * 60 * 1000; |
129 | | - |
130 | | - /** |
131 | | - * How many language servers may run at once (one per script environment |
132 | | - * and overlay). |
133 | | - */ |
134 | | - private static final int MAX_SERVERS = 3; |
135 | 126 |
|
136 | 127 | /** Python executables of script environments, by script and metadata. */ |
137 | 128 | private final Map<String, String> pythons = new LinkedHashMap<String, String>( |
@@ -609,27 +600,36 @@ private static String findPython(final List<File> dirs) { |
609 | 600 | return null; |
610 | 601 | } |
611 | 602 |
|
612 | | - /** Gets the language server client, creating it on first use. */ |
| 603 | + /** |
| 604 | + * Gets the language server client, creating it on first use; for the |
| 605 | + * Python servers of the context (see {@link ApposePythonLspServerPlugin}). |
| 606 | + */ |
613 | 607 | private synchronized LspClient lspClient() { |
614 | 608 | if (lsp != null) return lsp; |
615 | | - final ResidentWorkerService workers = service( |
616 | | - ResidentWorkerService.class); |
617 | | - if (workers == null) return null; |
618 | | - LogService log = service(LogService.class); |
619 | | - if (log == null) log = new StderrLogService(); |
| 609 | + final LspService service = service(LspService.class); |
| 610 | + final LspServers servers = service == null ? null : service.servers( |
| 611 | + "python"); |
| 612 | + if (servers == null) return null; |
| 613 | + lsp = new PythonLspClient(servers); |
| 614 | + return lsp; |
| 615 | + } |
| 616 | + |
| 617 | + /** |
| 618 | + * How to start jedi-language-server: with the Python of the tooling |
| 619 | + * environment, built first if needed (but starting no worker). |
| 620 | + */ |
| 621 | + static JediLanguageServerSpec serverSpec( |
| 622 | + final ResidentWorkerService workers) |
| 623 | + { |
620 | 624 | final File envs = new File(Environments.apposeEnvsDir()); |
621 | | - final JediLanguageServerSpec spec = new JediLanguageServerSpec(() -> { |
622 | | - // NB: Builds the tooling environment, if needed (but starts no worker). |
| 625 | + return new JediLanguageServerSpec(() -> { |
623 | 626 | final String python = pythonExecutable(toolingWorker(workers) |
624 | 627 | .environment().get()); |
625 | 628 | if (python == null) throw new IOException("No Python in " + |
626 | 629 | TOOLING_ENV); |
627 | 630 | return python; |
628 | 631 | }, new File(envs, TOOLING_ENV + "-workspace"), new File(envs, TOOLING_ENV + |
629 | 632 | "-server.log")); |
630 | | - lsp = new PythonLspClient(new LspServers(spec, log, SERVER_IDLE, |
631 | | - MAX_SERVERS)); |
632 | | - return lsp; |
633 | 633 | } |
634 | 634 |
|
635 | 635 | /** Gets the tooling environment's worker, building it first if needed. */ |
|
0 commit comments