From 2ed0efa668b316bf2c1cb87c59355b48969b2dd2 Mon Sep 17 00:00:00 2001 From: Greg Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 7 Jul 2020 14:50:02 -0600 Subject: [PATCH] Add lsc#config#messageType function This converts a message type by name into a log level value --- autoload/lsc/config.vim | 28 +++++++++++++++++++--------- autoload/lsc/server.vim | 3 ++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/autoload/lsc/config.vim b/autoload/lsc/config.vim index 316ecd21..7ad86a55 100644 --- a/autoload/lsc/config.vim +++ b/autoload/lsc/config.vim @@ -169,20 +169,30 @@ function! lsc#config#shouldEcho(server, type) abort let l:threshold = a:server.config.log_level else let l:config = a:server.config.log_level - if l:config ==# 'Error' - let l:threshold = 1 - elseif l:config ==# 'Warning' - let l:threshold = 2 - elseif l:config ==# 'Info' - let l:threshold = 3 - elseif l:config ==# 'Log' - let l:threshold = 4 - endif + let l:threshold = lsc#config#messageType(l:config) endif endif return a:type <= l:threshold endfunction +" Convert message type name to number +function! lsc#config#messageType(type) abort + if a:type ==# 'Error' + return 1 + elseif a:type ==# 'Warning' + return 2 + elseif a:type ==# 'Info' + return 3 + elseif a:type ==# 'Log' + return 4 + else + call lsc#message#error('Unkown message type: '.a:type) + + " Default to "Info" + return 3 + endif +endfunction + " A maker from returns from "message_hook" functions indicating that a call " should not be made. function! lsc#config#skip() abort diff --git a/autoload/lsc/server.vim b/autoload/lsc/server.vim index 3d72c61b..a98e4458 100644 --- a/autoload/lsc/server.vim +++ b/autoload/lsc/server.vim @@ -325,7 +325,8 @@ function! s:Dispatch(server, method, params, id) abort call lsc#util#shift(a:server.logs, 100, \ {'message': a:params.message, 'type': a:params.type}) elseif a:method ==? 'window/progress' - if lsc#config#shouldEcho(a:server, 4) + let a:params.type = lsc#config#messageType('Log') + if lsc#config#shouldEcho(a:server, a:params.type) if has_key(a:params, 'message') let l:full = a:params['title'] . a:params['message'] call lsc#message#show('Progress ' . l:full)