]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add commands to open the LSP server debug and error message files. Update the dates...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 3 Apr 2023 02:04:48 +0000 (19:04 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 3 Apr 2023 02:04:48 +0000 (19:04 -0700)
LICENSE
autoload/lsp/handlers.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
autoload/lsp/util.vim
doc/lsp.txt
plugin/lsp.vim

diff --git a/LICENSE b/LICENSE
index d200e83e60dbd530be319c44b5172c19d798bc06..9e55f93ad24d0737eb27099910847ceb997ebf69 100644 (file)
--- 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
index 16290d48f007a41b05db80b5500a7b7fa3c95f72..cbeab062512cd0a3e13477bfd591d190a1e734db 100644 (file)
@@ -50,7 +50,7 @@ def ProcessLogMsgNotif(lspserver: dict<any>, reply: dict<any>)
     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
index fd26217d8ad6539e12cc4357151aeaf1b60375dd..a9ea16ae37b70879558d31c87616b08a8e353416 100644 (file)
@@ -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
 
index d8907c35f94c976cd5343e9b778fa2ef26d706a6..d8909033714c9f0719de70c220097dc929b501b1 100644 (file)
@@ -26,7 +26,7 @@ import './inlayhints.vim'
 
 # LSP server standard output handler
 def Output_cb(lspserver: dict<any>, 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<any>, 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<any>, content: dict<any>): 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<any>, 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<any>, method: string, RpcCb: func, chan: channel, reply: dict<any>)
-  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<any>, 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])
index f9e73f6e9ab071cdd22108089dba6ed7ab735e4c..d2c9e606cc3ce9ab6b7c5c7d61521d37cd441a7d 100644 (file)
@@ -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<any>): list<any>
index 146c4905e987238496d185707c486f7d5cae5c5b..18c3fb4253b1af6aa1d6091bfb70329813fb8806 100644 (file)
@@ -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
index 7731f6d4ee8441ac894962fb06f8027605e583b6..043f75caba2f01ab6e38318f78fee7a26edeb987 100644 (file)
@@ -56,7 +56,7 @@ enddef
 
 # Command line completion function for the LspSetTrace command.
 def LspServerDebugComplete(arglead: string, cmdline: string, cursorpos: number): list<string>
-  var l = ['off', 'on']
+  var l = ['errors', 'messages', 'off', 'on']
   if arglead->empty()
     return l
   else