Skip to content

Commit

Permalink
Include Scala ctags definition for Tagbar
Browse files Browse the repository at this point in the history
Uses Tagbar’s “deffile” support to make the sidebar work out of the box
if the user has Tagbar installed, no ~/.ctags modification needed.
  • Loading branch information
ches committed Feb 5, 2015
1 parent 6bb6222 commit 3d4fec9
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 38 deletions.
13 changes: 13 additions & 0 deletions ctags/scala.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--langdef=scala
--langmap=scala:.scala

--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*class[ \t ]+([a-zA-Z0-9_]+)/\4/c,classes/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*object[ \t ]+([a-zA-Z0-9_]+)/\4/c,objects/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*case class[ \t ]+([a-zA-Z0-9_]+)/\6/c,case classes/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*case object[ \t ]+([a-zA-Z0-9_]+)/\4/c,case objects/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*trait[ \t ]+([a-zA-Z0-9_]+)/\4/t,traits/
--regex-scala=/^[ \t ]*type[ \t ]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*(\[[a-z]*\])*|protected)[ \t ]*)*def[ \t ]+([a-zA-Z0-9_]+)/\4/m,methods/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*val[ \t ]+([a-zA-Z0-9_]+)/\3/l,constants/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*var[ \t ]+([a-zA-Z0-9_]+)/\3/l,variables/
--regex-scala=/^[ \t ]*package[ \t ]+([a-zA-Z0-9_.]+)/\1/p,packages/
34 changes: 33 additions & 1 deletion doc/scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,40 @@ This plugin is only available if 'compatible' is not set.
==============================================================================
INTRODUCTION *scala*

Syntax highlighting and helper functions for the scala language.
Syntax highlighting and helper functions for the scala language. Extras
include:

- Sorting of import statements, configurable to your conventions.
- Tagbar support to navigate definitions within a file in the plugin's
sidebar window.
- ...and probably more that we've forgotten to update in this doc.

==============================================================================
OPTIONS *scala-options*

Use these options to control behavior of the plugin. Default values are
indicated in the examples.

*'g:scala_use_builtin_tagbar_defs'*
If you are using the Tagbar Vim plugin, vim-scala includes a Tagbar type
definition and ctags definition for Scala, so you can use Tagbar immediately.
If you have your own ctags definition in `~/.ctags` and prefer to use it, set
this option to 0 (we would appreciate contributions if you've improved the
ctags definition!).

Note that Tagbar's ctags definition for Scala is not used to generate a
|tags| file that Vim can use to navigate to definitions in other files, only
for the plugin sidebar. Feel free to copy `vim-scala/ctags/scala.ctags` into
your own `~/.ctags` if you wish to generate |tags| files.
>
let g:scala_use_builtin_tagbar_defs = 1
<
*'g:scala_use_default_keymappings'*
Set this option to disable definition of all mappings provided by vim-scala.
See |scala-mappings|.
>
let g:scala_use_default_keymappings = 1
<
==============================================================================
COMMANDS *scala-commands*

Expand Down
37 changes: 0 additions & 37 deletions ftplugin/scala.vim
Original file line number Diff line number Diff line change
Expand Up @@ -142,43 +142,6 @@ if globpath(&rtp, 'plugin/fuf.vim') != ''
endif
endif


"
" TagBar
"
let g:tagbar_type_scala = {
\ 'ctagstype' : 'scala',
\ 'kinds' : [
\ 'p:packages:1',
\ 'V:values',
\ 'v:variables',
\ 'T:types',
\ 't:traits',
\ 'o:objects',
\ 'a:aclasses',
\ 'c:classes',
\ 'r:cclasses',
\ 'm:methods'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'T' : 'type',
\ 't' : 'trait',
\ 'o' : 'object',
\ 'a' : 'abstract class',
\ 'c' : 'class',
\ 'r' : 'case class'
\ },
\ 'scope2kind' : {
\ 'type' : 'T',
\ 'trait' : 't',
\ 'object' : 'o',
\ 'abstract class' : 'a',
\ 'class' : 'c',
\ 'case class' : 'r'
\ }
\ }

function! s:CreateOrExpression(keywords)
return '('.join(a:keywords, '|').')'
endfunction
Expand Down
49 changes: 49 additions & 0 deletions ftplugin/scala/tagbar.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"
" Support for Tagbar -- https://github.com/majutsushi/tagbar
"
" Hat tip to Leonard Ehrenfried for the built-in ctags deffile:
" https://leonard.io/blog/2013/04/editing-scala-with-vim/
"
if !executable('ctags')
finish
elseif !exists(':Tagbar')
finish
endif

let g:tagbar_type_scala = {
\ 'ctagstype' : 'scala',
\ 'kinds' : [
\ 'p:packages:1',
\ 'V:values',
\ 'v:variables',
\ 'T:types',
\ 't:traits',
\ 'o:objects',
\ 'a:aclasses',
\ 'c:classes',
\ 'r:cclasses',
\ 'm:methods'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'T' : 'type',
\ 't' : 'trait',
\ 'o' : 'object',
\ 'a' : 'abstract class',
\ 'c' : 'class',
\ 'r' : 'case class'
\ },
\ 'scope2kind' : {
\ 'type' : 'T',
\ 'trait' : 't',
\ 'object' : 'o',
\ 'abstract class' : 'a',
\ 'class' : 'c',
\ 'case class' : 'r'
\ }
\ }

" In case you've updated/customized your ~/.ctags and prefer to use it.
if get(g:, 'scala_use_builtin_tagbar_defs', 1)
let g:tagbar_type_scala.deffile = expand('<sfile>:p:h:h:h') . '/ctags/scala.ctags'
endif

0 comments on commit 3d4fec9

Please sign in to comment.