Created
January 6, 2020 22:49
-
-
Save GWRon/b48683adb7cd83be7633484a22773803 to your computer and use it in GitHub Desktop.
server_standardio.bmx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SuperStrict | |
Framework BRL.StandardIO | |
Import BRL.SystemDefault | |
Import BRL.System | |
Import BRL.Stream | |
Import BRL.Retro | |
Import BRL.Blitz | |
Local args:String | |
Local port:Int | |
For Local s:String = EachIn AppArgs | |
args:+ s + "~n" | |
Next | |
SaveString(args, "ARGS_OUTPUT.txt") | |
LogAndVSPrint("Connected to server_standardio to VSCode!" ) | |
Local contentLength:Int | |
Local message:String | |
Global logging:string | |
Local start:int = Millisecs() | |
LogAndVSPrint("Calling ReadStdIn()~n") | |
Local readIn:String = ReadStdIn() | |
LogAndVSPrint("Initial ReadIn: ~q" + readIn + "~q~n") | |
While readIn <> "" or Millisecs() - start < 500 | |
contentLength = 0 | |
message = null | |
LogAndVSPrint("Waiting for readin: ~q" + readIn + "~q~n") | |
' Await content length | |
While contentLength <= 0 | |
LogAndVSPrint( "Await content length ... readin: ~q" + readIn+"~q~n" ) | |
message :+ readIn | |
readIn = :+ ReadStdIn() | |
'stdin of BMX does not contain "~r~n" or so, contains "full line" | |
'already | |
If message.StartsWith( "Content-Length: " ) | |
contentLength = int(Right(message, message.Length - 16)) | |
EndIf | |
Wend | |
' Await known data | |
LogAndVSPrint("Awaiting " + contentLength +" data~n") | |
message = null | |
While message.Length < contentLength | |
message :+ ReadStdIn() | |
LogAndVSPrint("Reading ... message=~q" + message +"~q message.length="+message.Length +" contentLength="+contentLength+"~n") | |
Wend | |
LogAndVSPrint("Final message ... message=~q" + message + "~q~n") | |
' Use data | |
OnMessage( message ) | |
Wend | |
Function OnMessage( msg:String ) | |
VSPrint( "GOT: " + msg.Replace("~n","/n").Replace("~r","/r") ) | |
' Oh this is just an awful way of handling this! | |
If msg.Contains( "~qmethod~q:~qinitialize~q" ) | |
VSPrint( "Okay, so here's the thing" ) | |
VSPrint( "No matter what I answer the client here..." ) | |
VSPrint( "It just crashes on ~qCan't read property textDocumentSync~q" ) | |
SendMessage( "{~qjsonrpc~q:~q2.0~q,~qid~q:0,~qresult~q:~qinitialize~q,~qparams~q:{~qcapabilities~q:{~qtextDocumentSync~q:0,~qcompletionProvider~q:{~qresolveProvider~q:true,~qtriggerCharacters~q:[~q/~q]},~qhoverProvider~q:true,~qdocumentSymbolProvider~q:true,~qreferencesProvider~q:true,~qdefinitionProvider~q:true,~qdocumentHighlightProvider~q:true,~qcodeActionProvider~q:true,~qrenameProvider~q:true,~qcolorProvider~q:{},~qfoldingRangeProvider~q:true}}}" ) | |
EndIf | |
If msg.Contains( "~qerror~q:{~q" ) VSPrint("Okay... VSCode did NOT like that!") | |
EndFunction | |
Function SendMessage( msg:String ) | |
VSPrint( "SND: " + msg.Replace("~n","/n").Replace("~r","/r") ) | |
Local cLen:String = "Content-Length: " + msg.Length + "~r~n~r~n" | |
logging :+ "==== SendMessage~n" | |
logging :+ cLen + " ~n" | |
logging :+ msg + "~n" | |
logging :+ "====~n" | |
SaveString(logging, "LOG.txt") | |
WriteStdOut( cLen + "~n") | |
WriteStdOut( msg + "~n") | |
EndFunction | |
Function VSPrint( text:String ) | |
WriteStdErr( text + "~r~n" ) | |
EndFunction | |
Function LogAndVSPrint( text:String ) | |
logging :+ "Waiting for readin: ~q" + text+"~q~n" | |
SaveString(logging, "LOG.txt") | |
VSPrint( text ) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment