4444import org .eclipse .lsp4j .CompletionItemKind ;
4545import org .eclipse .lsp4j .CompletionList ;
4646import org .eclipse .lsp4j .CompletionParams ;
47+ import org .eclipse .lsp4j .DidChangeConfigurationParams ;
4748import org .eclipse .lsp4j .DidChangeTextDocumentParams ;
49+ import org .eclipse .lsp4j .DidChangeWatchedFilesParams ;
4850import org .eclipse .lsp4j .DidCloseTextDocumentParams ;
4951import org .eclipse .lsp4j .DidOpenTextDocumentParams ;
52+ import org .eclipse .lsp4j .DidSaveTextDocumentParams ;
53+ import org .eclipse .lsp4j .Hover ;
54+ import org .eclipse .lsp4j .HoverParams ;
55+ import org .eclipse .lsp4j .InitializeParams ;
56+ import org .eclipse .lsp4j .InitializeResult ;
57+ import org .eclipse .lsp4j .InitializedParams ;
58+ import org .eclipse .lsp4j .SignatureHelp ;
59+ import org .eclipse .lsp4j .SignatureHelpParams ;
5060import org .eclipse .lsp4j .jsonrpc .messages .Either ;
61+ import org .eclipse .lsp4j .services .LanguageClient ;
62+ import org .eclipse .lsp4j .services .LanguageClientAware ;
5163import org .eclipse .lsp4j .services .LanguageServer ;
64+ import org .eclipse .lsp4j .services .TextDocumentService ;
65+ import org .eclipse .lsp4j .services .WorkspaceService ;
5266import org .scijava .code .lsp .jvm .Callable ;
5367import org .scijava .code .lsp .Positions ;
5468
6579 * {@link Callable}s: snippets with their parameters and types. (Not in
6680 * imports: an import names things, rather than calling them.)</li>
6781 * </ul>
82+ * <p>
83+ * Everything else is passed on to the server as is.
84+ * </p>
6885 *
6986 * @author Gabriel Selzer
7087 */
71- public class PythonCompletionServer extends DelegatingLanguageServer {
88+ public class PythonCompletionServer implements LanguageServer ,
89+ TextDocumentService , WorkspaceService , LanguageClientAware
90+ {
7291
7392 /** How long an answer may be reused, in milliseconds. */
7493 private static final long ANSWER_LIFETIME = 20_000 ;
@@ -77,6 +96,9 @@ public class PythonCompletionServer extends DelegatingLanguageServer {
7796 private static final Pattern IMPORT = Pattern .compile (
7897 "^\\ s*(from|import)\\ s" );
7998
99+ /** The Python language server. */
100+ private final LanguageServer inner ;
101+
80102 private final int signatures ;
81103 private final LongSupplier clock ;
82104
@@ -111,16 +133,61 @@ public PythonCompletionServer(final LanguageServer inner,
111133 PythonCompletionServer (final LanguageServer inner , final int signatures ,
112134 final LongSupplier clock )
113135 {
114- super ( inner ) ;
136+ this . inner = inner ;
115137 this .signatures = signatures ;
116138 this .clock = clock ;
117139 }
118140
141+ // -- LanguageClientAware --
142+
143+ @ Override
144+ public void connect (final LanguageClient client ) {
145+ if (inner instanceof LanguageClientAware ) {
146+ ((LanguageClientAware ) inner ).connect (client );
147+ }
148+ }
149+
150+ // -- LanguageServer --
151+
152+ @ Override
153+ public CompletableFuture <InitializeResult > initialize (
154+ final InitializeParams params )
155+ {
156+ return inner .initialize (params );
157+ }
158+
159+ @ Override
160+ public void initialized (final InitializedParams params ) {
161+ inner .initialized (params );
162+ }
163+
164+ @ Override
165+ public CompletableFuture <Object > shutdown () {
166+ return inner .shutdown ();
167+ }
168+
169+ @ Override
170+ public void exit () {
171+ inner .exit ();
172+ }
173+
174+ @ Override
175+ public TextDocumentService getTextDocumentService () {
176+ return this ;
177+ }
178+
179+ @ Override
180+ public WorkspaceService getWorkspaceService () {
181+ return this ;
182+ }
183+
184+ // -- TextDocumentService --
185+
119186 @ Override
120187 public void didOpen (final DidOpenTextDocumentParams params ) {
121188 texts .put (params .getTextDocument ().getUri (), params .getTextDocument ()
122189 .getText ());
123- super .didOpen (params );
190+ inner . getTextDocumentService () .didOpen (params );
124191 }
125192
126193 @ Override
@@ -129,14 +196,14 @@ public void didChange(final DidChangeTextDocumentParams params) {
129196 texts .put (params .getTextDocument ().getUri (), params .getContentChanges ()
130197 .get (params .getContentChanges ().size () - 1 ).getText ());
131198 }
132- super .didChange (params );
199+ inner . getTextDocumentService () .didChange (params );
133200 }
134201
135202 @ Override
136203 public void didClose (final DidCloseTextDocumentParams params ) {
137204 texts .remove (params .getTextDocument ().getUri ());
138205 pending .remove (params .getTextDocument ().getUri ());
139- super .didClose (params );
206+ inner . getTextDocumentService () .didClose (params );
140207 }
141208
142209 @ Override
@@ -145,7 +212,8 @@ public void didClose(final DidCloseTextDocumentParams params) {
145212 {
146213 final String uri = params .getTextDocument ().getUri ();
147214 final String text = texts .get (uri );
148- if (text == null ) return super .completion (params );
215+ if (text == null ) return inner .getTextDocumentService ().completion (
216+ params );
149217 final int caret = Math .min (Positions .offset (text , params .getPosition ()),
150218 text .length ());
151219 int start = caret ;
@@ -173,7 +241,7 @@ public void didClose(final DidCloseTextDocumentParams params) {
173241 final CompletionParams p = new CompletionParams (params .getTextDocument (),
174242 Positions .position (text , ask ), params .getContext ());
175243 final CompletableFuture <Either <List <CompletionItem >, CompletionList >> raw =
176- super .completion (p );
244+ inner . getTextDocumentService () .completion (p );
177245 final int n = word .isEmpty () || importing ? 0 : signatures ;
178246 answer = new Answer (raw , raw .thenCompose (list -> resolve (list , n )), now );
179247 synchronized (answers ) {
@@ -192,6 +260,44 @@ public void didClose(final DidCloseTextDocumentParams params) {
192260 word )));
193261 }
194262
263+ @ Override
264+ public void didSave (final DidSaveTextDocumentParams params ) {
265+ inner .getTextDocumentService ().didSave (params );
266+ }
267+
268+ @ Override
269+ public CompletableFuture <CompletionItem > resolveCompletionItem (
270+ final CompletionItem item )
271+ {
272+ return inner .getTextDocumentService ().resolveCompletionItem (item );
273+ }
274+
275+ @ Override
276+ public CompletableFuture <SignatureHelp > signatureHelp (
277+ final SignatureHelpParams params )
278+ {
279+ return inner .getTextDocumentService ().signatureHelp (params );
280+ }
281+
282+ @ Override
283+ public CompletableFuture <Hover > hover (final HoverParams params ) {
284+ return inner .getTextDocumentService ().hover (params );
285+ }
286+
287+ // -- WorkspaceService --
288+
289+ @ Override
290+ public void didChangeConfiguration (final DidChangeConfigurationParams p ) {
291+ inner .getWorkspaceService ().didChangeConfiguration (p );
292+ }
293+
294+ @ Override
295+ public void didChangeWatchedFiles (final DidChangeWatchedFilesParams p ) {
296+ inner .getWorkspaceService ().didChangeWatchedFiles (p );
297+ }
298+
299+ // -- Helper methods --
300+
195301 /** Resolves the first completions, making those with signatures callables. */
196302 private CompletableFuture <CompletionList > resolve (
197303 final Either <List <CompletionItem >, CompletionList > answer , final int n )
0 commit comments