Skip to content

Commit 8a642e5

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 <[email protected]>
1 parent fdca5e1 commit 8a642e5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/fileEventHandler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { WillRenameFiles } from './protocol';
1010
import { getJavaConfiguration } from './utils';
1111
import { userInfo } from 'os';
1212
import * as stringInterpolate from 'fmtr';
13+
import { apiManager } from './apiManager';
1314

1415
let serverReady: boolean = false;
1516

@@ -25,6 +26,18 @@ export function registerFileEventHandlers(client: LanguageClient, context: Exten
2526
if (workspace.onWillRenameFiles) {
2627
context.subscriptions.push(workspace.onWillRenameFiles(getWillRenameHandler(client)));
2728
}
29+
30+
// extension activated and empty Java file is in active editor ?
31+
// type declaration snippet handler activated too late so adjust the file here
32+
apiManager.getApiInstance().serverReady().then(async () => {
33+
const te = window.activeTextEditor?.document;
34+
if (te && te.getText().trim().length === 0) {
35+
setServerStatus(true);
36+
handleNewJavaFiles({
37+
files: [te.uri]
38+
});
39+
}
40+
});
2841
}
2942

3043
async function handleNewJavaFiles(e: FileCreateEvent) {

0 commit comments

Comments
 (0)