util functions for index<->position in active document

This commit is contained in:
2023-08-27 15:06:22 -06:00
parent 092397d55e
commit e760fdb912

View File

@@ -381,4 +381,21 @@
(function :Void awaitLetCatchThroughErrorMessage []
(set Prelude.makeAwaitLetDefaultCatch
->binding
->reason (errorMessage "awaitLet $binding failed: $reason")))
->reason (errorMessage "awaitLet $binding failed: $reason")))
(function :vscode.Position toPosition [:Int index]
(activeTextEditor.document.positionAt index))
(function toIndex [:vscode.Position position]
(activeTextEditor.document.offsetAt position))
(defAlias &call toOffset toIndex)
(function toSelection [:Int anchorIdx :Int activeIdx]
(new vscode.Selection (toPosition anchorIdx) (toPosition activeIdx)))
(function docIndexOf [:String what &opt :Int startingIndex]
(.indexOf (activeTextEditor.document.getText) what startingIndex))
(function docLastIndexOf [:String what &opt :Int startingIndex]
(.lastIndexOf (activeTextEditor.document.getText) what startingIndex))