Skip to content

Commit e7b4f72

Browse files
authored
fix: Create untitled new file when JLS is not ready (#540)
1 parent 9549809 commit e7b4f72

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/explorerCommands/new.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33

44
import * as fse from "fs-extra";
55
import * as path from "path";
6-
import { commands, languages, QuickPickItem, SnippetString, TextEditor, Uri, window, workspace, WorkspaceEdit, WorkspaceFolder } from "vscode";
6+
import { commands, Extension, extensions, languages, QuickPickItem, SnippetString, TextEditor, Uri,
7+
window, workspace, WorkspaceEdit, WorkspaceFolder } from "vscode";
78
import { Commands } from "../../extension.bundle";
9+
import { ExtensionName } from "../constants";
810
import { NodeKind } from "../java/nodeData";
911
import { DataNode } from "../views/dataNode";
1012
import { checkJavaQualifiedName } from "./utility";
1113

1214
export async function newJavaClass(node?: DataNode): Promise<void> {
1315
let packageFsPath: string | undefined;
1416
if (!node) {
17+
// from the new file menu entry
1518
packageFsPath = await inferPackageFsPath();
1619
} else {
1720
if (!node?.uri || !canCreateClass(node)) {
@@ -73,6 +76,20 @@ async function newUntiledJavaFile(): Promise<void> {
7376
}
7477

7578
async function inferPackageFsPath(): Promise<string> {
79+
const javaLanguageSupport: Extension<any> | undefined = extensions.getExtension(ExtensionName.JAVA_LANGUAGE_SUPPORT);
80+
if (!javaLanguageSupport || !javaLanguageSupport.isActive) {
81+
return "";
82+
}
83+
84+
const extensionApi: any = javaLanguageSupport.exports;
85+
if (!extensionApi) {
86+
return "";
87+
}
88+
89+
if (extensionApi.serverMode !== "Standard" || extensionApi.status !== "Started") {
90+
return "";
91+
}
92+
7693
let sourcePaths: string[] | undefined;
7794
try {
7895
const result = await commands.executeCommand<IListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS);

0 commit comments

Comments
 (0)