show comments from ktxt2

This commit is contained in:
2021-10-21 13:43:07 -04:00
parent db01de062e
commit 254e3d91b8
6 changed files with 65 additions and 24 deletions

View File

@@ -1,3 +1,4 @@
Stuff outside the thing is a comment
|||Title: The First Fountain->Hollywoo Script
Credit: written by
Author: Nat Quayle Nelson (she/her)
@@ -9,5 +10,7 @@ Contact: natquaylenelson@gmail.com
|>||||
|||INT. CABIN - SAME
|>||||
comment
|||NAT NELSON (23, femme) sits by a tall window, typing on a laptop.
|>||||
|>||||
Stuf at the end is a different ocmment

View File

@@ -11,6 +11,8 @@
-debug
--main Main
--next
-lib kiss
-lib kiss-vscode
-cp src
-js bin/ktxt2editor.js
--main ktxt2.KTxt2Editor

View File

@@ -10,9 +10,8 @@
(var outputStarts [unlockedStart lockedStart])
// Return [sourceFile outputFile]
(function :Array<String> splitFileContents [file]
(let [fileStream (kiss.Stream.fromFile file)
&mut sourceText ""
(function :Array<String> splitFileContents [:Stream fileStream]
(let [&mut sourceText ""
&mut outputText ""]
(loop
(case (fileStream.takeUntilAndDrop blockStartEnd)
@@ -29,9 +28,8 @@
(break))))
[sourceText outputText]))
(function :Array<KTxt2Element> splitFileElements [file]
(let [fileStream (kiss.Stream.fromFile file)
elements []]
(function :Array<KTxt2Element> splitFileElements [:Stream fileStream]
(let [elements []]
(loop
(let [block
(object
@@ -43,11 +41,12 @@
outputEnd null
outputLocked false)]
// Look for the start of a KTxt2 block
(case (fileStream.takeUntilAndDrop blockStartEnd)
(case (fileStream.takeUntilAndDrop blockStartEnd true)
((Some comment)
// Anything before the start of the block is a comment
(when comment
(elements.push (Comment comment)))
(when (fileStream.isEmpty) (break))
(let [sourceStartPosition (fileStream.position)
sourceBlock (fileStream.expect "A chunk of source text followed by one of $outputStarts"
->(fileStream.takeUntilOneOf outputStarts))

View File

@@ -1,13 +1,11 @@
package ktxt2;
@:build(kiss.Kiss.build())
class KTxt2Editor {
public static function main() {
var vscode = EditorExterns.acquireVsCodeApi();
import js.html.Document;
import js.html.Window;
import ktxt2.EditorExterns;
import ktxt2.KTxt2;
import kiss.Prelude;
import kiss.Stream;
var document = EditorExterns.window.document;
var pElement = document.createElement("p");
pElement.innerHTML = "helly eah";
document.body.appendChild(pElement);
}
}
@:build(kiss.Kiss.build())
class KTxt2Editor {}

View File

@@ -1,4 +1,35 @@
(function exportSourceAndOutputFiles [document]
(var &mut :VSCodeAPI vscode)
(var &mut :Window window)
(var &mut :Document document)
(var &mut :Array<KTxt2Element> ktxt2Elements)
(function main []
(set vscode (EditorExterns.acquireVsCodeApi))
(set window EditorExterns.window)
(set document window.document)
(window.addEventListener "message"
->:Void event
(case event.data.type
("update"
(updateContent event.data.text))
(otherType (throw "bad message type $otherType for KTxt2Editor")))))
(function pElement [text]
(let [p (document.createElement "p")]
(set p.innerHTML text)
(document.body.appendChild p)))
(function :Void updateContent [text]
(set document.body.innerHTML "")
(doFor [idx element] (enumerate (KTxt2.splitFileElements (Stream.fromString text)))
(case element
((Comment comment)
(pElement comment))
((Block block)
0))))
/*(function exportSourceAndOutputFiles [document]
(let [[sourceText outputText] (splitFileContents document.fileName)
ktxt2FullFilename document.fileName
ktxt2Directory (haxe.io.Path.directory ktxt2FullFilename)
@@ -39,7 +70,6 @@
(function rangeFromStartEnd [start end]
(new Range (streamPosToVscodePos start) (streamPosToVscodePos end)))
(function splitBlocks [&opt _]
(let [blocks (splitFileBlocks)] (print blocks)))
(let [blocks (splitFileBlocks)] (print blocks)))
*/

View File

@@ -1,3 +1,5 @@
// Based on https://github.com/microsoft/vscode-extension-samples/blob/main/custom-editor-sample/src/catScratchEditor.ts
(function register [context]
(let [provider (new KTxt2EditorProvider context)]
(Vscode.window.registerCustomEditorProvider "ktxt2.splitView" provider)))
@@ -7,8 +9,15 @@
(method :Promise<Void> resolveCustomTextEditor [:TextDocument document :WebviewPanel webviewPanel :CancellationToken _token]
(set webviewPanel.webview.options (object enableScripts true))
(set webviewPanel.webview.html (htmlForWebview webviewPanel.webview))
null
)
(let [updateWebview
->(webviewPanel.webview.postMessage (object type "update" text (document.getText)))
changeDocumentSubscription
(Vscode.workspace.onDidChangeTextDocument
->e (when (= (e.document.uri.toString) (document.uri.toString))
(updateWebview)))]
(webviewPanel.onDidDispose ->e (changeDocumentSubscription.dispose))
(updateWebview))
null)
(method :String htmlForWebview [:Webview webview]
(let [scriptUri