Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,132 @@ exports[`render symbol tree correctly 1`] = `
</div>
</div>
</div>
<div
className="euiSideNavItem euiSideNavItem--branch euiSideNavItem--hasChildItems"
>
<div
className="euiFlexGroup euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
className="sc-bwzfXH eSZWNW"
>
<svg
className="euiIcon euiIcon--small euiIcon--subdued codeStructureTree--icon"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<defs>
<path
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z"
id="arrow_down-a"
/>
</defs>
<use
fillRule="nonzero"
xlinkHref="#arrow_down-a"
/>
</svg>
<div
className="euiFlexItem euiFlexItem--flexGrow1"
>
<a
className="code-link"
href="/github.com/elastic/openjdkMirror/blob/master/jdk/src/share/classes/java/util/HashMap.java!L137:13?tab=structure"
onClick={[Function]}
>
<div
className="euiFlexGroup euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive code-structure-node"
>
<div
className="euiToken euiToken--tokenTint01 euiToken--circle euiToken--small sc-htpNat hDSXcY"
>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M11.333 7.027H9.375c-.056-.708-.48-1.187-1.222-1.187-.972 0-1.5.806-1.5 2.16 0 1.43.545 2.16 1.486 2.16.708 0 1.139-.415 1.236-1.08l1.958.015C11.236 10.418 10.181 12 8.097 12c-1.958 0-3.43-1.41-3.43-4 0-2.6 1.514-4 3.43-4 1.792 0 3.084 1.095 3.236 3.027z"
fillRule="evenodd"
/>
</svg>
</div>
<div
className="euiText euiText--small"
data-test-subj="codeStructureTreeNode-HashMap<K, V>"
>
HashMap&lt;K, V&gt;
</div>
</div>
</a>
</div>
</div>
</div>
<div
className="euiSideNavItem__items"
>
<div
className="euiSideNavItem euiSideNavItem--branch"
>
<div
className="euiFlexGroup euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
className="sc-bwzfXH havHSm"
>
<div
className="euiFlexItem euiFlexItem--flexGrow1"
>
<a
className="code-link"
href="/github.com/elastic/openjdkMirror/blob/master/jdk/src/share/classes/java/util/HashMap.java!L140:30?tab=structure"
onClick={[Function]}
>
<div
className="euiFlexGroup euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive code-structure-node"
>
<div
className="euiToken euiToken--tokenTint10 euiToken--circle euiToken--small sc-htpNat hDSXcY"
>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.27 12V4h5.46v1.57H7.203v1.641h3.18v1.574h-3.18V12z"
fillRule="evenodd"
/>
</svg>
</div>
<div
className="euiText euiText--small"
data-test-subj="codeStructureTreeNode-serialVersionUID"
>
serialVersionUID
</div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ export const props: { structureTree: SymbolWithMembers[] } = {
containerName: 'StackControl',
path: '"stack-control"/StackControl/stackView',
},
{
name: 'HashMap<K, V>',
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<K, V>',
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<K, V>/serialVersionUID',
},
],
},
],
},
],
Expand Down
64 changes: 39 additions & 25 deletions x-pack/plugins/code/public/reducers/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ 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[] = [];

function findContainer(
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 {
Expand All @@ -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;
};
Expand Down