Skip to content

Commit b3b80ca

Browse files
authored
fix: Cannot new classes/packages for unmanaged folders (#415)
1 parent 7292411 commit b3b80ca

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,6 @@ public static IJavaProject getJavaProject(String projectUri) {
582582
}
583583

584584
for (IContainer container : containers) {
585-
if (!(container instanceof IProject)) {
586-
continue;
587-
}
588585
IProject project = container.getProject();
589586
if (!project.exists()) {
590587
return null;

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void setMetaDataValue(String key, Object value) {
151151
public static PackageNode createNodeForProject(IJavaElement javaElement) {
152152
IProject proj = javaElement.getJavaProject().getProject();
153153
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(), NodeKind.PROJECT);
154-
projectNode.setUri(proj.getLocationURI().toString());
154+
projectNode.setUri(ProjectUtils.getProjectRealFolder(proj).toFile().toURI().toString());
155155
try {
156156
projectNode.setMetaDataValue(NATURE_ID, proj.getDescription().getNatureIds());
157157
} catch (CoreException e) {

src/explorerCommands/new.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ async function getPackageFsPath(node: DataNode): Promise<string> {
5454
const packageNode: DataNode | undefined = childrenNodes.find((child) => {
5555
return child.nodeData.kind === NodeKind.Package;
5656
});
57-
if (packageNode?.uri) {
57+
if (!packageNode && node.uri) {
58+
// This means the .java files are in the default package.
59+
return Uri.parse(node.uri).fsPath;
60+
} else if (packageNode?.uri) {
5861
return getPackageRootPath(Uri.parse(packageNode.uri).fsPath, packageNode.name);
5962
}
6063
return "";

test/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export function fsPath(node: DataNode): string {
3030
if (!node.uri) {
3131
return "";
3232
}
33-
return Uri.parse(node.uri).fsPath;
33+
return path.resolve(Uri.parse(node.uri).fsPath);
3434
}
3535

3636
export function truePath(...paths: string[]) {
3737
const basePath = path.join(__dirname, "..", "..", "test");
38-
return path.join(basePath, ...paths);
38+
return path.resolve(path.join(basePath, ...paths));
3939
}
4040

4141
export async function setupTestEnv() {

0 commit comments

Comments
 (0)