From 978d6890dce9e7293c22dea93a47f1ad8ff4ba0f Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Mon, 9 Jun 2025 17:20:33 -0400 Subject: [PATCH] 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 --- src/fileEventHandler.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/fileEventHandler.ts b/src/fileEventHandler.ts index e14970f089..3d6595987f 100644 --- a/src/fileEventHandler.ts +++ b/src/fileEventHandler.ts @@ -10,6 +10,7 @@ import { WillRenameFiles } from './protocol'; import { getJavaConfiguration } from './utils'; import { userInfo } from 'os'; import * as stringInterpolate from 'fmtr'; +import { apiManager } from './apiManager'; let serverReady: boolean = false; @@ -25,6 +26,18 @@ export function registerFileEventHandlers(client: LanguageClient, context: Exten if (workspace.onWillRenameFiles) { context.subscriptions.push(workspace.onWillRenameFiles(getWillRenameHandler(client))); } + + // extension activated and empty Java file is in active editor ? + // type declaration snippet handler activated too late so adjust the file here + apiManager.getApiInstance().serverReady().then(async () => { + const te = window.activeTextEditor?.document; + if (te && te.getText().trim().length === 0) { + setServerStatus(true); + handleNewJavaFiles({ + files: [te.uri] + }); + } + }); } async function handleNewJavaFiles(e: FileCreateEvent) {