roxma / nvim-completion-manager

:warning: PLEASE USE https://github.com/ncm2/ncm2 INSTEAD
MIT License
917 stars 49 forks source link

[question] how to use css omni completion in .js file type #103

Closed casprwang closed 7 years ago

casprwang commented 7 years ago

here's what I've tried without luck

au User CmSetup call cm#register_source({'name' : 'cm-css',
        \ 'priority': 9, 
        \ 'scopes': ['css', 'scss','js','jsx'],
        \ 'scoping': 1,
        \ 'abbreviation': 'css',
        \ 'cm_refresh_patterns':['\w{2,}$',':\s+\w*$'],
        \ 'cm_refresh': {'omnifunc': 'csscomplete#

and

autocmd FileType js set omnifunc=csscomplete#CompleteCSS
autocmd FileType javascript set omnifunc=csscomplete#CompleteCSS
autocmd FileType jsx set omnifunc=csscomplete#CompleteCSS
roxma commented 7 years ago

Css completion is already registered by the ncm. You can't register it twice.

Use g:cm_sources_override, override cm-css source's scopes field.

casprwang commented 7 years ago

Works, you've made my day!

FWIW:

let g:cm_sources_override = {
    \ 'cm-css': {'scopes': ['css', 'scss', 'javascript', 'jsx', 'javascript.jsx']}
    \ }

It's pretty useful for CSS-in-js tools like Styled components, I can add the example into readme for clarification if you want.