Skip to content

Commit

Permalink
Merge pull request #477 from Jafaral/ulsp-log
Browse files Browse the repository at this point in the history
ulsp: add a logger class
  • Loading branch information
Don-Ward authored Sep 17, 2024
2 parents bac7c90 + 91e2ea2 commit 6e291aa
Show file tree
Hide file tree
Showing 3 changed files with 318 additions and 11 deletions.
13 changes: 9 additions & 4 deletions uni/ulsp/database.icn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import UniDoc

link paths

global Logger

class LSPDB(
package_db,
built_in_functions, # List containing all native function names
Expand Down Expand Up @@ -108,10 +110,11 @@ class LSPDB(
if \unicon_dir then
put(db_paths, unicon_dir || "ipl/procs", unicon_dir || "uni/unidoc")

write("Looking in:")
every write(" ", !db_paths)

every build_by_path(!db_paths)
Logger.debug1_class("db", "Looking in unicon paths")
every dir := !db_paths do {
Logger.debug2_class("db:path", "Processing ", dir)
build_by_path(dir)
}
end

method build_by_path(path)
Expand All @@ -126,13 +129,15 @@ class LSPDB(
x := idoc.packages

every pack := !x do {
Logger.debug3_class("db:path:package", "Processing ", pack.getName())

if /package_db[pack.getName()] then {
package_db[pack.getName()] := table()
package_db[pack.getName()]["files"] := table()
}

every file_in_pack := pack.getFiles().get() do {
Logger.debug4_class("db:path:package:file", "Processing ", file_in_pack.getName())
file_without_ext := &null
file_in_pack.getName() ? {
file_without_ext := tab(upto("."))
Expand Down
27 changes: 25 additions & 2 deletions uni/ulsp/launch-lsp.icn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ link options
link basename
link ximage

global ulsp_server

procedure usage()
local prog
prog := basename(&progname)
Expand All @@ -23,24 +25,43 @@ procedure usage()
write("\t --socket <PORT> : set the lsp server port")
write("\t -s : run as a server (default)")
write("\t -c : run as a client")
write("\t --logfile <filename> : log file")
write("\t --loglevel <level> : log level from 0-17. log levels 8-17 are used for debugging")
write("\t --debug-class <class>: debug class to log")
write("\t -h : show this help\n")
exit(-1)
end

procedure validate_args(args)
local opts
opts := options(args, "--socket+ -h! -c! -s!", usage)
opts := options(args, "--socket+ --logfile: --loglevel+ --debug-class: -h! -c! -s!", usage)
if *opts = 0 then usage()
member(opts, "-socket") | usage()
return opts
end

procedure ulsp_sig_handler(siganl)
Logger.notice("\nshutdown signal received! Server Shutting down...")
if \ulsp_server then
ulsp_server.shutdown()

Logger.finalize()
exit(0)
end

procedure main(args)
local opts, sock, mode

trap("SIGINT", ulsp_sig_handler)

# 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

if \opts["-debug-class"] then
Logger.add_debug_class(opts["-debug-class"])

# Allow passing full host:port as an arg
sock := opts["-socket"]
if &features == ("MacOS" | "MS Windows NT") then {
Expand All @@ -53,5 +74,7 @@ procedure main(args)
# Set mode for server to run in, based on opts.
member(opts, mode := "c") | (mode := "s")

Server(sock, mode).run()

ulsp_server := Server(sock, mode)
ulsp_server.run()
end
Loading

0 comments on commit 6e291aa

Please sign in to comment.