Skip to content

Commit

Permalink
domain code_ more green
Browse files Browse the repository at this point in the history
SQUASHED: more-green,
  • Loading branch information
JensLincke committed Oct 18, 2023
1 parent a7999f9 commit 54afd57
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/client/domain-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,13 @@ export class DomainObject {
if (!domainObject) {
domainObject = domainObjectById.get(action.node.id)
}
if (!domainObject) {
throw new Error("could not find treeSitter node")
}

// we ignore the value change of the update but take the actual other treesitter node that is responsible
let otherTreeSitter = newTreeSitterNodeById.get(action.other.id)
debugger

if (!otherTreeSitter) {
throw new Error("could not find other treeSitter node again")
}
Expand Down Expand Up @@ -351,8 +354,6 @@ export class TreeSitterDomainObject extends DomainObject {
newEndPosition: loc(newTo).asTreeSitter(),
}

this.treeSitter.tree.edit(edit);

DomainObject.edit(this.rootNode(), livelyCodeMirror.value, edit)

livelyCodeMirror.dispatchEvent(new CustomEvent("domain-code-changed", {detail: {node: this, edit: edit}}))
Expand Down Expand Up @@ -453,7 +454,9 @@ export class ReplacementDomainObject extends DomainObject {
return this.target && this.target.endPosition
}


get id() {
return this.target.id
}

get inspectorClassName() {
if (this.type) {
Expand Down
4 changes: 4 additions & 0 deletions src/client/domain-code/chawathe-script-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import {addMapping, getSrcForDst, getDstForSrc, isSrcMapped, isDstMapped, label,
function positionInParent(node) {
// return node.parent.children.indexOf(node) // object identity might be a problem?

if (!node.parent) {
return -1
}

// search for myself based on explicit id and not implicit identitity
for(let i=0; i < node.parent.children.length; i++) {
if (node.parent.children[i].id == node.id) return i
Expand Down
6 changes: 4 additions & 2 deletions src/components/tools/domain-code-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ export default class DomainCodeExplorer extends Morph {
this._autoUpdate = false
this.sourceEditor.setText(this.editor.getText())

this.treeSitterRootNode = evt.detail.node.debugNewAST.rootNode
this.astInspector.inspect(this.treeSitterRootNode)

// TODO
// this.treeSitterRootNode = evt.detail.node.debugNewAST.rootNode
// this.astInspector.inspect(this.treeSitterRootNode)

this._autoUpdate = true
}
Expand Down
54 changes: 48 additions & 6 deletions test/domain-code-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,43 @@ a = 3`

describe('SmilyReplacementDomainObject', () => {

it('click on let replacement works', () => {
it('click on let replacement works MANAL', () => {

var sourceCode =
`// hello
let a = 3 + 4
const b = a`
livelyCodeMirror.value = sourceCode

let domainObject = TreeSitterDomainObject.fromSource(sourceCode)
domainObject.replaceType('let', LetSmilyReplacementDomainObject)
domainObject.replaceType('const', ConstSmilyReplacementDomainObject)

expect(domainObject.children.length, "childrens").to.equal(3)

var letReplacement = domainObject.children[1].children[0]
expect(letReplacement.isReplacement).to.be.true
expect(letReplacement.type).to.equal("let")

// letReplacement.target.setText(livelyCodeMirror, "const")

// MANUAL
livelyCodeMirror.value = `// hello
const a = 3 + 4
const b = a`
DomainObject.edit(domainObject, livelyCodeMirror.value)


expect(livelyCodeMirror.value).to.match(/const a/)
expect(domainObject.treeSitter.childCount, "childCount after replacement").to.equal(3)
expect(domainObject.children.length, "children after replacement").to.equal(3)

var newConsDomainObject = domainObject.children[1].children[0]
expect(newConsDomainObject.type, "newConst").to.equal("const")
});

it('click on let replacement works via setText', () => {

var sourceCode =
`// hello
let a = 3 + 4
Expand All @@ -387,6 +422,13 @@ const b = a`
expect(letReplacement.type).to.equal("let")

letReplacement.target.setText(livelyCodeMirror, "const")

expect(livelyCodeMirror.value).to.equal(`// hello
const a = 3 + 4
const b = a`)



expect(livelyCodeMirror.value).to.match(/const a/)
expect(domainObject.treeSitter.childCount, "childCount after replacement").to.equal(3)
expect(domainObject.children.length, "children after replacement").to.equal(3)
Expand All @@ -395,6 +437,7 @@ const b = a`
expect(newConsDomainObject.type, "newConst").to.equal("const")
});


// #WIP continue here #KnownToFail
xit('click on const and then on let replacement', () => {
var sourceCode =
Expand All @@ -408,10 +451,9 @@ const b = a`
domainObject.replaceType('const', ConstSmilyReplacementDomainObject)


var consReplacement = domainObject.children[2].children[0]
var constReplacement = domainObject.children[2].children[0]

debugger
consReplacement.target.setText(livelyCodeMirror, "let")
constReplacement.target.setText(livelyCodeMirror, "let")

expect(livelyCodeMirror.value).to.match(/let b/)
expect(domainObject.treeSitter.childCount, "childCount after replacement").to.equal(3)
Expand Down Expand Up @@ -445,8 +487,8 @@ const b = a`
var letReplacement = domainObject.children[1].children[0]
letReplacement.target.setText(livelyCodeMirror, "const")

var consReplacement = domainObject.children[2].children[0]
consReplacement.target.setText(livelyCodeMirror, "let")
var constReplacement = domainObject.children[2].children[0]
constReplacement.target.setText(livelyCodeMirror, "let")
expect(livelyCodeMirror.value).to.match(/let b/)
expect(domainObject.treeSitter.childCount, "childCount after replacement").to.equal(3)
expect(domainObject.children.length, "children after replacement").to.equal(3)
Expand Down

0 comments on commit 54afd57

Please sign in to comment.