Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates.
* Copyright (c) 2025-2026, Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,59 +15,27 @@
*/
package org.netbeans.modules.nbcode.java.notebook;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.jshell.JShell;
import org.eclipse.lsp4j.CallHierarchyItem;
import org.eclipse.lsp4j.CallHierarchyPrepareParams;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.CodeLensParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.CompletionParams;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.DidChangeNotebookDocumentParams;
import org.eclipse.lsp4j.DidCloseNotebookDocumentParams;
import org.eclipse.lsp4j.DidOpenNotebookDocumentParams;
import org.eclipse.lsp4j.DidSaveNotebookDocumentParams;
import org.eclipse.lsp4j.DocumentHighlight;
import org.eclipse.lsp4j.DocumentHighlightParams;
import org.eclipse.lsp4j.FoldingRange;
import org.eclipse.lsp4j.FoldingRangeRequestParams;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.HoverParams;
import org.eclipse.lsp4j.ImplementationParams;
import org.eclipse.lsp4j.InlayHint;
import org.eclipse.lsp4j.InlayHintParams;
import org.eclipse.lsp4j.InlineValue;
import org.eclipse.lsp4j.InlineValueParams;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.PrepareRenameDefaultBehavior;
import org.eclipse.lsp4j.PrepareRenameParams;
import org.eclipse.lsp4j.PrepareRenameResult;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.ReferenceParams;
import org.eclipse.lsp4j.SemanticTokens;
import org.eclipse.lsp4j.SemanticTokensParams;
import org.eclipse.lsp4j.SignatureHelp;
import org.eclipse.lsp4j.SignatureHelpParams;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.TypeDefinitionParams;
import org.eclipse.lsp4j.WillSaveTextDocumentParams;
import org.eclipse.lsp4j.NotebookDocumentSyncRegistrationOptions;
import org.eclipse.lsp4j.NotebookSelector;
import org.eclipse.lsp4j.NotebookSelectorCell;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.messages.Either3;
import org.eclipse.lsp4j.services.LanguageClient;
import org.netbeans.modules.java.lsp.server.notebook.NotebookDocumentServiceHandler;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
Expand All @@ -92,7 +60,7 @@ public class NotebookDocumentServiceHandlerImpl implements NotebookDocumentServi
private final Map<String, NotebookDocumentStateManager> notebookStateMap = new ConcurrentHashMap<>();
// Below map is required because completion request doesn't send notebook uri in the params
private final Map<String, String> notebookCellMap = new ConcurrentHashMap<>();

@Override
public void didOpen(DidOpenNotebookDocumentParams params) {
try {
Expand Down Expand Up @@ -158,105 +126,30 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
return CompletableFuture.completedFuture(Either.forRight(new CompletionList()));
}
}

@Override
public void connect(LanguageClient client) {
LanguageClientInstance.getInstance().setClient((NbCodeLanguageClient) client);
NotebookConfigs.getInstance().initConfigs();

}

@Override
public CompletableFuture<SemanticTokens> semanticTokensFull(SemanticTokensParams params) {
LOG.finer("SemanticTokensFull is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<List<CallHierarchyItem>> prepareCallHierarchy(CallHierarchyPrepareParams params) {
LOG.finer("prepareCallHierarchy is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<Either3<Range, PrepareRenameResult, PrepareRenameDefaultBehavior>> prepareRename(PrepareRenameParams params) {
LOG.finer("prepareRename is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestParams params) {
LOG.finer("foldingRange is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentParams params) {
LOG.finer("willSaveWaitUntil is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
LOG.finer("codeLens is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
LOG.finer("codeAction is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(DocumentHighlightParams params) {
LOG.finer("documentHighlight is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
LOG.finer("references is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Collections.emptyList());
}

@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> implementation(ImplementationParams params) {
LOG.finer("implementation is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
}

@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams params) {
LOG.finer("typeDefinition is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
}

@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams params) {
LOG.finer("definition is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
@Override // connect must be called before init
public void init(ServerCapabilities serverCapabilities){
if (clientWantsNotebook()) {
NotebookDocumentSyncRegistrationOptions opts = createNotebookRegOpts();
serverCapabilities.setNotebookDocumentSync(opts);
}
}

@Override
public CompletableFuture<SignatureHelp> signatureHelp(SignatureHelpParams params) {
LOG.finer("signatureHelp is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(null);
private boolean clientWantsNotebook() {
NbCodeLanguageClient client = LanguageClientInstance.getInstance().getClient();
return client != null && client.getNbCodeCapabilities().wantsNotebookSupport();
}

@Override
public CompletableFuture<Hover> hover(HoverParams params) {
LOG.finer("hover is not supported yet in notebookDocumentService");
return CompletableFuture.completedFuture(null);
private NotebookDocumentSyncRegistrationOptions createNotebookRegOpts() {
NotebookDocumentSyncRegistrationOptions opts = new NotebookDocumentSyncRegistrationOptions();
NotebookSelector ns = new NotebookSelector();
ns.setNotebook("*");
ns.setCells(List.of(new NotebookSelectorCell("java"), new NotebookSelectorCell("markdown")));
opts.setNotebookSelector(List.of(ns));
return opts;
}

@Override
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
return CompletableFuture.completedFuture(new ArrayList<>());
}

@Override
public CompletableFuture<List<InlineValue>> inlineValue(InlineValueParams params) {
return CompletableFuture.completedFuture(new ArrayList<>());
}
}
Loading