Skip to content

Commit 3d4fec9

Browse files
committed
Include Scala ctags definition for Tagbar
Uses Tagbar’s “deffile” support to make the sidebar work out of the box if the user has Tagbar installed, no ~/.ctags modification needed.
1 parent 6bb6222 commit 3d4fec9

File tree

4 files changed

+95
-38
lines changed

4 files changed

+95
-38
lines changed

ctags/scala.ctags

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--langdef=scala
2+
--langmap=scala:.scala
3+
4+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*class[ \t ]+([a-zA-Z0-9_]+)/\4/c,classes/
5+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*object[ \t ]+([a-zA-Z0-9_]+)/\4/c,objects/
6+
--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/
7+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*case object[ \t ]+([a-zA-Z0-9_]+)/\4/c,case objects/
8+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*trait[ \t ]+([a-zA-Z0-9_]+)/\4/t,traits/
9+
--regex-scala=/^[ \t ]*type[ \t ]+([a-zA-Z0-9_]+)/\1/T,types/
10+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*(\[[a-z]*\])*|protected)[ \t ]*)*def[ \t ]+([a-zA-Z0-9_]+)/\4/m,methods/
11+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*val[ \t ]+([a-zA-Z0-9_]+)/\3/l,constants/
12+
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*var[ \t ]+([a-zA-Z0-9_]+)/\3/l,variables/
13+
--regex-scala=/^[ \t ]*package[ \t ]+([a-zA-Z0-9_.]+)/\1/p,packages/

doc/scala.txt

+33-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,40 @@ This plugin is only available if 'compatible' is not set.
66
==============================================================================
77
INTRODUCTION *scala*
88

9-
Syntax highlighting and helper functions for the scala language.
9+
Syntax highlighting and helper functions for the scala language. Extras
10+
include:
1011

12+
- Sorting of import statements, configurable to your conventions.
13+
- Tagbar support to navigate definitions within a file in the plugin's
14+
sidebar window.
15+
- ...and probably more that we've forgotten to update in this doc.
16+
17+
==============================================================================
18+
OPTIONS *scala-options*
19+
20+
Use these options to control behavior of the plugin. Default values are
21+
indicated in the examples.
22+
23+
*'g:scala_use_builtin_tagbar_defs'*
24+
If you are using the Tagbar Vim plugin, vim-scala includes a Tagbar type
25+
definition and ctags definition for Scala, so you can use Tagbar immediately.
26+
If you have your own ctags definition in `~/.ctags` and prefer to use it, set
27+
this option to 0 (we would appreciate contributions if you've improved the
28+
ctags definition!).
29+
30+
Note that Tagbar's ctags definition for Scala is not used to generate a
31+
|tags| file that Vim can use to navigate to definitions in other files, only
32+
for the plugin sidebar. Feel free to copy `vim-scala/ctags/scala.ctags` into
33+
your own `~/.ctags` if you wish to generate |tags| files.
34+
>
35+
let g:scala_use_builtin_tagbar_defs = 1
36+
<
37+
*'g:scala_use_default_keymappings'*
38+
Set this option to disable definition of all mappings provided by vim-scala.
39+
See |scala-mappings|.
40+
>
41+
let g:scala_use_default_keymappings = 1
42+
<
1143
==============================================================================
1244
COMMANDS *scala-commands*
1345

ftplugin/scala.vim

-37
Original file line numberDiff line numberDiff line change
@@ -142,43 +142,6 @@ if globpath(&rtp, 'plugin/fuf.vim') != ''
142142
endif
143143
endif
144144

145-
146-
"
147-
" TagBar
148-
"
149-
let g:tagbar_type_scala = {
150-
\ 'ctagstype' : 'scala',
151-
\ 'kinds' : [
152-
\ 'p:packages:1',
153-
\ 'V:values',
154-
\ 'v:variables',
155-
\ 'T:types',
156-
\ 't:traits',
157-
\ 'o:objects',
158-
\ 'a:aclasses',
159-
\ 'c:classes',
160-
\ 'r:cclasses',
161-
\ 'm:methods'
162-
\ ],
163-
\ 'sro' : '.',
164-
\ 'kind2scope' : {
165-
\ 'T' : 'type',
166-
\ 't' : 'trait',
167-
\ 'o' : 'object',
168-
\ 'a' : 'abstract class',
169-
\ 'c' : 'class',
170-
\ 'r' : 'case class'
171-
\ },
172-
\ 'scope2kind' : {
173-
\ 'type' : 'T',
174-
\ 'trait' : 't',
175-
\ 'object' : 'o',
176-
\ 'abstract class' : 'a',
177-
\ 'class' : 'c',
178-
\ 'case class' : 'r'
179-
\ }
180-
\ }
181-
182145
function! s:CreateOrExpression(keywords)
183146
return '('.join(a:keywords, '|').')'
184147
endfunction

ftplugin/scala/tagbar.vim

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"
2+
" Support for Tagbar -- https://github.com/majutsushi/tagbar
3+
"
4+
" Hat tip to Leonard Ehrenfried for the built-in ctags deffile:
5+
" https://leonard.io/blog/2013/04/editing-scala-with-vim/
6+
"
7+
if !executable('ctags')
8+
finish
9+
elseif !exists(':Tagbar')
10+
finish
11+
endif
12+
13+
let g:tagbar_type_scala = {
14+
\ 'ctagstype' : 'scala',
15+
\ 'kinds' : [
16+
\ 'p:packages:1',
17+
\ 'V:values',
18+
\ 'v:variables',
19+
\ 'T:types',
20+
\ 't:traits',
21+
\ 'o:objects',
22+
\ 'a:aclasses',
23+
\ 'c:classes',
24+
\ 'r:cclasses',
25+
\ 'm:methods'
26+
\ ],
27+
\ 'sro' : '.',
28+
\ 'kind2scope' : {
29+
\ 'T' : 'type',
30+
\ 't' : 'trait',
31+
\ 'o' : 'object',
32+
\ 'a' : 'abstract class',
33+
\ 'c' : 'class',
34+
\ 'r' : 'case class'
35+
\ },
36+
\ 'scope2kind' : {
37+
\ 'type' : 'T',
38+
\ 'trait' : 't',
39+
\ 'object' : 'o',
40+
\ 'abstract class' : 'a',
41+
\ 'class' : 'c',
42+
\ 'case class' : 'r'
43+
\ }
44+
\ }
45+
46+
" In case you've updated/customized your ~/.ctags and prefer to use it.
47+
if get(g:, 'scala_use_builtin_tagbar_defs', 1)
48+
let g:tagbar_type_scala.deffile = expand('<sfile>:p:h:h:h') . '/ctags/scala.ctags'
49+
endif

0 commit comments

Comments
 (0)