Skip to content

Commit c822095

Browse files
committed
Merged document service refactoring changes into java-notebooks patch
1 parent 74bf9c4 commit c822095

File tree

3 files changed

+563
-1431
lines changed

3 files changed

+563
-1431
lines changed

nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookDocumentServiceHandlerImpl.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -31,6 +31,10 @@
3131
import org.eclipse.lsp4j.DidSaveNotebookDocumentParams;
3232
import org.eclipse.lsp4j.MessageParams;
3333
import 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;
3438
import org.eclipse.lsp4j.jsonrpc.messages.Either;
3539
import org.eclipse.lsp4j.services.LanguageClient;
3640
import 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

Comments
 (0)