MCPcopy
hub / github.com/ycm-core/YouCompleteMe / SetLocationListForWindow

Function SetLocationListForWindow

python/ycm/vimsupport.py:431–475  ·  view source on GitHub ↗
( window,
                              diagnostics,
                              open_on_edit = False )

Source from the content-addressed store, hash-verified

429
430
431def SetLocationListForWindow( window,
432 diagnostics,
433 open_on_edit = False ):
434 window_id = WinIDForWindow( window )
435 """Populate the location list with diagnostics. Diagnostics should be in
436 qflist format; see ":h setqflist" for details."""
437 ycm_loc_id = window.vars.get( 'ycm_loc_id' )
438 # User may have made a bunch of `:lgrep` calls and we do not own the
439 # location list with the ID we remember any more.
440 if ( ycm_loc_id is not None and
441 vim.eval( f'getloclist( { window_id }, '
442 f'{{ "id": { ycm_loc_id }, '
443 '"title": 0 } ).title' ) == 'ycm_loc' ):
444 ycm_loc_id = None
445
446 if ycm_loc_id is None:
447 # Create new and populate
448 vim.eval( f'setloclist( { window_id }, '
449 '[], '
450 '" ", '
451 '{ "title": "ycm_loc", '
452 f'"items": { json.dumps( diagnostics ) } }} )' )
453 window.vars[ 'ycm_loc_id' ] = GetIntValue(
454 f'getloclist( { window_id }, {{ "nr": "$", "id": 0 }} ).id' )
455 elif open_on_edit:
456 # Remove old and create new list
457 vim.eval( f'setloclist( { window_id }, '
458 '[], '
459 '"r", '
460 f'{{ "id": { ycm_loc_id }, '
461 '"items": [], "title": "" } )' )
462 vim.eval( f'setloclist( { window_id }, '
463 '[], '
464 '" ", '
465 '{ "title": "ycm_loc", '
466 f'"items": { json.dumps( diagnostics ) } }} )' )
467 window.vars[ 'ycm_loc_id' ] = GetIntValue(
468 f'getloclist( { window_id }, {{ "nr": "$", "id": 0 }} ).id' )
469 else:
470 # Just populate the old one
471 vim.eval( f'setloclist( { window_id }, '
472 '[], '
473 '"r", '
474 f'{{ "id": { ycm_loc_id }, '
475 f'"items": { json.dumps( diagnostics ) } }} )' )
476
477
478def OpenLocationList( focus = False, autoclose = False ):

Callers 2

SetLocationListFunction · 0.85

Calls 3

WinIDForWindowFunction · 0.85
GetIntValueFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected