瀏覽代碼

feat: added txt2gam QSP builder

gretmn102 3 年之前
父節點
當前提交
a89204f7f2
共有 4 個文件被更改,包括 55 次插入38 次删除
  1. 1 1
      .gitignore
  2. 二進制
      3rd/txt2gam.exe
  3. 39 3
      QspServer/Program.fs
  4. 15 34
      build.fsx

+ 1 - 1
.gitignore

@@ -10,7 +10,7 @@ obj
 bin
 *.exe
 !/.paket/paket.bootstrapper.exe
-
+!3rd/txt2gam.exe
 
 ### Linux ###
 *~

二進制
3rd/txt2gam.exe


+ 39 - 3
QspServer/Program.fs

@@ -37,6 +37,7 @@ module Position =
             End = { Line = int r.Line - 1
                     Character = int r.Column2 - 1 }
         }
+type UriString = string
 type SourceFilePath = string
 type HighlightingRequest = { FileName: string }
 type Serializer = obj -> string
@@ -86,7 +87,21 @@ module CommandResponse =
                   |> Array.map (fun (struct ((pos:Qsp.Tokens.InlineRange), tk)) ->
                       { Range = toVscodeRange2 pos; TokenType = map tk }) }
         }
-
+let txt2qspPath = @"3rd\txt2gam.exe"
+let buildQsp src =
+    let dst = System.IO.Path.ChangeExtension(src, ".qsp")
+    let args = sprintf "%s %s" src dst
+
+    let startProcString path args =
+        let drivenOutput = new System.Text.StringBuilder()
+        Proc.startProc (fun e ->
+            drivenOutput.AppendLine(e) |> ignore
+        ) path args
+        |> fun code -> code, drivenOutput.ToString()
+    Proc.startProcString txt2qspPath args
+let buildQspTest () =
+    let src = @"E:\Project\Qsp\QspSyntax\sample-code\Sandbox.qsps"
+    buildQsp src
 
 type Commands() =
     member x.GetHighlighting documentText = // (file: SourceFilePath) =
@@ -805,7 +820,28 @@ type BackgroundServiceServer(state: State, client: FsacClient) =
     //         }
     //     return LspResult.success None
     // }
-    // АрбузДыняДыраБородаБор ода
+    member __.BuildSource (uriStr:UriString) =
+        async {
+            // let uri = "file:///e:/Project/Qsp/QSP-LSP/3rd/txt2gam.exe"
+            let uri =
+                try
+                    let uri = System.Uri uriStr
+                    uri.LocalPath
+                    |> Right
+                with e ->
+                    Left e.Message
+            let res =
+                match uri with
+                | Right path ->
+                    try
+                        buildQsp path |> ignore
+                        Choice2Of2 "Ok"
+                    with e ->
+                        Choice1Of2 e.Message
+                | Left err ->
+                    Choice1Of2 (sprintf "'%s'\n%A" uriStr err)
+            return LspResult.success res
+        }
 
     override __.Initialize p =
         async {
@@ -871,7 +907,7 @@ let main argv =
         defaultRequestHandlings<BackgroundServiceServer>()
         |> Map.add "fsharp/highlighting" (requestHandling (fun s p -> s.GetHighlighting(p) ))
         |> Map.add "fsharp/workspaceLoad" (requestHandling (fun s p -> s.FSharpWorkspaceLoad(p) ))
-        // |> Map.add "fsharp/workspacePeek" (requestHandling (fun s p -> s.FSharpWorkspacePeek(p) ))
+        |> Map.add "qsp/build" (requestHandling (fun s p -> s.BuildSource(p) ))
 
     Server.start requestsHandlings input output FsacClient (fun lspClient -> BackgroundServiceServer((), lspClient))
     |> printfn "%A"

+ 15 - 34
build.fsx

@@ -40,6 +40,15 @@ Target.create "BuildTest" (fun _ ->
         |> dtntSmpl)
 )
 
+Target.create "Copy3rd" <| fun _ ->
+    let srcDir = @"3rd"
+    if not <| System.IO.Directory.Exists srcDir then
+        failwithf "'%s' not found" srcDir
+    let localPath = sprintf "bin/%A/net461" buildConf
+    let dstDir = sprintf "%s/%s/%s" mainProjName localPath srcDir
+    // printfn "%s\n%s" srcDir dstDir
+    Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
+
 let run projName projPath =
     let dir = Fake.IO.Path.getDirectory projPath
     let localpath = sprintf "bin/%A/net461/%s.exe" buildConf projName
@@ -77,47 +86,19 @@ Target.create "TrimTrailingWhitespace" (fun _ ->
     )
 )
 
-open Fake.IO
-// TODO: скачать и распаковать http://qsp.su/attachments/txt2gam011.zip в "Utils\txt2gam"
-let compilerPath =
-    Lazy.Create (fun _ ->
-        let compilerPath = "Utils/txt2gam/txt2gam.exe"
-        if System.IO.File.Exists compilerPath then compilerPath
-        else
-            failwithf "Compiler not found at '%A'" compilerPath
-    )
-let compiler src =
-    let dst = Path.changeExtension ".qsp" src
-
-    Command.RawCommand(compilerPath.Value, Arguments.ofList [src; dst])
-    |> CreateProcess.fromCommand
-    |> CreateProcess.withWorkingDirectory (Path.getDirectory compilerPath.Value)
-    |> Proc.run
-    |> fun x -> x.ExitCode
-
-Target.create "Watch" (fun _ ->
-    use watcher =
-       !! "Utils/txt2gam/*.qsps"
-       |> Fake.IO.ChangeWatcher.run (fun changes ->
-           changes
-           |> Seq.iter (fun x ->
-               Trace.trace "Compilation..."
-               let code = compiler x.FullPath
-               Trace.trace (sprintf "Compilation completed with code %d" code)
-           )
-    )
-
-    System.Console.ReadLine() |> ignore
-
-    watcher.Dispose() // по-идеи, и так должен выгрузиться
+Target.create "CopyToMainProj" (fun _ ->
+    let srcDir = @"QspServer\bin\Debug\net461"
+    let dstDir = @"e:\Project\Qsp\QspVscodeExtension\release\bin"
+    Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
 )
 
-
 // --------------------------------------------------------------------------------------
 // Build order
 // --------------------------------------------------------------------------------------
 open Fake.Core.TargetOperators
 
 "BuildTest"
+  ==> "Copy3rd"
+//   ==> "CopyToMainProj"
   ==> "RunTest"
 Target.runOrDefault "RunTest"