Skip to content

Commit

Permalink
filled it with some life
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-components-tools-astro-view-example-workspace.js,AUTO-COMMIT-src-components-tools-astro-view.html,AUTO-COMMIT-src-components-tools-astro-view.js,empty-new-astro-view,
  • Loading branch information
JensLincke committed Feb 22, 2024
1 parent 4a2ae7d commit d9600cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
5 changes: 4 additions & 1 deletion src/components/tools/astro-view-example-workspace.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// now wen have a workspace
// now wen have a workspace


this
8 changes: 8 additions & 0 deletions src/components/tools/astro-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
max-height: 300px
}

.token {
margin: 2px; padding: 2px; display:inline-block
}

.token.selected {
outline: 2px solid green
}

</style>

<div id="content" class="pane layout-column">
Expand Down
101 changes: 44 additions & 57 deletions src/components/tools/astro-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import SyntaxChecker from 'src/client/syntax.js'

import { uuid as generateUUID, debounce, flatmap, executeAllTestRunners, promisedEvent, loc, range } from 'utils';

import {DomainObject, TreeSitterDomainObject, LetSmilyReplacementDomainObject, ConstSmilyReplacementDomainObject} from "src/client/domain-code.js"


export default class AstroView extends Morph {

static get defaultSourceURL() { return lively4url + "/src/components/tools/astro-view-example-source.js"; }
Expand All @@ -22,7 +19,6 @@ export default class AstroView extends Morph {
get sourceEditor() { return this.get("#source"); }
get workspaceEditor() { return this.get("#workspace"); }


get sourceLCM() { return this.sourceEditor.livelyCodeMirror(); }
get sourceCM() { return this.sourceEditor.currentEditor(); }
get source() { return this.sourceCM.getValue(); }
Expand All @@ -37,9 +33,7 @@ export default class AstroView extends Morph {

get workspaceURL() { return this.workspaceEditor.getURL(); }
set workspaceURL(urlString) {
this.workspaceEditor.setURL(urlString) }
// onSourcePathEntered(urlString) { this.loadSourceFile(urlString); }

this.workspaceEditor.setURL(urlString) }

get updateButton() { return this.get("#update"); }

Expand Down Expand Up @@ -116,76 +110,67 @@ export default class AstroView extends Morph {
const workspace = this.getAttribute("workspace");
if (workspace) this.loadWorkspaceFile(workspace);


this.workspaceEditor.awaitEditor().then(() => {
// this object for workspace....
this.workspaceEditor.livelyCodeMirror().getDoitContext = () => this
})

this.dispatchEvent(new CustomEvent("initialize"));
}

onClearLog() {

}


onEditorCursorActivity(cm) {
var from = cm.getCursor(true)
var to = cm.getCursor(false)

this.get("#editorInfo").textContent = `${cm.indexFromPos(from)}-${cm.indexFromPos(to)}`
}

onDomainObjectSelect(node, object) {

if(!object.isDomainObject) return false


var currentRootNode = object.rootNode().treeSitter
if (currentRootNode !== this.treeSitterRootNode) {
this.treeSitterRootNode = currentRootNode
this.astInspector.inspect(this.treeSitterRootNode);
updateTokens() {
this.get("#tokens").innerHTML = ""
let counter = 1
let pos = 0
this.tokens = this.source.split(/(?=[^a-zA-z])/g)
.map(ea => {
let start = pos
let end = start + ea.length
pos = end
return { id: counter++, start: start, end: end, value: ea}
})
.filter(ea => !ea.value.match(/[ \n]+/))

for(let token of this.tokens) {
let tokenView = <div class="token" style="">
<div style="font-size: 6pt">{token.id}</div>
<div style="background-color: lightgray" click={() => this.selectToken(tokenView, token)}>{token.value}</div>
<div style="font-size: 6pt; color: blue">{token.start}-{token.end}</div>
</div>
this.get("#tokens").appendChild(tokenView)
}
this.astInspector.selectNode(object.treeSitter)

}

onDomainCodeChanged() {
this.log("domain code changed " + this.isUpdating + " length: " + this.editor.getText().length)

if (this.lastSource == this.editor.getText()) return

// this.domainObjectInspector.inspect(this.domainObjectInspector.targetObject)

// prevent cycle....
var oldAutoUpdate = this._autoUpdate
this._autoUpdate = false

var newSource = this.editor.getText()
this.sourceEditor.setText(newSource)
selectToken(view, token) {
if (this.selectedTokenView) this.selectedTokenView.classList.remove("selected")
view.classList.add("selected")
this.selectedTokenView = view

DomainObject.edit(this.domainObject, newSource, undefined, {
newAST: (ast) => {

this.astInspector.inspect(ast.rootNode);
}
})
this.get("#embeddings").innerHTML = ""
let rows = []

let tds = Array.from(token.value)
.map(ea => ea.charCodeAt(0))
.map(ea => <td style="border: 1px solid gray">{ea}</td>)

rows.push(<tr>{...tds}</tr>)

this.domainObject.updateReplacements()
this.domainObjectInspector.inspect(this.domainObject)
let table = <table style="border-collapse: collapse; border: 1px solid gray">{...rows}</table>

// TODO
// this.treeSitterRootNode = evt.detail.node.debugNewAST.rootNode
// this.astInspector.inspect(this.treeSitterRootNode)
this.get("#embeddings").appendChild(table)

this._autoUpdate = true
}

onDomainUpdateButton() {
lively.notify("update")
this.domainObjectInspector.inspect(this.domainObjectInspector.targetObject)
}

onDomainGraphButton() {
lively.openMarkdown(lively4url + "/src/components/tools/domain-code-graph.md",
"Domain Code Graph", {domainObject: this.domainObject})
}


/*MD ## Execution MD*/

async update() {
Expand All @@ -199,6 +184,8 @@ export default class AstroView extends Morph {
} catch (e) {
this.astInspector.inspect({Error: e.message});
}

this.updateTokens()
}

async save() {
Expand Down

0 comments on commit d9600cb

Please sign in to comment.