# Enable/disable the logging of the language server protocol messages
def ServerDebug(arg: string)
if ['errors', 'messages', 'off', 'on']->index(arg) == -1
- util.ErrMsg($'Unsupported argument "{arg}" for LspServer debug')
+ util.ErrMsg($'Unsupported argument "{arg}"')
return
endif
var lspservers: list<dict<any>> = buf.CurbufGetServers()
+ if lspservers->empty()
+ util.WarnMsg($'No Lsp servers found for "{@%}"')
+ return
+ endif
+
for lspserver in lspservers
if arg ==# 'on'
util.ClearTraceLogs(lspserver.logfile)
# Show the status of the LSP server for the current buffer
def ShowServer(arg: string)
- var lspservers: list<dict<any>> = buf.CurbufGetServers()
+ if ['status', 'capabilities', 'initializeRequest', 'messages']->index(arg) == -1
+ util.ErrMsg($'Unsupported argument "{arg}"')
+ return
+ endif
+ var lspservers: list<dict<any>> = buf.CurbufGetServers()
if lspservers->empty()
- util.InfoMsg($'No Lsp servers found for this buf')
+ util.WarnMsg($'No Lsp servers found for "{@%}"')
return
endif
# Restart the LSP server for the current buffer
def RestartServer()
+ var lspservers: list<dict<any>> = buf.CurbufGetServers()
+ if lspservers->empty()
+ util.WarnMsg($'No Lsp servers found for "{@%}"')
+ return
+ endif
+
# Remove all the buffers with the same file type as the current buffer
var ftype: string = &filetype
for binfo in getbufinfo()
endif
endfor
- var lspservers: list<dict<any>> = buf.CurbufGetServers()
for lspserver in lspservers
# Stop the server (if running)
if lspserver.running
# Params: SetTraceParams
def ServerTraceSet(traceVal: string)
if ['off', 'messages', 'verbose']->index(traceVal) == -1
- util.ErrMsg($'Unsupported LSP server trace value {traceVal}')
+ util.ErrMsg($'Unsupported argument "{traceVal}"')
return
endif
var lspservers: list<dict<any>> = buf.CurbufGetServers()
+ if lspservers->empty()
+ util.WarnMsg($'No Lsp servers found for "{@%}"')
+ return
+ endif
+
for lspserver in lspservers
lspserver.setTrace(traceVal)
endfor
# ":LspServer" command handler
export def LspServerCmd(args: string)
- if args->stridx('debug ') == 0
- var subcmd = args[6 : ]->trim()
- ServerDebug(subcmd)
+ if args->stridx('debug') == 0
+ if args[5] ==# ' '
+ var subcmd = args[6 : ]->trim()
+ ServerDebug(subcmd)
+ else
+ util.ErrMsg('Argument required')
+ endif
elseif args ==# 'restart'
RestartServer()
- elseif args->stridx('show ') == 0
- var subcmd = args[5 : ]->trim()
- ShowServer(subcmd)
- elseif args->stridx('trace ') == 0
- var subcmd = args[6 : ]->trim()
- ServerTraceSet(subcmd)
+ elseif args->stridx('show') == 0
+ if args[4] ==# ' '
+ var subcmd = args[5 : ]->trim()
+ ShowServer(subcmd)
+ else
+ util.ErrMsg('Argument required')
+ endif
+ elseif args->stridx('trace') == 0
+ if args[5] ==# ' '
+ var subcmd = args[6 : ]->trim()
+ ServerTraceSet(subcmd)
+ else
+ util.ErrMsg('Argument required')
+ endif
else
util.ErrMsg($'LspServer - Unsupported argument "{args}"')
endif
:bw!
enddef
+# Test for the :LspServer command.
+def g:Test_LspServer()
+ new a.raku
+ assert_equal(['Warn: No Lsp servers found for "a.raku"'],
+ execute('LspServer debug on')->split("\n"))
+ assert_equal(['Warn: No Lsp servers found for "a.raku"'],
+ execute('LspServer restart')->split("\n"))
+ assert_equal(['Warn: No Lsp servers found for "a.raku"'],
+ execute('LspServer show status')->split("\n"))
+ assert_equal(['Warn: No Lsp servers found for "a.raku"'],
+ execute('LspServer trace verbose')->split("\n"))
+ assert_equal(['Error: LspServer - Unsupported argument "xyz"'],
+ execute('LspServer xyz')->split("\n"))
+ assert_equal(['Error: Argument required'],
+ execute('LspServer debug')->split("\n"))
+ assert_equal(['Error: Unsupported argument "xyz"'],
+ execute('LspServer debug xyz')->split("\n"))
+ assert_equal(['Error: Unsupported argument "on xyz"'],
+ execute('LspServer debug on xyz')->split("\n"))
+ assert_equal(['Error: Argument required'],
+ execute('LspServer show')->split("\n"))
+ assert_equal(['Error: Unsupported argument "xyz"'],
+ execute('LspServer show xyz')->split("\n"))
+ assert_equal(['Error: Unsupported argument "status xyz"'],
+ execute('LspServer show status xyz')->split("\n"))
+ assert_equal(['Error: Argument required'],
+ execute('LspServer trace')->split("\n"))
+ assert_equal(['Error: Unsupported argument "xyz"'],
+ execute('LspServer trace xyz')->split("\n"))
+ assert_equal(['Error: Unsupported argument "verbose xyz"'],
+ execute('LspServer trace verbose xyz')->split("\n"))
+ :bw!
+enddef
+
# TODO:
# 1. Add a test for autocompletion with a single match while ignoring case.
# After the full matched name is typed, the completion popup should still