@@ -21,36 +21,37 @@ procedure usage()
21
21
write("Check your IDE for the correct LSP server invocation.")
22
22
write("\nOptions:")
23
23
write("\t --socket <PORT> : set the lsp server port")
24
+ write("\t -s : run as a server (default)")
25
+ write("\t -c : run as a client")
24
26
write("\t -h : show this help\n")
25
27
exit(-1)
26
28
end
27
29
28
30
procedure validate_args(args)
29
- local opts, port
30
- opts := options(args, "--socket:" )
31
+ local opts
32
+ opts := options(args, "--socket+ -h! -c! -s!", usage )
31
33
if *opts = 0 then usage()
32
- port := \opts["-socket"] | usage()
33
- port := opts["-socket"]
34
- return port
34
+ member(opts, "-socket") | usage()
35
+ return opts
35
36
end
36
37
37
-
38
38
procedure main(args)
39
- local port
40
- #write("args: ", ximage(args))
41
- port := validate_args(args) | stop("Error: invalid args/port number.")
39
+ local opts, sock, mode
40
+
41
+ # If validate_args() fails, it will display usage() and never return.
42
+ opts := validate_args(args)
42
43
43
44
# Allow passing full host:port as an arg
44
- if integer(port) then {
45
- if &features == ("MacOS" | "MS Windows NT") then
46
- port := "127.0.0.1:" || port
47
- else
48
- port := ":" || port
45
+ sock := opts["-socket"]
46
+ if &features == ("MacOS" | "MS Windows NT") then {
47
+ sock := "127.0.0.1:" || sock
48
+ }
49
+ else {
50
+ sock := ":" || sock
49
51
}
50
52
51
- Server(port).run()
52
- end
53
-
54
-
55
-
53
+ # Set mode for server to run in, based on opts.
54
+ member(opts, mode := "c") | (mode := "s")
56
55
56
+ Server(sock, mode).run()
57
+ end
0 commit comments