or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coc.nvim@0.0.x

docs

index.md
tile.json

tessl/npm-coc-nvim

tessl install tessl/npm-coc-nvim@0.0.0

LSP based intellisense engine for neovim & vim8.

workspace.mddocs/navigation/

Workspace [Intermediate]

Complexity: Intermediate | Category: Navigation

Common Tasks: Search workspace symbols | Open links | Manage workspace folders

Manage workspace folders, workspace symbols, and workspace-wide operations.

Common Tasks

Search Workspace Symbols

:CocList symbols

Interactive workspace symbol search.

Search Symbols Programmatically

let symbols = CocAction('workspaceSymbols', 'MyClass')

Open Link Under Cursor

nmap gx <Plug>(coc-openlink)

List Workspace Folders

:CocList folders

CocAction API

workspaceSymbols

CocAction('workspaceSymbols', [query])
" Returns: list

Search for symbols across the entire workspace.

Parameters:

  • query: Optional search query string

Returns: List of workspace symbol objects with properties:

  • name: Symbol name
  • kind: Symbol kind (Class, Function, etc.)
  • location: Location object with uri and range
  • containerName: 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
endfor

getWorkspaceSymbols

CocAction('getWorkspaceSymbols', query)
" Returns: list

Get workspace symbols matching query. Similar to workspaceSymbols.

Parameters:

  • query: Search query

Returns: List of symbol objects.

Example:

let results = CocAction('getWorkspaceSymbols', 'function')
for result in results
  echo result.name . ' in ' . result.location.uri
endfor

resolveWorkspaceSymbol

CocAction('resolveWorkspaceSymbol', symbol)
" Returns: symbol

Resolve additional information for a workspace symbol.

Parameters:

  • symbol: Symbol object to resolve

Returns: 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
endif

ensureDocument

CocAction('ensureDocument')

Ensure the current document is attached to the language server.

Example:

call CocAction('ensureDocument')

" Ensure before operations
autocmd BufEnter * call CocAction('ensureDocument')

openLink

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')

Key Mappings

<Plug>(coc-openlink)

<Plug>(coc-openlink)

Open link under cursor.

Example:

nmap <silent> gx <Plug>(coc-openlink)
xmap <silent> gx <Plug>(coc-openlink)

Global Variables

g:WorkspaceFolders

g:WorkspaceFolders

Runtime 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
endif

Utility Functions

coc#ui#open_url()

coc#ui#open_url(url)

Open URL in default browser.

Parameters:

  • url: URL to open

Example:

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)
endfunction

coc#ui#open_files()

coc#ui#open_files(files)

Open multiple files.

Parameters:

  • files: List of file paths

Example:

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)

Configuration

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"]
}

Using CocList

:CocList folders

:CocList folders

List and manage workspace folders.

Actions:

  • Add workspace folder
  • Remove workspace folder
  • Edit workspace configuration

Example:

:CocList folders

" Map to key
nnoremap <silent> <leader>wf :CocList folders<CR>

:CocList symbols

: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>

Examples

Search Workspace Symbols

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>)

Interactive Symbol Search

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>

Manage Workspace Folders

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>

Smart Link Opening

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>

Workspace Symbol Statistics

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()

Error Handling

No Workspace Symbols

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"
endif

Invalid Link

Handle invalid links gracefully:

try
  call CocAction('openLink')
catch
  echo "Invalid or unsupported link"
endtry

Troubleshooting

Workspace Symbols Not Found

Problem: Symbol search returns no results.

Solutions:

  1. Wait for language server indexing to complete
  2. Check workspace folders: :CocList folders
  3. Verify language server is running: :CocInfo
  4. Check workspace.ignoredFolders in settings
  5. Restart language server: :CocRestart

Wrong Workspace Root

Problem: Coc using incorrect workspace root.

Solutions:

  1. Check current root: :pwd
  2. Configure root patterns: "workspace.rootPatterns"
  3. Add workspace folder manually: :CocList folders
  4. Set workspace.workspaceFolderCheckCwd": true

Link Not Opening

Problem: gx or <Plug>(coc-openlink) doesn't work.

Solutions:

  1. Check if cursor is on link
  2. Verify link format is correct
  3. Test with call CocAction('openLink')
  4. Check system default browser/opener
  5. Specify custom command: call CocAction('openLink', 'firefox')

Performance Notes

  • Large Workspaces: Symbol search may be slow on initial index
  • Ignore Folders: Use workspace.ignoredFolders to exclude large directories
  • Symbol Caching: Language servers cache symbols for performance

See Also

  • Code Navigation - Jump to definitions
  • Symbols & Outline - Document-level symbols
  • Call Hierarchy - Function call relationships
  • List Interface - Using CocList
  • Configuration - Workspace settings