Skip to content

Commit 18fbe52

Browse files
committed
Enable formatting java in jupyter notebook
1 parent c0a9565 commit 18fbe52

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ export namespace Commands {
366366
*/
367367
export const SHOW_EXTEND_OUTLINE = 'java.action.showExtendedOutline';
368368

369+
/**
370+
* Get the content of the currently visible editor.
371+
*/
372+
export const GET_VISIBLE_EDITOR_CONTENT = '_java.getVisibleEditorContent';
373+
369374
}
370375

371376
/**

src/extension.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
202202
documentSelector: [
203203
{ scheme: 'file', language: 'java' },
204204
{ scheme: 'jdt', language: 'java' },
205-
{ scheme: 'untitled', language: 'java' }
205+
{ scheme: 'untitled', language: 'java' },
206+
{ scheme: 'vscode-notebook-cell', language: 'java' }
206207
],
207208
synchronize: {
208209
configurationSection: ['java', 'editor.insertSpaces', 'editor.tabSize', "files.associations"],
@@ -511,6 +512,20 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
511512

512513
context.subscriptions.push(onConfigurationChange(workspacePath, context));
513514

515+
context.subscriptions.push(commands.registerCommand(Commands.GET_VISIBLE_EDITOR_CONTENT, (uri: string) => {
516+
for (const editor of window.visibleTextEditors) {
517+
if (editor.document.uri.toString() === uri) {
518+
return editor.document.getText();
519+
}
520+
}
521+
const editor = window.activeTextEditor;
522+
if (editor) {
523+
return editor.document.getText();
524+
} else {
525+
return null;
526+
}
527+
}));
528+
514529
registerRestartJavaLanguageServerCommand(context);
515530

516531
/**

0 commit comments

Comments
 (0)