Skip to content

Commit a96d9e6

Browse files
committed
Handle snippets when opened (empty) Java file triggers activation.
- When extension is activated by opened empty Java source file, the snippet insertion logic has yet to be registered so boilerplate type declaration snippet cannot be applied - Recover by detecting opened, active Java source file and create the appropriate type declaration Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent fdca5e1 commit a96d9e6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,18 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
577577
commands.executeCommand('setContext', 'java:serverMode', event);
578578
});
579579

580+
// extension activated by creation of new Java file ?
581+
// type declaration snippet handler registered late so adjust the file here
582+
apiManager.getApiInstance().serverReady().then(async () => {
583+
const te = window.activeTextEditor?.document;
584+
if (te && te.getText().trim().length === 0) {
585+
fileEventHandler.setServerStatus(true);
586+
fileEventHandler.handleNewJavaFiles({
587+
files: [te.uri]
588+
});
589+
}
590+
});
591+
580592
if (serverMode === ServerMode.hybrid && !await fse.pathExists(path.join(workspacePath, ".metadata", ".plugins"))) {
581593
const config = getJavaConfiguration();
582594
const importOnStartupSection: string = "project.importOnFirstTimeStartup";

src/fileEventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function registerFileEventHandlers(client: LanguageClient, context: Exten
2727
}
2828
}
2929

30-
async function handleNewJavaFiles(e: FileCreateEvent) {
30+
export async function handleNewJavaFiles(e: FileCreateEvent) {
3131
const emptyFiles: Uri[] = [];
3232
const textDocuments: TextDocument[] = [];
3333
for (const uri of e.files) {

0 commit comments

Comments
 (0)