diff --git a/x-pack/plugins/code/public/components/symbol_tree/__test__/__snapshots__/symbol_tree.test.tsx.snap b/x-pack/plugins/code/public/components/symbol_tree/__test__/__snapshots__/symbol_tree.test.tsx.snap
index 19ef5b9a3efca..941f3f96a3c32 100644
--- a/x-pack/plugins/code/public/components/symbol_tree/__test__/__snapshots__/symbol_tree.test.tsx.snap
+++ b/x-pack/plugins/code/public/components/symbol_tree/__test__/__snapshots__/symbol_tree.test.tsx.snap
@@ -471,6 +471,132 @@ exports[`render symbol tree correctly 1`] = `
+
diff --git a/x-pack/plugins/code/public/components/symbol_tree/__test__/props.ts b/x-pack/plugins/code/public/components/symbol_tree/__test__/props.ts
index b1799c3e2f7e4..5ab617e9b658c 100644
--- a/x-pack/plugins/code/public/components/symbol_tree/__test__/props.ts
+++ b/x-pack/plugins/code/public/components/symbol_tree/__test__/props.ts
@@ -85,6 +85,33 @@ export const props: { structureTree: SymbolWithMembers[] } = {
containerName: 'StackControl',
path: '"stack-control"/StackControl/stackView',
},
+ {
+ name: 'HashMap',
+ kind: SymbolKind.Class,
+ location: {
+ uri:
+ 'git://github.com/elastic/openjdkMirror/blob/master/jdk/src/share/classes/java/util/HashMap.java',
+ range: { start: { line: 136, character: 13 }, end: { line: 136, character: 20 } },
+ },
+ containerName: 'HashMap.java',
+ path: 'HashMap',
+ members: [
+ {
+ name: 'serialVersionUID',
+ kind: SymbolKind.Field,
+ location: {
+ uri:
+ 'git://github.com/elastic/openjdkMirror/blob/master/jdk/src/share/classes/java/util/HashMap.java',
+ range: {
+ start: { line: 139, character: 30 },
+ end: { line: 139, character: 46 },
+ },
+ },
+ containerName: 'HashMap',
+ path: 'HashMap/serialVersionUID',
+ },
+ ],
+ },
],
},
],
diff --git a/x-pack/plugins/code/public/reducers/symbol.ts b/x-pack/plugins/code/public/reducers/symbol.ts
index 2ef7d7be47f46..75a71894285f2 100644
--- a/x-pack/plugins/code/public/reducers/symbol.ts
+++ b/x-pack/plugins/code/public/reducers/symbol.ts
@@ -44,6 +44,15 @@ const initialState: SymbolState = {
closedPaths: [],
};
+const sortSymbol = (a: SymbolWithMembers, b: SymbolWithMembers) => {
+ const lineDiff = a.location.range.start.line - b.location.range.start.line;
+ if (lineDiff === 0) {
+ return a.location.range.start.character - b.location.range.start.character;
+ } else {
+ return lineDiff;
+ }
+};
+
const generateStructureTree: (symbols: SymbolInformation[]) => any = symbols => {
const structureTree: SymbolWithMembers[] = [];
@@ -51,7 +60,10 @@ const generateStructureTree: (symbols: SymbolInformation[]) => any = symbols =>
tree: SymbolWithMembers[],
containerName: string
): SymbolInformation | undefined {
- const result = tree.find((s: SymbolInformation) => s.name === containerName);
+ const regex = new RegExp(`^${containerName}[<(]?.*[>)]?$`);
+ const result = tree.find((s: SymbolInformation) => {
+ return regex.test(s.name);
+ });
if (result) {
return result;
} else {
@@ -67,33 +79,35 @@ const generateStructureTree: (symbols: SymbolInformation[]) => any = symbols =>
}
}
- symbols.forEach((s: SymbolInformation, index: number, arr: SymbolInformation[]) => {
- let container: Container;
- /**
- * For Enum class in Java, the container name and symbol name that LSP gives are special.
- * For more information, see https://github.com/elastic/codesearch/issues/580
- */
- if (s.containerName === SPECIAL_CONTAINER_NAME) {
- container = _.findLast(
- arr.slice(0, index),
- (sy: SymbolInformation) => sy.name === SPECIAL_SYMBOL_NAME
- );
- } else {
- container = findContainer(structureTree, s.containerName || '');
- }
- if (container) {
- if (!container.path) {
- container.path = container.name;
+ symbols
+ .sort(sortSymbol)
+ .forEach((s: SymbolInformation, index: number, arr: SymbolInformation[]) => {
+ let container: Container;
+ /**
+ * For Enum class in Java, the container name and symbol name that LSP gives are special.
+ * For more information, see https://github.com/elastic/codesearch/issues/580
+ */
+ if (s.containerName === SPECIAL_CONTAINER_NAME) {
+ container = _.findLast(
+ arr.slice(0, index),
+ (sy: SymbolInformation) => sy.name === SPECIAL_SYMBOL_NAME
+ );
+ } else {
+ container = findContainer(structureTree, s.containerName || '');
}
- if (container.members) {
- container.members.push({ ...s, path: `${container.path}/${s.name}` });
+ if (container) {
+ if (!container.path) {
+ container.path = container.name;
+ }
+ if (container.members) {
+ container.members.push({ ...s, path: `${container.path}/${s.name}` });
+ } else {
+ container.members = [{ ...s, path: `${container.path}/${s.name}` }];
+ }
} else {
- container.members = [{ ...s, path: `${container.path}/${s.name}` }];
+ structureTree.push(s);
}
- } else {
- structureTree.push(s);
- }
- });
+ });
return structureTree;
};