Skip to content

Commit 6c2ad3b

Browse files
authored
Merge pull request #2 from Microsoft/yaohai_dev
Fix issues with the initialization and refactor.
2 parents 6cc1bce + 1a0a1db commit 6c2ad3b

23 files changed

+149
-59
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
88
* Contributors:
99
* Microsoft Corporation - initial API and implementation
1010
*******************************************************************************/
11+
1112
package com.microsoft.jdtls.ext.core;
1213

1314
import java.util.List;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@
1414
import java.net.URI;
1515
import java.net.URISyntaxException;
1616

17+
import org.eclipse.core.runtime.IPath;
1718
import org.eclipse.jdt.core.IPackageFragmentRoot;
1819
import org.eclipse.jdt.internal.core.JarEntryFile;
1920
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
@@ -34,4 +35,10 @@ public static String toUri(JarEntryFile jarEntryFile) {
3435
}
3536
}
3637

38+
public static IPath removeProjectSegment(String projectElementName, IPath path) {
39+
if (projectElementName.equals(path.segment(0))) {
40+
return path.removeFirstSegments(1).makeRelative();
41+
}
42+
return path;
43+
}
3744
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

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

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -61,7 +61,7 @@ public class PackageCommand {
6161
static {
6262
commands = new HashMap<>();
6363
commands.put(NodeKind.PROJECT, PackageCommand::getContainers);
64-
commands.put(NodeKind.CONTAINER, PackageCommand::getJars);
64+
commands.put(NodeKind.CONTAINER, PackageCommand::getPackageFragmentRoots);
6565
commands.put(NodeKind.JAR, PackageCommand::getPackages);
6666
commands.put(NodeKind.PACKAGE, PackageCommand::getClassfiles);
6767
commands.put(NodeKind.Folder, PackageCommand::getFolderChildren);
@@ -73,8 +73,8 @@ public class PackageCommand {
7373
* @param arguments
7474
* List of the arguments which contain two entries to get class path
7575
* children: the first entry is the query target node type
76-
* {@link NodeKind} and the second one is the query instance
77-
* of type {@link PackageParams}
76+
* {@link NodeKind} and the second one is the query instance of type
77+
* {@link PackageParams}
7878
* @return the found ClasspathNode list
7979
* @throws CoreException
8080
*/
@@ -86,8 +86,7 @@ public static List<PackageNode> getChildren(List<Object> arguments, IProgressMon
8686

8787
BiFunction<PackageParams, IProgressMonitor, List<PackageNode>> loader = commands.get(params.getKind());
8888
if (loader == null) {
89-
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
90-
String.format("Unknown classpath item type: %s", params.getKind())));
89+
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("Unknown classpath item type: %s", params.getKind())));
9190
}
9291
List<PackageNode> result = loader.apply(params, pm);
9392
return result;
@@ -102,30 +101,34 @@ private static List<PackageNode> getContainers(PackageParams query, IProgressMon
102101
if (javaProject != null) {
103102
try {
104103
IClasspathEntry[] references = javaProject.getRawClasspath();
105-
return Arrays.stream(references)
106-
.map(entry -> {
107-
try {
108-
entry = JavaCore.getResolvedClasspathEntry(entry);
109-
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
110-
javaProject);
111-
if (container != null) {
112-
PackageNode containerNode = new PackageNode(container.getDescription(),
113-
container.getPath().toPortableString(), NodeKind.CONTAINER);
114-
return containerNode;
104+
return Arrays.stream(references).map(entry -> {
105+
try {
106+
entry = JavaCore.getResolvedClasspathEntry(entry);
107+
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
108+
if (container != null) {
109+
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
110+
IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry);
111+
for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) {
112+
String rootName = ExtUtils.removeProjectSegment(javaProject.getElementName(), fragmentRoot.getPath()).toPortableString();
113+
return new PackageNode(rootName, fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
115114
}
116-
} catch (CoreException e) {
117-
// Ignore it
115+
} else {
116+
return new PackageNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER);
118117
}
119-
return null;
120-
}).filter(containerNode -> containerNode != null).collect(Collectors.toList());
118+
}
119+
} catch (CoreException e) {
120+
// Ignore it
121+
}
122+
return null;
123+
}).filter(containerNode -> containerNode != null).collect(Collectors.toList());
121124
} catch (CoreException e) {
122125
JavaLanguageServerPlugin.logException("Problem load project library ", e);
123126
}
124127
}
125128
return Collections.emptyList();
126129
}
127130

128-
private static List<PackageNode> getJars(PackageParams query, IProgressMonitor pm) {
131+
private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IProgressMonitor pm) {
129132
IJavaProject javaProject = getJavaProject(query.getProjectUri());
130133

131134
if (javaProject != null) {
@@ -142,8 +145,7 @@ private static List<PackageNode> getJars(PackageParams query, IProgressMonitor p
142145
ArrayList<PackageNode> children = new ArrayList<>();
143146
IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(containerEntry);
144147
for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) {
145-
PackageNode node = new PackageNode(fragmentRoot.getElementName(),
146-
fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
148+
PackageNode node = new PackageNode(fragmentRoot.getElementName(), fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
147149
children.add(node);
148150
if (fragmentRoot instanceof JrtPackageFragmentRoot) {
149151
node.setModuleName(fragmentRoot.getModuleDescription().getElementName());
@@ -165,11 +167,9 @@ private static List<PackageNode> getPackages(PackageParams query, IProgressMonit
165167
if (javaProject != null) {
166168

167169
try {
168-
IPackageFragmentRoot packageRoot = javaProject
169-
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
170+
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
170171
if (packageRoot == null) {
171-
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
172-
String.format("No package root found for %s", query.getPath())));
172+
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
173173
}
174174
Object[] result = getPackageFragmentRootContent(packageRoot, pm);
175175
return convertToClasspathNode(result);
@@ -184,21 +184,17 @@ private static List<PackageNode> getClassfiles(PackageParams query, IProgressMon
184184
IJavaProject javaProject = getJavaProject(query.getProjectUri());
185185
if (javaProject != null) {
186186
try {
187-
IPackageFragmentRoot packageRoot = javaProject
188-
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
187+
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
189188
if (packageRoot == null) {
190-
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
191-
String.format("No package root found for %s", query.getPath())));
189+
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
192190
}
193191
IPackageFragment packageFragment = packageRoot.getPackageFragment(query.getPath());
194192
if (packageFragment != null) {
195193
IJavaElement[] classFiles = packageFragment.getChildren();
196-
return Arrays.stream(classFiles).filter(classFile -> !classFile.getElementName().contains("$"))
197-
.map(classFile -> {
198-
PackageNode item = new PackageNode(classFile.getElementName(),
199-
classFile.getPath().toPortableString(), NodeKind.CLASSFILE);
200-
return item;
201-
}).collect(Collectors.toList());
194+
return Arrays.stream(classFiles).filter(classFile -> !classFile.getElementName().contains("$")).map(classFile -> {
195+
PackageNode item = new PackageNode(classFile.getElementName(), classFile.getPath().toPortableString(), NodeKind.CLASSFILE);
196+
return item;
197+
}).collect(Collectors.toList());
202198

203199
}
204200
} catch (CoreException e) {
@@ -212,11 +208,9 @@ private static List<PackageNode> getFolderChildren(PackageParams query, IProgres
212208
IJavaProject javaProject = getJavaProject(query.getProjectUri());
213209
if (javaProject != null) {
214210
try {
215-
IPackageFragmentRoot packageRoot = javaProject
216-
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
211+
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
217212
if (packageRoot == null) {
218-
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
219-
String.format("No package root found for %s", query.getPath())));
213+
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
220214
}
221215
// jar file and folders
222216
Object[] resources = packageRoot.getNonJavaResources();
@@ -240,8 +234,7 @@ private static List<PackageNode> getFolderChildren(PackageParams query, IProgres
240234
return Collections.emptyList();
241235
}
242236

243-
private static Object[] getPackageFragmentRootContent(IPackageFragmentRoot root, IProgressMonitor pm)
244-
throws CoreException {
237+
private static Object[] getPackageFragmentRootContent(IPackageFragmentRoot root, IProgressMonitor pm) throws CoreException {
245238
ArrayList<Object> result = new ArrayList<>();
246239
for (IJavaElement child : root.getChildren()) {
247240
IPackageFragment fragment = (IPackageFragment) child;
@@ -263,8 +256,7 @@ private static List<PackageNode> convertToClasspathNode(Object[] rootContent) th
263256
for (Object root : rootContent) {
264257
if (root instanceof IPackageFragment) {
265258
IPackageFragment packageFragment = (IPackageFragment) root;
266-
PackageNode entry = new PackageNode(((IPackageFragment) root).getElementName(),
267-
packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
259+
PackageNode entry = new PackageNode(((IPackageFragment) root).getElementName(), packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
268260
result.add(entry);
269261
} else if (root instanceof IClassFile) {
270262
IClassFile classFile = (IClassFile) root;
@@ -284,11 +276,9 @@ private static List<PackageNode> convertToClasspathNode(Object[] rootContent) th
284276

285277
private static PackageNode getJarEntryResource(JarEntryResource resource) {
286278
if (resource instanceof JarEntryDirectory) {
287-
return new PackageNode(resource.getName(), resource.getFullPath().toPortableString(),
288-
NodeKind.Folder);
279+
return new PackageNode(resource.getName(), resource.getFullPath().toPortableString(), NodeKind.Folder);
289280
} else if (resource instanceof JarEntryFile) {
290-
PackageNode entry = new PackageNode(resource.getName(), resource.getFullPath().toPortableString(),
291-
NodeKind.FILE);
281+
PackageNode entry = new PackageNode(resource.getName(), resource.getFullPath().toPortableString(), NodeKind.FILE);
292282
entry.setUri(ExtUtils.toUri((JarEntryFile) resource));
293283
return entry;
294284
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2018 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

jdtls.ext/target.target

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?pde version="3.8"?><target name="JDTLS.EXT" sequenceNumber="38">
3+
<locations>
4+
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
5+
<unit id="org.eclipse.libra.framework.feature.feature.group" version="0.3.1.201609011955"/>
6+
<repository location="http://download.eclipse.org/releases/oxygen"/>
7+
</location>
8+
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
9+
<unit id="org.eclipse.xtend.sdk.feature.group" version="2.13.0.v20171020-0920"/>
10+
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.13.0.v20171020-0920"/>
11+
<repository location="http://download.eclipse.org/releases/photon/"/>
12+
</location>
13+
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
14+
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.4.0.v20180301-0956"/>
15+
<repository location="http://download.eclipse.org/lsp4j/updates/milestones"/>
16+
</location>
17+
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
18+
<unit id="org.eclipse.jdt.ls.core" version="0.16.0.201804042215"/>
19+
<repository location="http://download.eclipse.org/jdtls/snapshots/repository/0.16.0.201804042215/"/>
20+
</location>
21+
</locations>
22+
</target>

vscode/images/statusMarker.png

-10.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)