preliminary support for decorating Relationship declarations with their Mocha relationship type and friendly name

This commit is contained in:
Michael Becker 2025-04-02 05:47:36 -04:00
parent a6e608e1fc
commit b58def7680
4 changed files with 284 additions and 12 deletions

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="12.22255mm"
height="2.476717mm"
viewBox="0 0 12.22255 2.476717"
version="1.1"
id="svg1085"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
sodipodi:docname="arrow-both.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1087"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="17.709562"
inkscape:cx="21.400868"
inkscape:cy="18.831635"
inkscape:window-width="1840"
inkscape:window-height="1011"
inkscape:window-x="80"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1082">
<linearGradient
id="linearGradient2780"
inkscape:swatch="solid">
<stop
style="stop-color:#595959;stop-opacity:1;"
offset="0"
id="stop2778" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient2780"
id="linearGradient2782"
x1="146.74658"
y1="95.895023"
x2="158.96913"
y2="95.895023"
gradientUnits="userSpaceOnUse" />
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-146.74658,-94.656664)">
<path
style="fill:url(#linearGradient2782);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.36765;stroke-dasharray:none;stop-color:#000000"
d="m 146.74658,95.835989 3.76255,-1.174495 v 0.690318 h 4.30912 v -0.695148 l 4.15088,1.147258 -4.11513,1.324734 V 96.42606 h -4.30143 v 0.707321 z"
id="path367"
sodipodi:nodetypes="ccccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="12.22255mm"
height="2.476717mm"
viewBox="0 0 12.22255 2.476717"
version="1.1"
id="svg1085"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
sodipodi:docname="arrow-left.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1087"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="17.709562"
inkscape:cx="19.763335"
inkscape:cy="18.831635"
inkscape:window-width="1840"
inkscape:window-height="1011"
inkscape:window-x="80"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1082">
<linearGradient
id="linearGradient1031"
inkscape:swatch="solid">
<stop
style="stop-color:#595959;stop-opacity:1;"
offset="0"
id="stop1029" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1031"
id="linearGradient1033"
x1="146.77032"
y1="95.89266"
x2="155.23032"
y2="95.89266"
gradientUnits="userSpaceOnUse" />
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-146.74658,-94.656664)">
<path
style="fill:url(#linearGradient1033);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.36765;stroke-dasharray:none;stop-color:#000000"
d="m 155.23032,95.351812 h -4.30912 v -0.695148 l -4.15088,1.147258 4.11513,1.324734 V 96.42606 h 4.30143 z"
id="path367"
sodipodi:nodetypes="cccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="12.22255mm"
height="2.476717mm"
viewBox="0 0 12.22255 2.476717"
version="1.1"
id="svg1085"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
sodipodi:docname="arrow-right.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1087"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="17.709562"
inkscape:cx="21.400868"
inkscape:cy="18.888101"
inkscape:window-width="1840"
inkscape:window-height="1011"
inkscape:window-x="80"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1082">
<linearGradient
id="linearGradient1918"
inkscape:swatch="solid">
<stop
style="stop-color:#595959;stop-opacity:1;"
offset="0"
id="stop1916" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1918"
id="linearGradient1920"
x1="150.50913"
y1="95.89266"
x2="158.96913"
y2="95.89266"
gradientUnits="userSpaceOnUse" />
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-146.74658,-94.656664)">
<path
style="fill:url(#linearGradient1920);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.36765;stroke-dasharray:none;stop-color:#000000"
d="m 150.50913,95.351812 h 4.30912 v -0.695148 l 4.15088,1.147258 -4.11513,1.324734 V 96.42606 h -4.30143 z"
id="path367"
sodipodi:nodetypes="cccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -151,19 +151,20 @@ const options = {
borderStyle: 'solid',
overviewRulerColor: 'blue',
overviewRulerLane: vscode.OverviewRulerLane.Right,
light: {
// this color will be used in light color themes
overviewRulerLane: vscode.OverviewRulerLane.Right,
light: {
// this color will be used in light color themes
borderColor: 'darkblue',
contentIconPath: extension?.extensionPath + '/icons/light/explorer/class.svg'
},
dark: {
// this color will be used in dark color themes
borderColor: 'lightblue',
},
dark: {
// this color will be used in dark color themes
borderColor: 'lightblue',
contentIconPath: extension?.extensionPath + '/icons/dark/explorer/class.svg'
}
}
}
};
const classDecorationType = vscode.window.createTextEditorDecorationType({
before:
{
@ -499,15 +500,82 @@ export function activate(context: vscode.ExtensionContext) {
});
context.subscriptions.push(cmd_suv_up);
const relationshipDecorations: vscode.TextEditorDecorationType[] = [];
context.subscriptions.push(vscode.window.onDidChangeTextEditorSelection((e) => {
if (e.textEditor.document.languageId === "zql") {
let clz = ZqParser.parse(e.textEditor.document.getText()) as ZqClass;
if (clz !== null)
{
relationshipDecorations.forEach(element => {
e.textEditor.setDecorations(element, []);
});
clz.relationships.forEach(rel => {
let n = "";
let ns = [];
for (var i = 0; i < rel.name.length; i++) {
if (i < rel.name.length - 1 && rel.name[i].toUpperCase() === rel.name[i] && rel.name[i + 1].toLowerCase() === rel.name[i + 1]) {
ns.push(n);
n = "";
}
n += rel.name[i];
}
if (n !== "") {
ns.push(n);
}
let nom = "", rest = "";
for (var i = 0; i < ns.length; i++) {
if (i === 0) {
nom = ns[i];
}
else {
rest += ns[i] + ' ';
}
}
rest = rest.trim();
const relationshipDecorationType = vscode.window.createTextEditorDecorationType({
before:
{
contentIconPath: extension?.extensionPath + '/icons/decorations/arrow-both.svg',
margin: "2px 10px 2px 10px"
}
});
const relationshipDecorationType2 = vscode.window.createTextEditorDecorationType({
before:
{
contentText: nom,
margin: "0px 4px 0px 4px",
fontWeight: "bold"
}
});
const relationshipDecorationType3 = vscode.window.createTextEditorDecorationType({
before:
{
contentText: rest,
margin: "0px 4px 0px 4px",
color: "#4EC9B0"
}
});
e.textEditor.setDecorations(relationshipDecorationType, [
new vscode.Range(rel.definition.lineIndex + 1 /*hack*/, rel.definition.columnIndex + rel.toString().length + 16,
rel.definition.lineIndex + 1, rel.definition.columnIndex + rel.toString().length + 16)
]);
e.textEditor.setDecorations(relationshipDecorationType2, [
new vscode.Range(rel.definition.lineIndex + 1 /*hack*/, rel.definition.columnIndex + rel.toString().length + 24,
rel.definition.lineIndex + 1, rel.definition.columnIndex + rel.toString().length + 24)
]);
e.textEditor.setDecorations(relationshipDecorationType3, [
new vscode.Range(rel.definition.lineIndex + 1 /*hack*/, rel.definition.columnIndex + rel.toString().length + 24 + nom.length,
rel.definition.lineIndex + 1, rel.definition.columnIndex + rel.toString().length + 24 + nom.length)
]);
relationshipDecorations.push(relationshipDecorationType);
relationshipDecorations.push(relationshipDecorationType2);
relationshipDecorations.push(relationshipDecorationType3);
});
}