Skip to content

Commit

Permalink
Merge pull request #479 from Jafaral/ulsp-crash-res
Browse files Browse the repository at this point in the history
Fix crash in ulsp, additional logging and cleanup
  • Loading branch information
Don-Ward authored Sep 18, 2024
2 parents 0105ad9 + f77285b commit 776266e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"**/*.so": true,
"**/*.o": true,
"**/*.u": true,
"**/*.exe": true,
"**/*.tmp": true,
"config.status": true,
"**/uniclass.*": true,
Expand Down
2 changes: 1 addition & 1 deletion Makedefs.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ OSREL=@unicon_osrel@
SHELL = /bin/sh
RTT=../../bin/urtt
RM = rm -f
CP = cp
CP = cp -f
AR = ar
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
Expand Down
2 changes: 1 addition & 1 deletion Makedefs.uni.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BIN=$(BASE)/bin
RM=rm -f
RMDIR=rm -rf
MKDIR=mkdir
CP=cp
CP=cp -f
TOUCH=touch
ARC=zip
ARCEXT=zip
Expand Down
3 changes: 1 addition & 2 deletions uni/ulsp/launch-lsp.icn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ procedure main(args)
# If validate_args() fails, it will display usage() and never return.
opts := validate_args(args)

Logger(opts["-loglevel"] | 7, opts["-logfile"] | &null) # # default to informational, stdout
Logger((opts["-loglevel"]), opts["-logfile"]) # # default to informational, stdout

if \opts["-debug-class"] then
Logger.add_debug_class(opts["-debug-class"])
Expand All @@ -74,7 +74,6 @@ procedure main(args)
# Set mode for server to run in, based on opts.
member(opts, mode := "c") | (mode := "s")


ulsp_server := Server(sock, mode)
ulsp_server.run()
end
55 changes: 34 additions & 21 deletions uni/ulsp/server.icn
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Logger(
# private
method _log(loglvl, msgs)
local msg
clock := &date || " " || &clock
if loglvl <= current_log_level then {
clock := &date || " " || &clock
msg := ""; every msg ||:=!msgs
self._log_to_file(msg, loglvl)
self._log_std(msg, loglvl)
Expand All @@ -60,9 +60,10 @@ class Logger(
# }
# }

clock := &date || " " || &clock
if loglvl <= current_log_level |
(loglvl >= 8 & member(debug_class_set, filter)) then {
if current_log_level < 8 then fail

if loglvl <= current_log_level | member(debug_class_set, filter) then {
clock := &date || " " || &clock
msg := ""; every msg ||:=!msgs
self._log_to_file(msg, loglvl, filter)
self._log_std(msg, loglvl, filter)
Expand Down Expand Up @@ -285,7 +286,7 @@ class Logger(
enable_timestamp := "file"
enable_loginfo := "all"
debug_class_set := set("")
current_log_level := \init_log_level | 5
current_log_level := \init_log_level | 7
log_destinations := []
if \log_file_path then
if f := open(log_file_path, "a") then
Expand Down Expand Up @@ -317,11 +318,13 @@ class Server(
request_params := jsontable["params"]
request_id := jsontable["id"]

write("-----------------------------------------")
write(request_method)
write("-----------------------------------------")
Logger.debug2_class("lsp:jrpc:request", "-----------------------------------------")
Logger.debug2_class("lsp:jrpc:request", request_method)
Logger.debug2_class("lsp:jrpc:request", "-----------------------------------------")
Logger.debug5_class("lsp:jrpc:request:", image(request_body) )

case request_method of {
# requests
"initialize" : initialize(request_id)
"textDocument/didOpen" : didOpen(request_params)
"textDocument/didClose" : didClose(request_params)
Expand All @@ -330,8 +333,15 @@ class Server(
"textDocument/signatureHelp" : signatureHelp(request_id, request_params)
"textDocument/hover" : hoverHelp(request_id, request_params)
"textDocument/definition" : definitionHelp(request_id, request_params)

# notifications
"initialized" : Logger.debug2_class("lsp:jrpc:notification:", image(request_body))

# utils?
"$/cancelRequest" : cancelRequest(request_id)
default: { write("Don't know what to do with: ", request_method) }
default: {
Logger.debug1_class("lsp:jrpc", "Unsupported request: ", image(request_method), ">>", image(request_body))
}
}
}
}
Expand Down Expand Up @@ -379,6 +389,7 @@ class Server(

method build_response(id, results)
local responseBody, responseHeader
/results := "{}"
responseBody := "{\"jsonrpc\":\"2.0\",\"id\":"||id||",\"result\":"||results||"}"
responseHeader := "Content-Length:" || *responseBody || "\r\n\r\n"
return responseHeader || responseBody
Expand All @@ -404,18 +415,20 @@ class Server(
method initialize(request_id)
local capabilitiesTable, result

capabilitiesTable := ["capabilities": [
"completionProvider": [
"triggerCharacters": [".", ":"]
];
"textDocumentSync": 1;
"signatureHelpProvider": [
"contextSupport": "__true__";
"triggerCharacters": ["("]
];
"hoverProvider": "__true__";
"definitionProvider": "__true__"
]]
capabilitiesTable := [
"capabilities": [
"completionProvider": [
"triggerCharacters": [".", ":"]
];
"textDocumentSync": 1;
"signatureHelpProvider": [
"contextSupport": "__true__";
"triggerCharacters": ["("]
];
"hoverProvider": "__true__";
"definitionProvider": "__true__"
]
]

result := build_response(request_id, tojson(capabilitiesTable))
write(result)
Expand Down

0 comments on commit 776266e

Please sign in to comment.