diff --git a/icons/decorations/arrow-both.svg b/icons/decorations/arrow-both.svg new file mode 100644 index 0000000..102e890 --- /dev/null +++ b/icons/decorations/arrow-both.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + diff --git a/icons/decorations/arrow-left.svg b/icons/decorations/arrow-left.svg new file mode 100644 index 0000000..08a1a73 --- /dev/null +++ b/icons/decorations/arrow-left.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + diff --git a/icons/decorations/arrow-right.svg b/icons/decorations/arrow-right.svg new file mode 100644 index 0000000..5224d3c --- /dev/null +++ b/icons/decorations/arrow-right.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + diff --git a/src/extension.ts b/src/extension.ts index 2c56b3e..a9ab619 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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) { - clz.relationships.forEach(rel => { + 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); }); }