From 6cbd77f4df7578d1c97e48ba8cd4206794d5a840 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 9 Aug 2018 12:40:37 -0700 Subject: [PATCH] Fix diagnostic truncatign for multi-byte chars In some cases where a mult-byte character was at the truncation point it could get broken and end with with things like `<86>` in the output. Use `strtrans` to get the string as it would be printed, then `strchars` and `strdisplaywidth` to truncate to handle both multi-byte and wide characters. Add changelog for duplicate word completion and prepare to tag for release. --- CHANGELOG.md | 4 +++- autoload/lsc/cursor.vim | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 699f06c5..a4604494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.3.1-dev +# 0.3.1 - Allow using the default map but overriding or omitting a subset of the keys. - Set `completefunc` even when autocomplete is enabled. @@ -10,6 +10,8 @@ automatically. - Bug fix: Handle workspace edits that have double quotes. - Add support for `CodeAction` literals. +- Bug fix: Correctly truncate multi-byte or wide character diagnostics. +- Bug fix: Allow duplicate words in completions (overloads). # 0.3.0 diff --git a/autoload/lsc/cursor.vim b/autoload/lsc/cursor.vim index 1efae2c6..dd1b7b47 100644 --- a/autoload/lsc/cursor.vim +++ b/autoload/lsc/cursor.vim @@ -27,14 +27,19 @@ function! lsc#cursor#enableReferenceHighlights(filetype) endfunction function! lsc#cursor#showDiagnostic() abort - let diagnostic = lsc#diagnostics#underCursor() - if has_key(diagnostic, 'message') - let max_width = &columns - 18 - let message = substitute(diagnostic.message, '\n', '\\n', 'g') - if len(message) > max_width - echo message[:max_width].'...' + let l:diagnostic = lsc#diagnostics#underCursor() + if has_key(l:diagnostic, 'message') + let l:max_width = &columns - 18 + let l:message = strtrans(l:diagnostic.message) + if strdisplaywidth(l:message) > l:max_width + let l:truncated = strcharpart(l:message, 0, l:max_width) + " Trim by character until a satisfactory display width. + while strdisplaywidth(l:truncated) > l:max_width + let l:truncated = strcharpart(l:truncated, 0, strchars(l:truncated) - 1) + endwhile + echo l:truncated.'...' else - echo message + echo l:message endif else echo ''