tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Intermediate | Category: Navigation
Common Tasks: Search workspace symbols | Open links | Manage workspace folders
Manage workspace folders, workspace symbols, and workspace-wide operations.
:CocList symbolsInteractive workspace symbol search.
let symbols = CocAction('workspaceSymbols', 'MyClass')nmap gx <Plug>(coc-openlink):CocList foldersCocAction('workspaceSymbols', [query])
" Returns: listSearch for symbols across the entire workspace.
Parameters:
query: Optional search query stringReturns: List of workspace symbol objects with properties:
name: Symbol namekind: Symbol kind (Class, Function, etc.)location: Location object with uri and rangecontainerName: Parent symbol name (if any)Example:
" Search all symbols
let symbols = CocAction('workspaceSymbols')
" Search for specific symbols
let symbols = CocAction('workspaceSymbols', 'MyClass')
echo 'Found ' . len(symbols) . ' symbols'
for sym in symbols
echo sym.kind . ': ' . sym.name
endforCocAction('getWorkspaceSymbols', query)
" Returns: listGet workspace symbols matching query. Similar to workspaceSymbols.
Parameters:
query: Search queryReturns: List of symbol objects.
Example:
let results = CocAction('getWorkspaceSymbols', 'function')
for result in results
echo result.name . ' in ' . result.location.uri
endforCocAction('resolveWorkspaceSymbol', symbol)
" Returns: symbolResolve additional information for a workspace symbol.
Parameters:
symbol: Symbol object to resolveReturns: Resolved symbol with complete information.
Example:
let symbols = CocAction('workspaceSymbols', 'MyClass')
if len(symbols) > 0
let resolved = CocAction('resolveWorkspaceSymbol', symbols[0])
echo resolved.name . ' at ' . resolved.location.uri
endifCocAction('ensureDocument')Ensure the current document is attached to the language server.
Example:
call CocAction('ensureDocument')
" Ensure before operations
autocmd BufEnter * call CocAction('ensureDocument')CocAction('openLink', [command])Open link under cursor (URL or file path).
Parameters:
command: Optional open command (default: system opener)Example:
" Open with default handler
call CocAction('openLink')
" Open in specific application
call CocAction('openLink', 'firefox')
" Open in Vim
call CocAction('openLink', 'edit')<Plug>(coc-openlink)Open link under cursor.
Example:
nmap <silent> gx <Plug>(coc-openlink)
xmap <silent> gx <Plug>(coc-openlink)g:WorkspaceFoldersRuntime variable containing list of workspace folder paths.
Type: List (read-only)
Example:
if exists('g:WorkspaceFolders')
echo 'Workspace folders:'
for folder in g:WorkspaceFolders
echo ' ' . folder
endfor
endifcoc#ui#open_url(url)Open URL in default browser.
Parameters:
url: URL to openExample:
call coc#ui#open_url('https://github.com/neoclide/coc.nvim')
" Open documentation links
function! OpenDocs(url) abort
call coc#ui#open_url(a:url)
endfunctioncoc#ui#open_files(files)Open multiple files.
Parameters:
files: List of file pathsExample:
call coc#ui#open_files(['file1.js', 'file2.js', 'file3.js'])
" Open related files
let related = ['src/index.js', 'src/utils.js', 'test/index.test.js']
call coc#ui#open_files(related)Workspace settings in coc-settings.json:
{
"workspace.ignoredFolders": [
"$HOME",
"$HOME/.cargo/**",
"$HOME/.rustup/**",
"**/node_modules/**",
"**/.git/**"
],
"workspace.workspaceFolderCheckCwd": true,
"workspace.openResourceCommand": "edit",
"workspace.rootPatterns": [".git", ".hg", ".projections.json"]
}:CocList foldersList and manage workspace folders.
Actions:
Example:
:CocList folders
" Map to key
nnoremap <silent> <leader>wf :CocList folders<CR>:CocList symbols [query]Search workspace symbols interactively with fuzzy matching.
Example:
:CocList symbols
" Search symbols with initial query
:CocList symbols MyClass
" Map to key
nnoremap <silent> <leader>ws :CocList symbols<CR>function! SearchWorkspaceSymbols(query) abort
let symbols = CocAction('workspaceSymbols', a:query)
if len(symbols) == 0
echo 'No symbols found for: ' . a:query
return
endif
echo 'Found ' . len(symbols) . ' symbols:'
for symbol in symbols
let file = fnamemodify(substitute(symbol.location.uri, 'file://', '', ''), ':t')
echo symbol.kind . ': ' . symbol.name . ' (' . file . ')'
endfor
endfunction
command! -nargs=1 FindSymbol call SearchWorkspaceSymbols(<q-args>)function! InteractiveSymbolSearch() abort
let query = input('Search symbols: ')
if empty(query)
return
endif
let symbols = CocAction('workspaceSymbols', query)
if len(symbols) == 0
echo 'No symbols found'
return
endif
" Build menu
let items = []
for i in range(len(symbols))
let sym = symbols[i]
let file = fnamemodify(substitute(sym.location.uri, 'file://', '', ''), ':t')
call add(items, (i + 1) . '. ' . sym.kind . ': ' . sym.name . ' (' . file . ')')
endfor
let choice = inputlist(['Select symbol:'] + items)
if choice > 0 && choice <= len(symbols)
let sym = symbols[choice - 1]
let loc = sym.location
let file = substitute(loc.uri, 'file://', '', '')
execute 'edit ' . fnameescape(file)
call cursor(loc.range.start.line + 1, loc.range.start.character + 1)
normal! zz
endif
endfunction
nnoremap <silent> <leader>ws :call InteractiveSymbolSearch()<CR>function! ShowWorkspaceFolders() abort
if !exists('g:WorkspaceFolders')
echo 'No workspace folders'
return
endif
echo '=== Workspace Folders ==='
for i in range(len(g:WorkspaceFolders))
echo (i + 1) . '. ' . g:WorkspaceFolders[i]
endfor
endfunction
command! ShowWorkspace call ShowWorkspaceFolders()
nnoremap <silent> <leader>wl :ShowWorkspace<CR>function! SmartOpenLink() abort
let word = expand('<cWORD>')
" Detect link type
if word =~# '^https\?://'
call coc#ui#open_url(word)
elseif word =~# '^file://'
let path = substitute(word, 'file://', '', '')
execute 'edit ' . fnameescape(path)
elseif filereadable(expand(word))
execute 'edit ' . fnameescape(word)
else
call CocAction('openLink')
endif
endfunction
nnoremap <silent> gx :call SmartOpenLink()<CR>function! WorkspaceSymbolStats() abort
let symbols = CocAction('workspaceSymbols')
let stats = {}
for sym in symbols
let kind = sym.kind
if !has_key(stats, kind)
let stats[kind] = 0
endif
let stats[kind] += 1
endfor
echo '=== Workspace Symbol Statistics ==='
echo 'Total symbols: ' . len(symbols)
echo ''
for [kind, count] in sort(items(stats))
echo printf("%-15s: %d", kind, count)
endfor
endfunction
command! WorkspaceStats call WorkspaceSymbolStats()Handle cases where no symbols are found:
let symbols = CocAction('workspaceSymbols', query)
if len(symbols) == 0
echo "No symbols found. Possible reasons:"
echo "- Language server not finished indexing"
echo "- No matching symbols"
echo "- Workspace folders not configured"
endifHandle invalid links gracefully:
try
call CocAction('openLink')
catch
echo "Invalid or unsupported link"
endtryProblem: Symbol search returns no results.
Solutions:
:CocList folders:CocInfo:CocRestartProblem: Coc using incorrect workspace root.
Solutions:
:pwd"workspace.rootPatterns":CocList foldersworkspace.workspaceFolderCheckCwd": trueProblem: gx or <Plug>(coc-openlink) doesn't work.
Solutions:
call CocAction('openLink')call CocAction('openLink', 'firefox')workspace.ignoredFolders to exclude large directories