|
3 | 3 |
|
4 | 4 | import * as fse from "fs-extra"; |
5 | 5 | 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"; |
7 | 8 | import { Commands } from "../../extension.bundle"; |
| 9 | +import { ExtensionName } from "../constants"; |
8 | 10 | import { NodeKind } from "../java/nodeData"; |
9 | 11 | import { DataNode } from "../views/dataNode"; |
10 | 12 | import { checkJavaQualifiedName } from "./utility"; |
11 | 13 |
|
12 | 14 | export async function newJavaClass(node?: DataNode): Promise<void> { |
13 | 15 | let packageFsPath: string | undefined; |
14 | 16 | if (!node) { |
| 17 | + // from the new file menu entry |
15 | 18 | packageFsPath = await inferPackageFsPath(); |
16 | 19 | } else { |
17 | 20 | if (!node?.uri || !canCreateClass(node)) { |
@@ -73,6 +76,20 @@ async function newUntiledJavaFile(): Promise<void> { |
73 | 76 | } |
74 | 77 |
|
75 | 78 | 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 | + |
76 | 93 | let sourcePaths: string[] | undefined; |
77 | 94 | try { |
78 | 95 | const result = await commands.executeCommand<IListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS); |
|
0 commit comments