hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.79k stars 389 forks source link

Use NormalFloat instead of Normal for cmp.config.window.bordered()'s winhighlight #2042

Open slugbyte opened 1 day ago

slugbyte commented 1 day ago

FAQ

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  window = {
    completion = cmp.config.window.bordered(),
    documentation = cmp.config.window.bordered(),
  },
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF

Description

The winhighlight does not follow the :help docs when using the bordered configuration. the help docs recommends pairing NormalFloat and FloatBorder when configuring floating windows, but nvim-cmp is using Normal with FloatBorder.

winhighlight is assigned Normal:Normal here

I was wondering if it could change the borders window winhighlight to NormalFloat:NormalFloat,FloatBorder:FloatBorder,CursorLine:Visual,Search:None or
Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:Visual,Search:None
In order to make backgrounds and borders consistent with the nvim help docs, other floating windows.

This becomes an issue for colorscheme editors when trying to make nvim-cmps's borders the have the same background color as the main nvim-cmp floating window, it breaks the way borders look for all other floating windows, that follow the :help docs.

Steps to reproduce

use cmp.config.window_bordered()

cmp.setup({
    window = {
       completion = cmp.config.window.bordered(),
       documentation = cmp.config.window.bordered(),
     },
})

Expected behavior

the winhighlight should use NormalFloat for the background when using the bordered config``

Actual behavior

the winhighlight uses Normal for the background when using the the bordered config

Additional context

nvims help docs

related issues

This is an essentially asking for the same thing as issue #748 (merged in PR #1689) but for the main window's fg/bg instead of just the border.

I would be happy to create a PR if this is approved :)

slugbyte commented 1 day ago

this is what i used for testing my proposed change to winhighlight

cmp.setup({
    window = {
        completion = vim.tbl_extend("force", cmp.config.window.bordered(), {
            winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
        }),
        documentation = vim.tbl_extend("force", cmp.config.window.bordered(), {
            winhighlight = "NormalFloat:NormalFloat,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
        }),
    },
    -- rest of config
})