Skip to content

Commit

Permalink
moved treesitter loading into own module
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-demos-tree-sitter-index.md,AUTO-COMMIT-src-client-domain-code.js,AUTO-COMMIT-src-client-tree-sitter.js,AUTO-COMMIT-src-components-tools-domain-code-explorer.js,AUTO-COMMIT-src-components-tools-lively-ast-domain-object-inspector.js,AUTO-COMMIT-src-components-tools-lively-ast-inspector.js,AUTO-COMMIT-src-components-tools-lively-ast-treesitter-inspector.js,
  • Loading branch information
JensLincke committed Sep 14, 2023
1 parent d7de01d commit 0d20467
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
12 changes: 1 addition & 11 deletions demos/tree-sitter/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
😊

<script>
await lively.loadJavaScriptThroughDOM("treeSitter", lively4url + "/src/external/tree-sitter/tree-sitter.js")


const Parser = window.TreeSitter;
await Parser.init()

const parser = new Parser;


const JavaScript = await Parser.Language.load(lively4url + "/src/external/tree-sitter/tree-sitter-javascript.wasm");

import {Parser, JavaScript} from "src/client/tree-sitter.js"

parser.setLanguage(JavaScript);

Expand Down
8 changes: 1 addition & 7 deletions src/client/domain-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ MD*/
import tinycolor from 'src/external/tinycolor.js';


// #Copy from /src/components/tools/lively-ast-treesitter-inspector.js
// #TODO extract... ?
await lively.loadJavaScriptThroughDOM("treeSitter", lively4url + "/src/external/tree-sitter/tree-sitter.js")
const Parser = window.TreeSitter;
await Parser.init()
const JavaScript = await Parser.Language.load(lively4url + "/src/external/tree-sitter/tree-sitter-javascript.wasm");

import {Parser, JavaScript} from "src/client/tree-sitter.js"

import {loc} from "utils"

Expand Down
13 changes: 13 additions & 0 deletions src/client/tree-sitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// #Copy from /src/components/tools/lively-ast-treesitter-inspector.js
// #TODO extract... ?
await lively.loadJavaScriptThroughDOM("treeSitter", lively4url + "/src/external/tree-sitter/tree-sitter.js")

export const Parser = window.TreeSitter;

await Parser.init()
export const JavaScript = await Parser.Language.load(lively4url + "/src/external/tree-sitter/tree-sitter-javascript.wasm");




7 changes: 1 addition & 6 deletions src/components/tools/lively-ast-domain-object-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import AstInspector from "./lively-ast-inspector.js"

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

await lively.loadJavaScriptThroughDOM("treeSitter", lively4url + "/src/external/tree-sitter/tree-sitter.js")

const Parser = window.TreeSitter;
await Parser.init()

const JavaScript = await Parser.Language.load(lively4url + "/src/external/tree-sitter/tree-sitter-javascript.wasm");

import {Parser, JavaScript} from "src/client/tree-sitter.js"

import LivelyCodeMirrorCodeProvider from 'src/components/widgets/lively-code-mirror-code-provider.js';

Expand Down
2 changes: 2 additions & 0 deletions src/components/tools/lively-ast-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export default class AstInspector extends Morph {
}

setViewState(state) {
if (!state) return
return this.applyViewState(this.container.childNodes[0], state)
}

Expand All @@ -493,6 +494,7 @@ export default class AstInspector extends Morph {
}

captureViewState(node) {
if (!node) return
const result = {
pattern: node.pattern,
children: [],
Expand Down
8 changes: 1 addition & 7 deletions src/components/tools/lively-ast-treesitter-inspector.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import AstInspector from "./lively-ast-inspector.js"

await lively.loadJavaScriptThroughDOM("treeSitter", lively4url + "/src/external/tree-sitter/tree-sitter.js")

const Parser = window.TreeSitter;
await Parser.init()

const JavaScript = await Parser.Language.load(lively4url + "/src/external/tree-sitter/tree-sitter-javascript.wasm");

import {Parser, JavaScript} from "src/client/tree-sitter.js"

import LivelyCodeMirrorCodeProvider from 'src/components/widgets/lively-code-mirror-code-provider.js';

Expand Down

0 comments on commit 0d20467

Please sign in to comment.