text_properties.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2020, YouCompleteMe Contributors
  2. #
  3. # This file is part of YouCompleteMe.
  4. #
  5. # YouCompleteMe is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # YouCompleteMe is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. from ycm import vimsupport
  18. from ycmd import utils
  19. import vim
  20. import json
  21. # FIXME/TODO: Merge this with vimsupport funcitons, added after these were
  22. # written. It's not trivial, as those vimsupport functions are a bit fiddly.
  23. # They also support neovim, but we don't.
  24. def AddTextPropertyType( name, **kwargs ):
  25. props = {
  26. 'highlight': 'Ignore',
  27. 'combine': False,
  28. 'start_incl': False,
  29. 'end_incl': False,
  30. 'priority': 10
  31. }
  32. props.update( kwargs )
  33. vim.eval( f"prop_type_add( '{ vimsupport.EscapeForVim( name ) }', "
  34. f" { json.dumps( kwargs ) } )" )
  35. def GetTextPropertyTypes( *args, **kwargs ):
  36. return [ utils.ToUnicode( p ) for p in vim.eval( 'prop_type_list()' ) ]
  37. def AddTextProperty( bufnr,
  38. prop_id,
  39. prop_type,
  40. range,
  41. extra_args: dict = None ):
  42. props = {
  43. 'end_lnum': range[ 'end' ][ 'line_num' ],
  44. 'end_col': range[ 'end' ][ 'column_num' ],
  45. 'bufnr': bufnr,
  46. 'type': prop_type
  47. }
  48. if prop_id is not None:
  49. props[ 'id' ]: prop_id
  50. if extra_args:
  51. props.update( extra_args )
  52. return vim.eval( f"prop_add( { range[ 'start' ][ 'line_num' ] },"
  53. f" { range[ 'start' ][ 'column_num' ] },"
  54. f" { json.dumps( props ) } )" )
  55. def ClearTextProperties( bufnr, prop_id ):
  56. props = {
  57. 'id': prop_id,
  58. 'bufnr': bufnr,
  59. 'all': 1,
  60. }
  61. vim.eval( f"prop_remove( { json.dumps( props ) } )" )