GH-1431: fix broken hierarchical vs non-hierarchical symbol generation for concourse yaml
This commit is contained in:
@@ -22,6 +22,7 @@ import org.eclipse.lsp4j.SymbolKind;
|
||||
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;
|
||||
@@ -140,20 +141,27 @@ public class TypeBasedYamlHierarchicalSymbolHandler implements DocumentSymbolHan
|
||||
|
||||
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
|
||||
|
||||
@@ -48,9 +48,9 @@ public class ConcourseLanguageServerBootApp {
|
||||
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) {
|
||||
|
||||
@@ -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
|
||||
@@ -5023,13 +5023,13 @@ public class ConcourseEditorTest {
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user