Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Correct boolean interpretation for config variables #365

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ set shortmess+=c
- By default auto popup is enabled, turn it off by

```vim
let g:completion_enable_auto_popup = 0
let g:completion_enable_auto_popup = v:false
```
- Or you can toggle auto popup on the fly by using command `CompletionToggle`
- You can manually trigger completion with mapping key by
Expand Down Expand Up @@ -165,7 +165,7 @@ imap <expr> <cr> pumvisible() ? complete_info()["selected"] != "-1" ?
called and displays in a floating window. Disable it by

```vim
let g:completion_enable_auto_hover = 0
let g:completion_enable_auto_hover = v:false
```

### Enable/Disable auto signature
Expand All @@ -174,7 +174,7 @@ let g:completion_enable_auto_hover = 0
it by

```vim
let g:completion_enable_auto_signature = 0
let g:completion_enable_auto_signature = v:false
```

### Sorting completion items
Expand Down Expand Up @@ -252,7 +252,7 @@ let g:completion_trigger_keyword_length = 3 " default = 1
you can enable it by

```vim
let g:completion_trigger_on_delete = 1
let g:completion_trigger_on_delete = v:true
```

### Timer Adjustment
Expand Down
12 changes: 6 additions & 6 deletions lua/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ local function applyAddtionalTextEdits(completed_item)
if completed_item.user_data.lsp ~= nil then
local item = completed_item.user_data.lsp.completion_item
-- vim-vsnip have better additional text edits...
if vim.fn.exists('g:loaded_vsnip_integ') == 1 then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the == 1 is mandatory here, as VimL functions return an integer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result may be an integer, but according to documentation, any value other than zero is considered True, and only 0 is considered False:

                                                       exists()                                            
exists({expr})  The result is a Number, which is TRUE if {expr} is                                          
                defined, zero otherwise.

So which integer doesn't really matters, as long as it can be interpreted the same way boolean expressions are interpreted in C language.

Restricting the comparison to == 1 may lead to unexpected behaviors if for instance, on runtime, the exists() function decides to return 2; which according to documentation is also a valid return value when the expression is defined.

Copy link
Contributor

@theHamsta theHamsta Apr 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But 0 is true in Lua. You could do if XX ~= 0

This comment was marked as outdated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But 0 is true in Lua. You could do if XX ~= 0

Ok, true, corrected the PR

if vim.fn.exists('g:loaded_vsnip_integ') ~= 0 then
api.nvim_call_function('vsnip_integ#do_complete_done', {
{
completed_item = completed_item,
Expand Down Expand Up @@ -129,7 +129,7 @@ local function hasConfirmedCompletion()
require 'snippets'.expand_at_cursor(completed_item.user_data.actual_item, completed_item.word)
end
end
if opt.get_option('enable_auto_paren') == 1 then
if opt.get_option('enable_auto_paren') then
autoAddParens(completed_item)
end
if completed_item.user_data.snippet_source == 'UltiSnips' then
Expand Down Expand Up @@ -174,7 +174,7 @@ function M.on_InsertEnter()

-- TODO: remove this
local autoChange = false
if opt.get_option('auto_change_source') == 1 then
if opt.get_option('auto_change_source') then
autoChange = true
end

Expand All @@ -189,13 +189,13 @@ function M.on_InsertEnter()
-- complete if changes are made
if l_changedTick ~= manager.changedTick then
manager.changedTick = l_changedTick
if opt.get_option('enable_auto_popup') == 1 then
if opt.get_option('enable_auto_popup') then
source.autoCompletion()
end
if opt.get_option('enable_auto_hover') == 1 then
if opt.get_option('enable_auto_hover') then
hover.autoOpenHoverInPopup(manager)
end
if opt.get_option('enable_auto_signature') == 1 then
if opt.get_option('enable_auto_signature') then
signature.autoOpenSignatureHelp()
end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/completion/matching.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ local opt = require 'completion.option'
local M = {}

local function setup_case(prefix, word)
local ignore_case = opt.get_option('matching_ignore_case') == 1
local ignore_case = opt.get_option('matching_ignore_case')

if ignore_case and opt.get_option('matching_smart_case') == 1 and prefix:match('[A-Z]') then
if ignore_case and opt.get_option('matching_smart_case') and prefix:match('[A-Z]') then
ignore_case = false
end

Expand Down
6 changes: 3 additions & 3 deletions lua/completion/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local triggerCurrentCompletion = function(bufnr, line_to_cursor, prefix, textMat
if value.server_capabilities.completionProvider == nil then
break
end
if opt.get_option('enable_server_trigger') == 1 then
if opt.get_option('enable_server_trigger') then
triggered = triggered or util.checkTriggerCharacter(line_to_cursor,
value.server_capabilities.completionProvider.triggerCharacters)
end
Expand All @@ -101,7 +101,7 @@ local triggerCurrentCompletion = function(bufnr, line_to_cursor, prefix, textMat
if complete_source['triggered_only'] ~= nil then
local triggered_only = util.checkTriggerCharacter(line_to_cursor, complete_source['triggered_only'])
if not triggered_only then
if opt.get_option('auto_change_source') == 1 then
if opt.get_option('auto_change_source') then
manager.changeSource = true
end
return
Expand Down Expand Up @@ -162,7 +162,7 @@ function M.autoCompletion()
-- not sure if I should clear cache here
complete.clearCache()
-- api.nvim_input("<c-g><c-g>")
if opt.get_option('trigger_on_delete') == 1 then
if opt.get_option('trigger_on_delete') then
M.triggerCompletion(false)
end
M.stop_complete = false
Expand Down