Skip to content

Commit

Permalink
GH-1431: fix broken hierarchical vs non-hierarchical symbol generatio…
Browse files Browse the repository at this point in the history
…n for concourse yaml
  • Loading branch information
martinlippert committed Feb 20, 2025
1 parent ef83670 commit 6f06259
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.languageserver.util.DocumentSymbolHandler;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.util.text.DocumentRegion;
import org.springframework.ide.vscode.commons.util.text.IDocument;
Expand Down Expand Up @@ -140,20 +141,27 @@ public void addChild(DocumentSymbol sym) {

private Stack<Item> stack = new Stack<>();
private ImmutableList.Builder<DocumentSymbol> rootSymbols;
private SimpleLanguageServer server;

public TypeBasedYamlHierarchicalSymbolHandler(TypeBasedYamlSymbolHandler baseHandler,
List<HierarchicalDefType> hierarchicalDefinitionTypes) {
this.baseHandler = baseHandler;
Builder<YType, HierarchicalDefType> builder = ImmutableMap.builder();
for (HierarchicalDefType hdt : hierarchicalDefinitionTypes) {
builder.put(hdt.defType, hdt);
}
this.hierarchicalDefinitionTypes = builder.build();
public TypeBasedYamlHierarchicalSymbolHandler(TypeBasedYamlSymbolHandler baseHandler, List<HierarchicalDefType> hierarchicalDefinitionTypes, SimpleLanguageServer server) {
this.baseHandler = baseHandler;
Builder<YType, HierarchicalDefType> builder = ImmutableMap.builder();
for (HierarchicalDefType hdt : hierarchicalDefinitionTypes) {
builder.put(hdt.defType, hdt);
}
this.hierarchicalDefinitionTypes = builder.build();
this.server = server;
}

@Override
public List<? extends DocumentSymbol> handle(DocumentSymbolParams params) {
return outlineByUri.get(params.getTextDocument().getUri());
if (server.hasHierarchicalDocumentSymbolSupport()) {
return outlineByUri.get(params.getTextDocument().getUri());
}
else {
return this.baseHandler.handle(params);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public static void main(String[] args) throws Exception {
return new ASTTypeCache();
}

@Bean DocumentSymbolHandler documentSymbolHandler(SimpleTextDocumentService documents, ASTTypeCache astTypeCache, PipelineYmlSchema schema) {
@Bean DocumentSymbolHandler documentSymbolHandler(SimpleTextDocumentService documents, ASTTypeCache astTypeCache, PipelineYmlSchema schema, SimpleLanguageServer server) {
TypeBasedYamlSymbolHandler baseHandler = new TypeBasedYamlSymbolHandler(documents, astTypeCache, schema.getDefinitionTypes());
return new TypeBasedYamlHierarchicalSymbolHandler(baseHandler, schema.getHierarchicalDefinitionTypes());
return new TypeBasedYamlHierarchicalSymbolHandler(baseHandler, schema.getHierarchicalDefinitionTypes(), server);
}

@Bean PipelineYmlSchema pipelineYmlSchema(ConcourseModel models, GithubInfoProvider github) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2024 Pivotal, Inc.
* Copyright (c) 2016, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -5023,13 +5023,13 @@ void gotoSymbolInPipeline() throws Exception {
);

editor.assertDocumentSymbols(
"some-resource-type|ResourceType",
"foo-resource|Resource",
"bar-resource|Resource",
"do-some-stuff|Job",
"do-more-stuff|Job",
"group-one|Group",
"group-two|Group"
"some-resource-type",
"foo-resource",
"bar-resource",
"do-some-stuff",
"do-more-stuff",
"group-one",
"group-two"
);
}

Expand Down

0 comments on commit 6f06259

Please sign in to comment.