Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulsp: add run mode (server -s and client -c) #468

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions uni/ulsp/launch-lsp.icn
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,37 @@ procedure usage()
write("Check your IDE for the correct LSP server invocation.")
write("\nOptions:")
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 -h : show this help\n")
exit(-1)
end

procedure validate_args(args)
local opts, port
opts := options(args, "--socket:")
local opts
opts := options(args, "--socket+ -h! -c! -s!", usage)
if *opts = 0 then usage()
port := \opts["-socket"] | usage()
port := opts["-socket"]
return port
member(opts, "-socket") | usage()
return opts
end


procedure main(args)
local port
#write("args: ", ximage(args))
port := validate_args(args) | stop("Error: invalid args/port number.")
local opts, sock, mode

# If validate_args() fails, it will display usage() and never return.
opts := validate_args(args)

# Allow passing full host:port as an arg
if integer(port) then {
if &features == ("MacOS" | "MS Windows NT") then
port := "127.0.0.1:" || port
else
port := ":" || port
sock := opts["-socket"]
if &features == ("MacOS" | "MS Windows NT") then {
sock := "127.0.0.1:" || sock
}
else {
sock := ":" || sock
}

Server(port).run()
end



# Set mode for server to run in, based on opts.
member(opts, mode := "c") | (mode := "s")

Server(sock, mode).run()
end
16 changes: 12 additions & 4 deletions uni/ulsp/server.icn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import json

class Server(
port, # Port number acquired from args on start up of server
mode, # Mode to run in (client | server)
sock, # Socket connection for communication with client
openFiles, # File container for open files
completionHandler, # Instance of CompletionHandler class for handling completion requests
Expand Down Expand Up @@ -282,22 +283,29 @@ class Server(
end

initially
local openopt := "n", mstring := "server"

every 1 to 10 do {
if sock := open(port, "n", 1000) then
case mode of {
"s" : { openopt ||:= "a" }
"c" : { mstring := "client" }
default: { write("Unknown mode: " || mode) }
}

write("Attempting to start ulsp as a " || mstring)
every 1 to 5 do {
if sock := open(port, openopt) then
break
else {
write("open(",port,") ERROR: ", \&errortext | "Unknown")
delay(1000)
}
}

if /sock then stop("failed to connect to ",port)
if /sock then stop("Failed to establish connection on ",port)

openFiles := table()
lsp_database := LSPDB()
lsp_database.build()

completionHandler := CompletionHandler()
signatureHandler := SignatureHandler()
hoverHandler := HoverHandler()
Expand Down
Loading