Skip to content

Commit

Permalink
udap: Added runInTerminal features
Browse files Browse the repository at this point in the history
  • Loading branch information
austin-barr authored and mstreeter10 committed Jan 6, 2024
1 parent b985fb2 commit ac74c42
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 228 deletions.
11 changes: 5 additions & 6 deletions uni/ulsp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ OBJ=launch-lsp.u workspace.u database.u server.u completion.u signature.u hover.

export IPATH=$(UNI)/unidoc

.PHONY: all
.PHONY: all udap

all:udap mulsp

mulsp: $(prog)
all:udap $(prog)

$(prog): $(OBJ)
$(UC) $(DASHG) -o $(prog) $(OBJ)
Expand All @@ -33,6 +31,7 @@ zip:

clean:
$(RM) -f *.u $(prog) uniclass*
cd udap; $(MAKE) clean

udap: $(prog)
cd udap; $(MAKE)
udap:
cd udap; $(MAKE)
8 changes: 7 additions & 1 deletion uni/ulsp/udap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ prog=udap
SRC=launch-dap.icn server.icn communicator.icn
OBJ=launch-dap.u server.u communicator.u

export IPATH=$(UNI)/unidoc
.PHONY:all progcom

all:progcom $(prog)

$(prog): $(OBJ)
$(UC) $(DASHG) -o $(prog) $(OBJ)
Expand All @@ -18,6 +20,10 @@ launch-dap.u:launch-dap.icn server.u
server.u:server.icn communicator.u
communicator.u:communicator.icn

progcom:progcom.icn
$(UC) $(DASHG) -o progcom progcom.icn
$(CP) progcom$(EXE) ../../../bin

zip:
zip udap.zip Makefile *.icn

Expand Down
167 changes: 50 additions & 117 deletions uni/ulsp/udap/communicator.icn
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,36 @@ package udap
link findre
import json

class Communicator(udb, udbSock, progSock, filePath)
class Communicator(udb, udbSock, progSock, filePath, debuggerActive)

method start_debugger(port)
local udbPath, dir, result

udbPath := find_debugger()
if /udbPath then return "udap could not find udb"
if debuggerActive == "n" then {
udbPath := find_debugger()
if /udbPath then return "udap could not find udb"

if udb := open(udbPath || " -adapter " || port, "pw") then {
result := connect_udbsock(port)
if result != "success" then {
return result
}
result := connect_progsock(port + 10)
if result != "success" then {
return result
}
} else return "udap could not start udb"
if udb := open(udbPath || " -adapter " || port, "pw") then debuggerActive := "y"
else return "udap could not start udb"
}

result := connect_udbsock(port)
if result ~== "success" then {
return result
}

return "success"
end

method end_debugger()
close(udb)
debuggerActive := "n"
end

method find_debugger()
return pathfind("udb")
end

method progress(cmd)
local udbRes, udbResTable, udbResList, progRes, progResTable

if /cmd then cmd := "run"
udbRes := ""
udbResList := list()
progRes := ""

write(udbSock, cmd)

#in json
udbRes := udb_output()
#raw output
progRes := prog_output()

if progRes ~== "" then {
progResTable := table("type", "stdout", "consoleMsg", progRes)
}

if udbRes ~== "" then {
every udbResTable := jtou(udbRes) do {
put(udbResList, udbResTable)
if member(udbResTable, "type") then {
if udbResTable["type"] == "stderr" | udbResTable["type"] == "exited" | udbResTable["type"] == "breakpoint" | udbResTable["type"] == "step" then {
if progRes ~== "" then suspend progResTable
return udbResTable
}
}
}
}

if \progResTable then return progResTable
end

method stackTrace()
local udbRes, udbResTable, udbResList

Expand All @@ -82,6 +48,8 @@ class Communicator(udb, udbSock, progSock, filePath)
every udbResTable := jtou(udbRes) do {
if member(udbResTable, "type") then {
if udbResTable["type"] == "frame" then {
udbResTable["name"] := replace(udbResTable["name"], "\"", "\\\"")
udbResTable["consoleMsg"] := replace(udbResTable["consoleMsg"], "\"", "\\\"")
put(udbResList, udbResTable)
}
}
Expand All @@ -100,6 +68,8 @@ class Communicator(udb, udbSock, progSock, filePath)
write(udbSock, "frame " || frame)
write(udbSock, "print -g")
write(udbSock, "print -l")
write(udbSock, "print -s")
write(udbSock, "print -p")

#in json
udbRes := udb_output()
Expand All @@ -113,6 +83,12 @@ class Communicator(udb, udbSock, progSock, filePath)
if udbResTable["type"] == "locals" & *udbResTable["variables"] > 0 then {
put(scopes, table("name", "Locals", "variablesReference", 2))
}
if udbResTable["type"] == "statics" & *udbResTable["variables"] > 0 then {
put(scopes, table("name", "Statics", "variablesReference", 3))
}
if udbResTable["type"] == "params" & *udbResTable["variables"] > 0 then {
put(scopes, table("name", "Parameters", "variablesReference", 4))
}
}
}
}
Expand All @@ -128,14 +104,16 @@ class Communicator(udb, udbSock, progSock, filePath)

if variablesReference = 1 then write(udbSock, "print -g")
if variablesReference = 2 then write(udbSock, "print -l")
if variablesReference = 3 then write(udbSock, "print -s")
if variablesReference = 4 then write(udbSock, "print -p")

#in json
udbRes := udb_output()

if udbRes ~== "" then {
every udbResTable := jtou(udbRes) do {
if member(udbResTable, "type") & member(udbResTable, "variables") then {
if udbResTable["type"] == "globals" | udbResTable["type"] == "locals" then {
if udbResTable["type"] == "globals" | udbResTable["type"] == "locals" | udbResTable["type"] == "statics" | udbResTable["type"] == "params" then {
variables := udbResTable["variables"]
}
}
Expand All @@ -151,23 +129,22 @@ class Communicator(udb, udbSock, progSock, filePath)
return variables
end

method load_prog()
method load_cmds()
local dir

filePath ? dir := tab(findre("\/[^\/]+$"))
write(udbSock, "dir args " || dir)
write(udbSock, "load " || filePath)
write(ximage(jtou(udb_output())))
suspend "dir args " || dir
suspend "load " || filePath
end

method set_filepath(fpath)
filePath := fpath
end

method connect_udbsock(port)
if /port then {
return "udb communication port not declared"
}
if /port then return "udb communication port not declared"

if \udbSock then return "success"

every 1 to 5 do {
if udbSock := open(":" || port, "n") then {
Expand All @@ -181,29 +158,9 @@ class Communicator(udb, udbSock, progSock, filePath)
return "udap failed to connect to udb on port: " || port
end

method connect_progsock(port)
if /port then {
return "prog communication port not declared"
}

every 1 to 5 do {
if progSock := open(":" || port, "n") then {
return "success"
}
else {
delay(1000)
}
}

return "udap failed to connect to prog on port: " || port
end

method disconnect_udbsock()
close(udbSock)
end

method disconnect_progsock()
close(progSock)
udbSock := &null
end

method udb_output()
Expand All @@ -216,65 +173,41 @@ class Communicator(udb, udbSock, progSock, filePath)
return msg
end

method prog_output()
local msg

msg := ""
while *select(progSock, 200) > 0 do {
msg ||:= ready(progSock)
}
return msg
end

method udb_input(exp)
local udbRes := "", progRes, udbResTable
local udbRes := "", resultTable

write(udbSock, exp)

udbRes := udb_output()
progRes := replace(prog_output(), "\"", "\\\"")

if \udbRes ~== "" then {
every udbResTable := jtou(udbRes) do {
write(ximage(udbResTable))
}
if udbRes ~== "" then {
every resultTable := jtou(udbRes) do suspend resultTable
}

return progRes
end

method prog_input(exp)
local udbRes := "", progRes, udbResTable

write(progSock, exp)

progRes := replace(prog_output(), "\"", "\\\"")
udbRes := udb_output()

if \udbRes ~== "" then {
every udbResTable := jtou(udbRes) do {
write(ximage(udbResTable))
}
}

return progRes
method get_communication_source()
if \udbSock then return udbSock
end

method set_breakpoints(breakpoints)
local bp, line, cond, resultTable
method set_breakpoints(arguments)
local breakpoints, bp, line, cond, res, resultTable

write(udbSock, "clear break")
udb_output()

breakpoints := arguments["breakpoints"]
if *breakpoints = 0 then fail

every bp := 1 to *breakpoints do {
line := breakpoints[bp]["line"]
cond := \breakpoints[bp]["condition"]

write(udbSock, "b "|| line)
resultTable := jtou(udb_output())

breakpoints[bp]["verified"] := resultTable["success"]
write(udbSock, "b " || arguments["source"]["name"] || ":" || line)
res := udb_output()

if res ~== "" & resultTable := jtou(res) then breakpoints[bp]["verified"] := resultTable["success"]
else breakpoints[bp]["verified"] := "__false__"
}
end

initially
debuggerActive := "n"
end
Binary file added uni/ulsp/udap/progcom
Binary file not shown.
13 changes: 13 additions & 0 deletions uni/ulsp/udap/progcom.icn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
procedure main(argv)
port := pop(argv)
sock := open(":" || port, "n")

repeat {
if *select(sock, 50) > 0 then {
writes(ready(sock))
}
if *select(&input, 50) > 0 then {
writes(sock, ready())
}
}
end
Loading

0 comments on commit ac74c42

Please sign in to comment.