Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add simple send line with prefix in pipe #1614

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/Components/Fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open global.Node

open DTO
open Ionide.VSCode.Helpers
open System.Text.RegularExpressions
module node = Node.Api

module Fsi =
Expand Down Expand Up @@ -367,16 +368,46 @@ module Fsi =
window.showErrorMessage("Failed to send text to FSI", null) |> ignore
)

let (|IsPipe|_|) v =
if Regex(@"(^(\s+)?)\|>").IsMatch(v) then
Some v
else
None

let (|IsComment|_|) v =
if Regex(@"(^(\s+)?)\/\/").IsMatch(v) then
Some v
else
None

let rec private getStartPipe (numberLine: float) (result: string list) =
let editor = window.activeTextEditor.Value
let isEmpty = (editor.document.lineAt numberLine).isEmptyOrWhitespace

match (editor.document.lineAt numberLine).text with
| IsPipe v -> getStartPipe (numberLine - 1.0) ($"it {v}" :: result)
| IsComment v -> getStartPipe (numberLine - 1.0) (v :: result)
| _ when isEmpty -> getStartPipe (numberLine - 1.0) result
| v -> v :: result

let private sendLine () =
let editor = window.activeTextEditor.Value
let _ = editor.document.fileName
let pos = editor.selection.start
let line = editor.document.lineAt pos

let lines =
match line.text with
| IsPipe _ -> getStartPipe (pos.line) []
| v -> [v]

sendCd (Some editor)
send line.text
|> Promise.onSuccess (fun _ -> commands.executeCommand("cursorDown", null) |> ignore)
|> Promise.suppress // prevent unhandled promise exception
|> ignore
lines
|> List.iter (fun l ->
send l
|> Promise.onSuccess (fun _ -> commands.executeCommand("cursorDown", null) |> ignore)
|> Promise.suppress // prevent unhandled promise exception
|> ignore)

let private sendSelection () =
let editor = window.activeTextEditor.Value
Expand Down