From 8af226327289ea84c07415c2665875bde6a44931 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 2 Apr 2023 19:04:48 -0700 Subject: [PATCH] Add commands to open the LSP server debug and error message files. Update the dates in the license --- LICENSE | 2 +- autoload/lsp/handlers.vim | 2 +- autoload/lsp/lsp.vim | 8 ++++++-- autoload/lsp/lspserver.vim | 14 ++++++------- autoload/lsp/util.vim | 22 ++++++++++++++++++++ doc/lsp.txt | 42 +++++++++++++++++++++++++++++++------- plugin/lsp.vim | 2 +- 7 files changed, 73 insertions(+), 19 deletions(-) diff --git a/LICENSE b/LICENSE index d200e83..9e55f93 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Yegappan Lakshmanan +Copyright (c) 2020-2023 Yegappan Lakshmanan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 16290d4..cbeab06 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -50,7 +50,7 @@ def ProcessLogMsgNotif(lspserver: dict, reply: dict) mtype = msgType[reply.params.type] endif - util.TraceLog(false, $'[{mtype}]: {reply.params.message}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: [{mtype}]: {reply.params.message}') enddef # process unsupported notification messages diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index fd26217..a9ea16a 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -55,7 +55,7 @@ enddef # Enable/disable the logging of the language server protocol messages export def ServerDebug(arg: string) - if arg !=? 'on' && arg !=? 'off' + if arg !=? 'errors' && arg !=? 'messages' && arg !=? 'on' && arg !=? 'off' util.ErrMsg($'Error: Invalid argument ("{arg}") for LSP server debug') return endif @@ -63,8 +63,12 @@ export def ServerDebug(arg: string) if arg ==? 'on' util.ClearTraceLogs() util.ServerTrace(true) - else + elseif arg ==? 'off' util.ServerTrace(false) + elseif arg ==? 'messages' + util.ServerMessagesShow(false) + else + util.ServerMessagesShow(true) endif enddef diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index d8907c3..d890903 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -26,7 +26,7 @@ import './inlayhints.vim' # LSP server standard output handler def Output_cb(lspserver: dict, chan: channel, msg: any): void - util.TraceLog(false, $'Received [{strftime("%m/%d/%y %T")}]: {msg->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Received {msg->string()}') lspserver.data = msg lspserver.processMessages() enddef @@ -38,7 +38,7 @@ enddef # LSP server exit callback def Exit_cb(lspserver: dict, job: job, status: number): void - util.WarnMsg($'[{strftime("%m/%d/%y %T")}]: LSP server exited with status {status}') + util.WarnMsg($'{strftime("%m/%d/%y %T")}: LSP server exited with status {status}') lspserver.running = false lspserver.ready = false lspserver.requests = {} @@ -290,7 +290,7 @@ def SendMessage(lspserver: dict, content: dict): void endif job->ch_sendexpr(content) if content->has_key('id') - util.TraceLog(false, $'Sent [{strftime("%m/%d/%y %T")}]: {content->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Sent {content->string()}') endif enddef @@ -315,12 +315,12 @@ def Rpc(lspserver: dict, method: string, params: any, handleError: bool = t return {} endif - util.TraceLog(false, $'Sent [{strftime("%m/%d/%y %T")}]: {req->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Sent {req->string()}') # Do the synchronous RPC call var reply = job->ch_evalexpr(req) - util.TraceLog(false, $'Received [{strftime("%m/%d/%y %T")}]: {reply->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Received {reply->string()}') if reply->has_key('result') # successful reply @@ -342,7 +342,7 @@ enddef # LSP server asynchronous RPC callback def AsyncRpcCb(lspserver: dict, method: string, RpcCb: func, chan: channel, reply: dict) - util.TraceLog(false, $'Received [{strftime("%m/%d/%y %T")}]: {reply->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Received {reply->string()}') if reply->empty() return @@ -382,7 +382,7 @@ def AsyncRpc(lspserver: dict, method: string, params: any, Cbfunc: func): n return -1 endif - util.TraceLog(false, $'Sent [{strftime("%m/%d/%y %T")}]: {req->string()}') + util.TraceLog(false, $'{strftime("%m/%d/%y %T")}: Sent {req->string()}') # Do the asynchronous RPC call var Fn = function('AsyncRpcCb', [lspserver, method, Cbfunc]) diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index f9e73f6..d2c9e60 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -50,6 +50,28 @@ export def ClearTraceLogs() writefile([], $'{lsp_log_dir}lsp-server.err') enddef +# Open the LSP server debug messages file. If errors is true, then open the +# error messages file. +export def ServerMessagesShow(errors: bool = false) + var fname: string + if errors + fname = $'{lsp_log_dir}lsp-server.err' + else + fname = $'{lsp_log_dir}lsp-server.out' + endif + if filereadable(fname) + var wid = fname->bufwinid() + if wid == -1 + exe $'split {fname}' + else + win_gotoid(wid) + endif + setlocal autoread + setlocal nomodified + setlocal nomodifiable + endif +enddef + # Parse a LSP Location or LocationLink type and return a List with two items. # The first item is the DocumentURI and the second item is the Range. export def LspLocationParse(lsploc: dict): list diff --git a/doc/lsp.txt b/doc/lsp.txt index 146c490..18c3fb4 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -2,12 +2,12 @@ Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) For Vim version 9.0 and above -Last change: March 24, 2023 +Last change: April 2, 2023 ============================================================================== *lsp-license* License: MIT License -Copyright (c) 2020-2022 Yegappan Lakshmanan +Copyright (c) 2020-2023 Yegappan Lakshmanan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -682,11 +682,23 @@ can map these commands to keys and make it easier to invoke them. successively to shrink the current symbol visual region. -:LspServerDebug { on | off } *:LspServerDebug* - Enable or disable the logging of the messages emitted - by a language server in the standard output and - standard error. On a Unix-like system, these messages - are logged to the /tmp/lsp-server.out and + *:LspServerDebug* +:LspServerDebug { on | off | messages | errors } + The following arguments are supported: + + errors Open the log file containing the language + server error messages. + messages + Open the log file containing the language + server debug messages. + off Disable the logging of the language server + messages. + on Enable the logging of the messages emitted + by the language server in the standard output + and standard error. + By default, the language server messages are not + logged. On a Unix-like system, when enabled, these + messages are logged to the /tmp/lsp-server.out and /tmp/lsp-server.err file respectively. On MS-Windows, the %TEMP%/lsp-server.out and %TEMP%/lsp-server.err% files are used. See |lsp-debug| for more information. @@ -1091,6 +1103,22 @@ lsp-server.err file. On a Unix-like system, these files are created in the /tmp directory. On MS-Windows, these files are created in the %TEMP% directory. +The following command opens the file containing the messages printed by the +language server in the stdout: > + + :LspServerDebug messages +< +The following command opens the file containing the messages printed by the +language server in the stderr: > + + :LspServerDebug errors +< +To debug language server initialization problems, after enabling the above +server debug, you can restart the server for the file type in the current +buffer using the following command: > + + :LspServerRestart +< The language servers typically support command line options to enable debug messages and to increase the verbosity of the messages. You can refer to the language server documentation for information about this. You can include diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 7731f6d..043f75c 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -56,7 +56,7 @@ enddef # Command line completion function for the LspSetTrace command. def LspServerDebugComplete(arglead: string, cmdline: string, cursorpos: number): list - var l = ['off', 'on'] + var l = ['errors', 'messages', 'off', 'on'] if arglead->empty() return l else -- 2.48.1