Skip to content

Temp document service refactoring changes#541

Open
shivam71 wants to merge 2 commits intooracle:mainfrom
shivam71:document-service-refactor
Open

Temp document service refactoring changes#541
shivam71 wants to merge 2 commits intooracle:mainfrom
shivam71:document-service-refactor

Conversation

@shivam71
Copy link
Member

No description provided.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 12, 2026
Copy link
Member

@Achal1607 Achal1607 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shivam71 for refactoring the code, it will help us in maintainability of the code.
Also one more nit, format the code for the changes that you have made if possible.

+ rq.setMethod(newMethod);
+ }
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NullPointerException ex) {
+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the behaviour of the request if a notebook sends a request for let's day formatter but if that method is not implemented by the notebook then would it come in the catch block?
If yes, then can we add at least a FINE level logger so that exceptions are not swallowed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if the method is not implemented we get a JSON-RPC error of UnsupportedRequestMethod exception .
In this try catch however that cannot be caught , here the reflection based errors are being caught . Hence that exception is not being swallowed here .

private OperationContext initialContext;
private List<Object> additionalServices = new ArrayList<>();
-
+ private static final String NOTEBOOK_TEXT_DOC_URI_IDENTIFIER = "vscode-notebook-cell";// NOI18N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think vscode-notebook-cell is a property of NotebookDocumentService, then you can create a static member in the NotebookDocumentService and then reference it everywhere for identifier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure !

+ String newMethod = rq.getMethod().replaceFirst("textDocument", "notebookDocument");
+ rq.setMethod(newMethod);
+ }
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NullPointerException ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the behaviour of the request if a notebook sends a request for let's day formatter but if that method is not implemented by the notebook then would it come in the catch block?
Also, can we add at least a FINE level logger in the catch block so that exceptions are not swallowed.

+ // LSP Client sends requests for notebook cells with textDocument prefix
+ // Our notebookDocumentService implementation requires different implementation for these requests
+ try {
+ Class<?> paramClass = p.getClass();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any alternate approach possible here, apart from using reflection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core idea was to make it generic so in future we can just add new methods in NotebookDocumentServiceHandler
without making any changes in this part of the code . For now we could have just done this delegation for completion request in particular and not do any reflection .

private static final Logger LOG = Logger.getLogger(LanguageServerImpl.class.getName());
private NbCodeClientWrapper client;
private final TextDocumentServiceImpl textDocumentService = new TextDocumentServiceImpl(this);
+ private final NotebookDocumentServiceHandler notebookDocService = Lookup.getDefault().lookup(NotebookDocumentServiceHandler.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Lookup.getDefault().lookup(NotebookDocumentServiceHandler.class) can be moved into the getNotebookDocumentService() method so that the lookup is performed only when needed. Additionally, if NotebookDocumentServiceHandler is not yet loaded during Server class initialization, the current approach could lead to issues.

sessionServices.add(inputService.getRegistry());
sessionServices.add(workspaceService.getWorkspace());
((LanguageClientAware) getTextDocumentService()).connect(client);
+ ((LanguageClientAware) getNotebookDocumentService()).connect(client);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null check for getNotebookDocumentService() would be good, since we don't contribute our nbcode to Netbeans, but if we contribute the LSP code to Netbeans, it will not find any NotebookDocumentServiceHandler and fail with a NPE before starting the server itself.


public void init(ClientCapabilities clientCapabilities, ServerCapabilities severCapabilities) {
+ setServerSemanticTokenProvider(clientCapabilities,severCapabilities);
+ setServerNotebookCaps(severCapabilities);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is now proper isolation between the TextDocumentService and the NotebookDocumentService, would it be possible to move setServerNotebookCaps into the NotebookDocumentService as well?
I’m not entirely sure whether this is feasible, it’s just a thought, but if it is, it would be good to move this responsibility out as well for better separation of concerns.

}
}
-
+ public void testDelegationForNotebookCells() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one more test, for a method which is not implemented, so that we know that the exception is thrown and caught in the catch block?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add copyright 2025-2026

@shivam71 shivam71 force-pushed the document-service-refactor branch from e68e21a to 35880ed Compare January 30, 2026 11:38
@shivam71 shivam71 marked this pull request as ready for review February 2, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants