Skip to content

Commit 24c8ff8

Browse files
committed
additional steps towards opening stereotype definition doc
1 parent 1147e1c commit 24c8ff8

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Node createTree(IJavaProject project, IndexBasedStereotypeFactory factory
5555
};
5656

5757
// create json nodes to display the structure in a nice way
58-
var jsonHandler = new JsonNodeHandler<StereotypePackageElement, Object>(labelProvider, consumer, springIndex, catalog);
58+
var jsonHandler = new JsonNodeHandler<StereotypePackageElement, Object>(labelProvider, consumer, springIndex, catalog, project);
5959

6060
// create the project tree and apply all the groupers from the project
6161
// TODO: in the future, we need to trim this grouper arrays down to what is selected on the UI

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ide.vscode.boot.java.commands;
1818

19+
import java.net.URI;
1920
import java.net.URISyntaxException;
2021
import java.net.URL;
2122
import java.util.ArrayList;
@@ -38,6 +39,7 @@
3839
import org.springframework.ide.vscode.boot.java.stereotypes.StereotypeClassElement;
3940
import org.springframework.ide.vscode.boot.java.stereotypes.StereotypeMethodElement;
4041
import org.springframework.ide.vscode.boot.java.stereotypes.StereotypePackageElement;
42+
import org.springframework.ide.vscode.commons.java.IJavaProject;
4143
import org.springframework.ide.vscode.commons.protocol.spring.SymbolElement;
4244

4345
import com.google.gson.Gson;
@@ -60,15 +62,17 @@ public class JsonNodeHandler<A, C> implements NodeHandler<A, StereotypePackageEl
6062
private final LabelProvider<A, StereotypePackageElement, StereotypeClassElement, StereotypeMethodElement, C> labels;
6163
private final BiConsumer<Node, C> customHandler;
6264
private final CachedSpringMetamodelIndex springIndex;
65+
private final IJavaProject project;
6366

6467
private Node current;
6568
private StereotypeCatalog catalog;
6669

6770
public JsonNodeHandler(LabelProvider<A, StereotypePackageElement, StereotypeClassElement, StereotypeMethodElement, C> labels, BiConsumer<Node, C> customHandler,
68-
CachedSpringMetamodelIndex springIndex, StereotypeCatalog catalog) {
71+
CachedSpringMetamodelIndex springIndex, StereotypeCatalog catalog, IJavaProject project) {
6972
this.labels = labels;
7073
this.springIndex = springIndex;
7174
this.customHandler = customHandler;
75+
this.project = project;
7276

7377
this.root = new Node(null);
7478
this.current = root;
@@ -90,10 +94,17 @@ public void handleStereotype(Stereotype stereotype, NodeContext context) {
9094
String reference = null;
9195
for (Object source : sources) {
9296
if (source instanceof URL) {
93-
try {
94-
reference = ((URL)source).toURI().toASCIIString();
95-
} catch (URISyntaxException e) {
96-
// ignore
97+
URL url = (URL) source;
98+
if (url.getProtocol().equals("jar")) {
99+
reference = convertUrlToJdtUri((URL) source, project.getElementName());
100+
}
101+
else if (url.getProtocol().equals("file")) {
102+
try {
103+
reference = url.toURI().toASCIIString();
104+
}
105+
catch (URISyntaxException e) {
106+
// something went wrong
107+
}
97108
}
98109
}
99110
else if (source instanceof Location) {
@@ -111,6 +122,38 @@ else if (source instanceof Location) {
111122
}
112123
}
113124

125+
private String convertUrlToJdtUri(URL url, String projectName) {
126+
try {
127+
URI uri = url.toURI();
128+
129+
// Extract the scheme-specific part (everything after "jar:")
130+
String schemeSpecificPart = uri.getSchemeSpecificPart();
131+
132+
// Split on "!/" to separate jar file path from internal path
133+
String[] parts = schemeSpecificPart.split("!/", 2);
134+
135+
if (parts.length != 2) {
136+
return null;
137+
}
138+
139+
String jarFilePath = parts[0];
140+
String internalPath = parts[1];
141+
142+
// Remove "file:" prefix from jar file path if present
143+
if (jarFilePath.startsWith("file:")) {
144+
jarFilePath = jarFilePath.substring(5);
145+
}
146+
147+
String jarFileName = jarFilePath.substring(jarFilePath.lastIndexOf('/') + 1);
148+
149+
// Construct the JDT URI with just the jar file name
150+
return "jdt://contents/" + jarFileName + "/" + internalPath + "?=" + projectName;
151+
152+
} catch (URISyntaxException e) {
153+
return null;
154+
}
155+
}
156+
114157
@Override
115158
public void handleApplication(A application) {
116159
this.root

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Node createTree(IJavaProject project, IndexBasedStereotypeFactory factory
5656
};
5757

5858
// create json nodes to display the structure in a nice way
59-
var jsonHandler = new JsonNodeHandler<ApplicationModules, NamedInterfaceNode>(labelProvider, consumer, springIndex, catalog);
59+
var jsonHandler = new JsonNodeHandler<ApplicationModules, NamedInterfaceNode>(labelProvider, consumer, springIndex, catalog, project);
6060

6161
// create the project tree and apply all the groupers from the project
6262
// TODO: in the future, we need to trim this grouper arrays down to what is selected on the UI

vscode-extensions/vscode-spring-boot/lib/explorer/nodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TextDocumentShowOptions, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
1+
import { TextDocumentShowOptions, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
22
import { Location } from "vscode-languageclient";
33
import { LsStereoTypedNode } from "./structure-tree-manager";
44

@@ -56,7 +56,7 @@ export class StereotypedNode extends SpringNode {
5656
item.command = {
5757
command: "vscode.open",
5858
title: "Navigate",
59-
arguments: [location.uri, {
59+
arguments: [Uri.parse(location.uri), {
6060
selection: location.range
6161
} as TextDocumentShowOptions]
6262
};

0 commit comments

Comments
 (0)