Skip to content

Commit 03ca407

Browse files
committed
Make "..." clickable to reveal abbreviated name
1 parent 58afeba commit 03ca407

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

extensions/ql-vscode/src/view/compare-performance/RAPrettyPrinter.tsx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment } from "react";
1+
import { Fragment, useState } from "react";
22
import { styled } from "styled-components";
33

44
/**
@@ -29,6 +29,21 @@ interface QualifiedName {
2929
args?: QualifiedName[];
3030
}
3131

32+
function qnameToString(name: QualifiedName): string {
33+
const parts: string[] = [];
34+
if (name.prefix != null) {
35+
parts.push(qnameToString(name.prefix));
36+
parts.push("::");
37+
}
38+
parts.push(name.name);
39+
if (name.args != null && name.args.length > 0) {
40+
parts.push("<");
41+
parts.push(name.args.map(qnameToString).join(","));
42+
parts.push(">");
43+
}
44+
return parts.join("");
45+
}
46+
3247
function tokeniseName(text: string) {
3348
return Array.from(text.matchAll(/:+|<|>|,|"[^"]+"|`[^`]+`|[^:<>,"`]+/g));
3449
}
@@ -137,7 +152,10 @@ class TrieBuilder {
137152
if (args != null) {
138153
result.push("<");
139154
if (trieNodeBeforeArgs.children.size === 1) {
140-
result.push("...");
155+
const argsText = qname
156+
.args!.map((arg) => qnameToString(arg))
157+
.join(",");
158+
result.push(<ExpandableNamePart>{argsText}</ExpandableNamePart>);
141159
} else {
142160
let first = true;
143161
for (const arg of args) {
@@ -157,6 +175,30 @@ class TrieBuilder {
157175
}
158176
}
159177

178+
const ExpandableTextButton = styled.button`
179+
background: none;
180+
border: none;
181+
cursor: pointer;
182+
padding: 0;
183+
color: inherit;
184+
&:hover {
185+
background-color: rgba(128, 128, 128, 0.2);
186+
}
187+
`;
188+
189+
interface ExpandableNamePartProps {
190+
children: React.ReactNode;
191+
}
192+
193+
function ExpandableNamePart(props: ExpandableNamePartProps) {
194+
const [isExpanded, setExpanded] = useState(false);
195+
return (
196+
<ExpandableTextButton onClick={() => setExpanded(!isExpanded)}>
197+
{isExpanded ? props.children : "..."}
198+
</ExpandableTextButton>
199+
);
200+
}
201+
160202
/**
161203
* Span enclosing an entire qualified name.
162204
*

0 commit comments

Comments
 (0)