Skip to content

Commit 79a904a

Browse files
committed
GH-1642: moved stereotype definition locoation to inline action in the tree view and switched the locaiton information to a dedicated attribute
1 parent c3196c2 commit 79a904a

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
import org.eclipse.lsp4j.DocumentSymbol;
3131
import org.eclipse.lsp4j.Location;
32-
import org.eclipse.lsp4j.Position;
33-
import org.eclipse.lsp4j.Range;
3432
import org.jmolecules.stereotype.api.Stereotype;
3533
import org.jmolecules.stereotype.catalog.StereotypeCatalog;
3634
import org.jmolecules.stereotype.tooling.LabelProvider;
@@ -52,6 +50,7 @@
5250
public class JsonNodeHandler<A, C> implements NodeHandler<A, StereotypePackageElement, StereotypeClassElement, StereotypeMethodElement, C> {
5351

5452
private static final String LOCATION = "location";
53+
private static final String REFERENCE = "reference";
5554

5655
public static final String ICON = "icon";
5756
public static final String TEXT = "text";
@@ -88,27 +87,26 @@ public void handleStereotype(Stereotype stereotype, NodeContext context) {
8887
var definition = catalog.getDefinition(stereotype);
8988
var sources = definition.getSources();
9089

91-
Location location = null;
90+
String reference = null;
9291
for (Object source : sources) {
9392
if (source instanceof URL) {
9493
try {
95-
String uri = ((URL)source).toURI().toString();
96-
location = new Location(uri, new Range(new Position(0, 0), new Position(0, 0)));
94+
reference = ((URL)source).toURI().toASCIIString();
9795
} catch (URISyntaxException e) {
9896
// ignore
9997
}
10098
}
10199
else if (source instanceof Location) {
102-
location = ((Location) source);
100+
reference = ((Location) source).getUri();
103101
}
104102
}
105103

106-
final Location finalLocation = location;
104+
final String referenceUri = reference;
107105
addChild(node -> node
108106
.withAttribute(TEXT, labels.getStereotypeLabel(stereotype))
109107
.withAttribute(ICON, StereotypeIcons.getIcon(stereotype))
110108
.withAttribute(HOVER, "defined in: " + sources.toString())
111-
.withAttribute(LOCATION, finalLocation)
109+
.withAttribute(REFERENCE, referenceUri)
112110
);
113111
}
114112
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,16 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
187187
const structureManager = new StructureManager();
188188
const explorerTreeProvider = new ExplorerTreeProvider(structureManager);
189189
context.subscriptions.push(window.createTreeView('explorer.spring', { treeDataProvider: explorerTreeProvider, showCollapseAll: true }));
190-
context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.refresh", () => structureManager.refresh(true)));
190+
context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.refresh", () => structureManager.refresh(true)));
191+
context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.openReference", (node) => {
192+
if (node && node.getReferenceValue) {
193+
const reference = node.getReferenceValue();
194+
if (reference) {
195+
// Reference is a specific URL that should be passed to java.open.file command
196+
commands.executeCommand('java.open.file', reference);
197+
}
198+
}
199+
}));
191200

192201
context.subscriptions.push(commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
193202
// Boot LS is fully started

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export class StereotypedNode extends SpringNode {
2020
const item = super.getTreeItem();
2121
item.label = this.n.attributes.text;
2222
item.iconPath = this.computeIcon();
23+
24+
// Add context value if reference attribute exists
25+
if (this.n.attributes.reference) {
26+
item.contextValue = "stereotypedNodeWithReference";
27+
}
28+
2329
if (this.n.attributes.location) {
2430
const location = this.n.attributes.location as Location;
2531
// Hard-coded range. Not present... likely not serialized correctly.
@@ -34,6 +40,10 @@ export class StereotypedNode extends SpringNode {
3440
return item;
3541
}
3642

43+
getReferenceValue(): any {
44+
return this.n.attributes.reference;
45+
}
46+
3747
computeIcon() {
3848
return new ThemeIcon(this.n.attributes.icon);
3949
/* switch (this.n.attributes.icon) {

vscode-extensions/vscode-spring-boot/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@
203203
"command": "vscode-spring-boot.live.hide.active",
204204
"group": "Spring Boot"
205205
}
206+
],
207+
"view/item/context": [
208+
{
209+
"command": "vscode-spring-boot.structure.openReference",
210+
"when": "view == explorer.spring && viewItem == stereotypedNodeWithReference",
211+
"group": "inline"
212+
}
206213
]
207214
},
208215
"commands": [
@@ -296,6 +303,12 @@
296303
"title": "Apply Changes",
297304
"category": "Spring Boot Agent",
298305
"enablement": "false"
306+
},
307+
{
308+
"command": "vscode-spring-boot.structure.openReference",
309+
"title": "Open Reference",
310+
"category": "Spring Boot",
311+
"icon": "$(link-external)"
299312
}
300313
],
301314
"configuration": [

0 commit comments

Comments
 (0)