Skip to content

Commit

Permalink
Fix diagnostic truncatign for multi-byte chars
Browse files Browse the repository at this point in the history
In some cases where a mult-byte character was at the truncation point it
could get broken and end with with things like `<e2><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.
  • Loading branch information
natebosch committed Aug 9, 2018
1 parent cc74a14 commit 6cbd77f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
19 changes: 12 additions & 7 deletions autoload/lsc/cursor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down

0 comments on commit 6cbd77f

Please sign in to comment.