11/*
2- * Copyright (c) 2025, Oracle and/or its affiliates.
2+ * Copyright (c) 2025-2026 , Oracle and/or its affiliates.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3131import org .eclipse .lsp4j .DidSaveNotebookDocumentParams ;
3232import org .eclipse .lsp4j .MessageParams ;
3333import org .eclipse .lsp4j .MessageType ;
34+ import org .eclipse .lsp4j .NotebookDocumentSyncRegistrationOptions ;
35+ import org .eclipse .lsp4j .NotebookSelector ;
36+ import org .eclipse .lsp4j .NotebookSelectorCell ;
37+ import org .eclipse .lsp4j .ServerCapabilities ;
3438import org .eclipse .lsp4j .jsonrpc .messages .Either ;
3539import org .eclipse .lsp4j .services .LanguageClient ;
3640import org .netbeans .modules .java .lsp .server .notebook .NotebookDocumentServiceHandler ;
@@ -56,7 +60,7 @@ public class NotebookDocumentServiceHandlerImpl implements NotebookDocumentServi
5660 private final Map <String , NotebookDocumentStateManager > notebookStateMap = new ConcurrentHashMap <>();
5761 // Below map is required because completion request doesn't send notebook uri in the params
5862 private final Map <String , String > notebookCellMap = new ConcurrentHashMap <>();
59-
63+
6064 @ Override
6165 public void didOpen (DidOpenNotebookDocumentParams params ) {
6266 try {
@@ -128,4 +132,24 @@ public void connect(LanguageClient client) {
128132 NotebookConfigs .getInstance ().initConfigs ();
129133
130134 }
135+ @ Override // connect must be called before init
136+ public void init (ServerCapabilities serverCapabilities ){
137+ if (clientWantsNotebook ()) {
138+ NotebookDocumentSyncRegistrationOptions opts = createNotebookRegOpts ();
139+ serverCapabilities .setNotebookDocumentSync (opts );
140+ }
141+ }
142+ private boolean clientWantsNotebook () {
143+ NbCodeLanguageClient client = LanguageClientInstance .getInstance ().getClient ();
144+ return client != null && client .getNbCodeCapabilities ().wantsNotebookSupport ();
145+ }
146+ private NotebookDocumentSyncRegistrationOptions createNotebookRegOpts () {
147+ NotebookDocumentSyncRegistrationOptions opts = new NotebookDocumentSyncRegistrationOptions ();
148+ NotebookSelector ns = new NotebookSelector ();
149+ ns .setNotebook ("*" );
150+ ns .setCells (List .of (new NotebookSelectorCell ("java" ), new NotebookSelectorCell ("markdown" )));
151+ opts .setNotebookSelector (List .of (ns ));
152+ return opts ;
153+ }
154+
131155}
0 commit comments