mirror of
https://github.com/heyman/heynote.git
synced 2024-11-22 07:54:11 +01:00
Add ability to display the Lezer syntax tree for debugging
This commit is contained in:
parent
ddc184fb24
commit
221e42e30a
@ -84,6 +84,7 @@
|
|||||||
@cursorChange="onCursorChange"
|
@cursorChange="onCursorChange"
|
||||||
:theme="theme"
|
:theme="theme"
|
||||||
:development="development"
|
:development="development"
|
||||||
|
:debugSyntaxTree="false"
|
||||||
class="editor"
|
class="editor"
|
||||||
ref="editor"
|
ref="editor"
|
||||||
@openLanguageSelector="openLanguageSelector"
|
@openLanguageSelector="openLanguageSelector"
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
<script>
|
<script>
|
||||||
import { HeynoteEditor } from '../editor/editor.js'
|
import { HeynoteEditor } from '../editor/editor.js'
|
||||||
|
import { syntaxTree } from "@codemirror/language"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: [
|
props: [
|
||||||
"theme",
|
"theme",
|
||||||
"development",
|
"development",
|
||||||
|
"debugSyntaxTree",
|
||||||
],
|
],
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
syntaxTreeDebugContent: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$refs.editor.addEventListener("selectionChange", (e) => {
|
this.$refs.editor.addEventListener("selectionChange", (e) => {
|
||||||
//console.log("selectionChange:", e)
|
//console.log("selectionChange:", e)
|
||||||
@ -35,6 +44,25 @@
|
|||||||
window.heynote.onWindowClose(() => {
|
window.heynote.onWindowClose(() => {
|
||||||
window.heynote.buffer.saveAndQuit(this.editor.getContent())
|
window.heynote.buffer.saveAndQuit(this.editor.getContent())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// if debugSyntaxTree prop is set, display syntax tree for debugging
|
||||||
|
if (this.debugSyntaxTree) {
|
||||||
|
setTimeout(() => {
|
||||||
|
function render(tree) {
|
||||||
|
let lists = ''
|
||||||
|
tree.iterate({
|
||||||
|
enter(type) {
|
||||||
|
lists += `<ul class="testlist"><li>${type.name} (${type.from},${type.to})`
|
||||||
|
},
|
||||||
|
leave() {
|
||||||
|
lists += '</ul>'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return lists
|
||||||
|
}
|
||||||
|
this.syntaxTreeDebugContent = render(syntaxTree(this.editor.view.state))
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
@ -61,12 +89,30 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="editor" ref="editor"></div>
|
<div>
|
||||||
|
<div class="editor" ref="editor"></div>
|
||||||
|
<div
|
||||||
|
v-if="debugSyntaxTree"
|
||||||
|
v-html="syntaxTreeDebugContent"
|
||||||
|
class="debug-syntax-tree"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style lang="sass">
|
||||||
.editor {
|
.debug-syntax-tree
|
||||||
width: 100%;
|
position: absolute
|
||||||
background-color: #f1f1f1;
|
top: 0
|
||||||
}
|
bottom: 0
|
||||||
|
right: 20px
|
||||||
|
width: 50%
|
||||||
|
background-color: #f1f1f1
|
||||||
|
color: #000
|
||||||
|
font-size: 12px
|
||||||
|
font-family: monospace
|
||||||
|
padding: 10px
|
||||||
|
overflow: auto
|
||||||
|
|
||||||
|
ul
|
||||||
|
padding-left: 30px
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user