Skip to content

Commit 350f102

Browse files
committed
Adopt VSCode to location. Eclipse open any JAR support
1 parent c6199aa commit 350f102

File tree

5 files changed

+89
-17
lines changed

5 files changed

+89
-17
lines changed

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/commands/OpenJarEntryInEditor.java

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*******************************************************************************/
1111
package org.springframework.tooling.ls.eclipse.commons.commands;
1212

13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import java.net.JarURLConnection;
1316
import java.net.URI;
1417
import java.util.Optional;
1518

@@ -18,7 +21,9 @@
1821
import org.eclipse.core.commands.ExecutionException;
1922
import org.eclipse.core.commands.IHandler;
2023
import org.eclipse.core.resources.IProject;
24+
import org.eclipse.core.resources.IStorage;
2125
import org.eclipse.core.resources.ResourcesPlugin;
26+
import org.eclipse.core.runtime.CoreException;
2227
import org.eclipse.core.runtime.IPath;
2328
import org.eclipse.core.runtime.IStatus;
2429
import org.eclipse.core.runtime.Path;
@@ -65,13 +70,78 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
6570
IJavaProject javaProject = JavaCore.create(project);
6671
if (javaProject != null) {
6772
JarUri jarUri = createJarUri(uri);
68-
findJavaObj(javaProject, jarUri).ifPresent(s -> {
73+
Object inputElement = findJavaObj(javaProject, jarUri).orElseGet(() -> {
6974
try {
70-
EditorUtility.openInEditor(s, true);
75+
JarURLConnection c = (JarURLConnection) uri.toURL().openConnection();
76+
return new IStorage() {
77+
78+
@Override
79+
public <T> T getAdapter(Class<T> adapter) {
80+
if (URI.class.equals(adapter)) {
81+
return (T) uri;
82+
}
83+
return null;
84+
}
85+
86+
@Override
87+
public InputStream getContents() throws CoreException {
88+
try {
89+
return c.getInputStream();
90+
} catch (IOException e) {
91+
throw new CoreException(new Status(IStatus.ERROR,
92+
LanguageServerCommonsActivator.PLUGIN_ID, "Cannot load JAR entry", e));
93+
}
94+
}
95+
96+
@Override
97+
public IPath getFullPath() {
98+
return new Path(jarUriStr);
99+
}
100+
101+
@Override
102+
public String getName() {
103+
return new Path(c.getEntryName()).lastSegment();
104+
}
105+
106+
@Override
107+
public boolean isReadOnly() {
108+
return true;
109+
}
110+
111+
@Override
112+
public int hashCode() {
113+
return uri.hashCode();
114+
}
115+
116+
@Override
117+
public boolean equals(Object obj) {
118+
if (obj instanceof IStorage s) {
119+
return uri.equals(s.getAdapter(URI.class));
120+
}
121+
return false;
122+
}
123+
124+
@Override
125+
public String toString() {
126+
return jarUriStr;
127+
}
128+
129+
130+
131+
};
132+
} catch (IOException e) {
133+
LanguageServerCommonsActivator.getInstance().getLog().log(new Status(IStatus.ERROR,
134+
LanguageServerCommonsActivator.PLUGIN_ID, "Cannot load JAR entry: " + uri));
135+
return null;
136+
}
137+
});
138+
if (inputElement != null) {
139+
try {
140+
EditorUtility.openInEditor(inputElement, true);
71141
} catch (PartInitException e) {
72142
LanguageServerCommonsActivator.getInstance().getLog().log(e.getStatus());
73143
}
74-
});
144+
}
75145
} else {
76146
LanguageServerCommonsActivator.getInstance().getLog().log(new Status(IStatus.WARNING,
77147
LanguageServerCommonsActivator.PLUGIN_ID, "Cannot find project: " + projectName));

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands/JsonNodeHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import org.eclipse.lsp4j.DocumentSymbol;
3232
import org.eclipse.lsp4j.Location;
33+
import org.eclipse.lsp4j.Position;
3334
import org.eclipse.lsp4j.Range;
3435
import org.jmolecules.stereotype.api.Stereotype;
3536
import org.jmolecules.stereotype.catalog.StereotypeCatalog;
@@ -110,7 +111,7 @@ public void handleStereotype(Stereotype stereotype, NodeContext context) {
110111

111112
try {
112113
URI uri = url.toURI();
113-
reference = new Location(uri.toASCIIString(), new Range());
114+
reference = new Location(uri.toASCIIString(), new Range(new Position(0,0), new Position(0,0)));
114115
if (Misc.JAR.equals(uri.getScheme())) {
115116
sourceLinks.sourceLinkForJarEntry(project, uri).map(u -> u.toASCIIString()).ifPresent(reference::setUri);
116117
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/stereotypes/IndexBasedStereotypeFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ private static boolean doesImplement(StereotypeClassElement type, String fqn) {
127127
}
128128

129129
private StereotypePackageElement findPackageFor(StereotypeClassElement type) {
130-
String packageName = type.getType().substring(0, type.getType().lastIndexOf('.'));
131-
return springIndex.findPackageNode(packageName, this.project.getElementName());
130+
int index = type.getType().lastIndexOf('.');
131+
if (index >= 0) {
132+
String packageName = type.getType().substring(0, index);
133+
return springIndex.findPackageNode(packageName, this.project.getElementName());
134+
}
135+
return null;
132136
}
133137

134138
private void registerStereotype(StereotypeDefinitionElement element) {

vscode-extensions/vscode-spring-boot/lib/Main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
160160

161161
return commons.activate(options, context).then(client => {
162162

163-
// Activation of structure explorer
164-
const structureManager = new StructureManager(context);
165-
new ExplorerTreeProvider(structureManager).createTreeView(context, 'explorer.spring');
166-
167163
context.subscriptions.push(commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
168164
// Boot LS is fully started
169165
registerClasspathService(client);
@@ -201,8 +197,10 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
201197

202198
const api = new ApiManager(client).api
203199

204-
context.subscriptions.push(api.getSpringIndex().onSpringIndexUpdated(e => structureManager.refresh(false)));
205-
200+
// Activation of structure explorer
201+
const structureManager = new StructureManager(context, api);
202+
new ExplorerTreeProvider(structureManager).createTreeView(context, 'explorer.spring');
203+
206204
return api;
207205
});
208206
}

vscode-extensions/vscode-spring-boot/lib/explorer/structure-tree-manager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ export class StructureManager {
1616
this.workspaceState = context.workspaceState;
1717
context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.refresh", () => this.refresh(true)));
1818
context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.openReference", (node) => {
19-
if (node && node.getReferenceValue) {
20-
const reference = node.getReferenceValue();
21-
if (reference) {
22-
commands.executeCommand('vscode.open', api.client.protocol2CodeConverter.asLocation(reference as ls.Location));
23-
}
19+
const reference = node?.getReferenceValue() as ls.Location;;
20+
if (reference) {
21+
const location = api.client.protocol2CodeConverter.asLocation(reference)
22+
window.showTextDocument(location.uri, { selection: location.range });
2423
}
2524
}));
2625

0 commit comments

Comments
 (0)