Skip to content

Commit

Permalink
Add open to Azimutt
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Nov 25, 2024
1 parent f57ac54 commit f19f431
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 9 additions & 8 deletions extensions/vscode-aml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ This Visual Studio Code extension provides language support for [AML](https://az

## Roadmap

- graph preview
- diagram preview + open in Azimutt
- convert AML to PostgreSQL, JSON, DOT, Mermaid, Markdown (Command Palette)
- convert SQL and JSON to AML (Command Palette)
- Add parsing errors
- auto-complete
- quick-fixes (code actions)
- Go-to-definition for relations (cf https://microsoft.github.io/monaco-editor/typedoc/interfaces/languages.DocumentSymbolProvider.html)
- hover info
- Add diagram preview & Open in Azimutt
- Add AML support in Markdown
- Add parsing errors ([createDiagnosticCollection](https://code.visualstudio.com/api/references/vscode-api#languages.createDiagnosticCollection)?)
- auto-complete (cf [registerCompletionItemProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerCompletionItemProvider.html))
- rename (cf [registerRenameProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerRenameProvider.html))
- hover infos (cf [registerHoverProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerHoverProvider.html))
- go-to-definition (cf [registerDefinitionProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerDefinitionProvider.html) and [registerImplementationProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerImplementationProvider.html))
- quick-fixes (cf [registerCodeActionProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerCodeActionProvider.html))
- hints with actions (cf [registerCodeLensProvider](https://microsoft.github.io/monaco-editor/typedoc/functions/languages.registerCodeLensProvider.html))
- AML support in Markdown
- Connect to a database


Expand Down
11 changes: 8 additions & 3 deletions extensions/vscode-aml/src/web/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function activate(context: ExtensionContext) {
vscode.commands.registerTextEditorCommand('aml.fromSQL', (editor: TextEditor) => convertSqlToAml(editor)),
vscode.commands.registerTextEditorCommand('aml.convert', (editor: TextEditor) => convertAmlToDialect(editor)),
vscode.commands.registerTextEditorCommand('aml.preview', (editor: TextEditor) => previewAml(editor, context)),
vscode.languages.registerDocumentSymbolProvider({scheme: 'file', language: 'aml'}, new AmlDocumentSymbolProvider()),
vscode.languages.registerDocumentSymbolProvider({language: 'aml'}, new AmlDocumentSymbolProvider()),
)
}

Expand Down Expand Up @@ -169,7 +169,7 @@ const updateAmlPreviewReal = (document: TextDocument, panel: WebviewPanel) => {
function buildAmlPreview(aml: string): string | undefined {
// const res = parseAml(aml)
// const content = res.result ? generateMermaid(res.result) : aml // TODO: render mermaid as svg
const content = aml
const content = aml.trim()
return `<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -178,11 +178,16 @@ function buildAmlPreview(aml: string): string | undefined {
<title>AML preview</title>
</head>
<body>
<a href="${openInAzimuttUrl(aml)}" target="_blank">Open in Azimutt</a>
<pre>${content}</pre>
</body>
</html>`
}

function openInAzimuttUrl(aml: string): string {
return 'https://azimutt.app/create?aml=' + encodeURIComponent(aml)
}

// see https://microsoft.github.io/monaco-editor/typedoc/interfaces/languages.DocumentSymbolProvider.html
class AmlDocumentSymbolProvider implements DocumentSymbolProvider {
provideDocumentSymbols(document: TextDocument, token: CancellationToken): ProviderResult<SymbolInformation[] | DocumentSymbol[]> {
Expand All @@ -191,7 +196,7 @@ class AmlDocumentSymbolProvider implements DocumentSymbolProvider {
let match: RegExpExecArray | null = null
while (match = regex.exec(document.getText())) {
const [all, lr, keyword, name] = match || []
if (name === 'rel') continue
if (name === 'rel') { continue }
const range = new Range(
document.positionAt(match.index + lr.length + (keyword || '').length),
document.positionAt(match.index + all.length)
Expand Down

0 comments on commit f19f431

Please sign in to comment.