Skip to content

Commit a4950d2

Browse files
committed
Add lsc#config#messageType function
This converts a message type by name into a log level value
1 parent 8f82a02 commit a4950d2

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

autoload/lsc/config.vim

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,30 @@ function! lsc#config#shouldEcho(server, type) abort
169169
let l:threshold = a:server.config.log_level
170170
else
171171
let l:config = a:server.config.log_level
172-
if l:config ==# 'Error'
173-
let l:threshold = 1
174-
elseif l:config ==# 'Warning'
175-
let l:threshold = 2
176-
elseif l:config ==# 'Info'
177-
let l:threshold = 3
178-
elseif l:config ==# 'Log'
179-
let l:threshold = 4
180-
endif
172+
let l:threshold = lsc#config#messageType(l:config)
181173
endif
182174
endif
183175
return a:type <= l:threshold
184176
endfunction
185177

178+
" Convert message type name to number
179+
function! lsc#config#messageType(type) abort
180+
if a:type ==# 'Error'
181+
return 1
182+
elseif a:type ==# 'Warning'
183+
return 2
184+
elseif a:type ==# 'Info'
185+
return 3
186+
elseif a:type ==# 'Log'
187+
return 4
188+
else
189+
call lsc#message#error('Unkown message type: '.a:type)
190+
191+
" Default to "Info"
192+
return 3
193+
endif
194+
endfunction
195+
186196
" A maker from returns from "message_hook" functions indicating that a call
187197
" should not be made.
188198
function! lsc#config#skip() abort

autoload/lsc/server.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ function! s:Dispatch(server, method, params, id) abort
325325
call lsc#util#shift(a:server.logs, 100,
326326
\ {'message': a:params.message, 'type': a:params.type})
327327
elseif a:method ==? 'window/progress'
328-
if lsc#config#shouldEcho(a:server, 4)
328+
let a:params.type = lsc#config#messageType('Log')
329+
if lsc#config#shouldEcho(a:server, a:params.type)
329330
if has_key(a:params, 'message')
330331
let l:full = a:params['title'] . a:params['message']
331332
call lsc#message#show('Progress ' . l:full)

0 commit comments

Comments
 (0)