summaryrefslogtreecommitdiffstats
path: root/ftplugin/purescript.vim
blob: b53af764d92a26b8cd88b5e6cc2f7a1ecfe36cae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let s:base = expand("<sfile>:h:h")
let Filter = { _, v -> stridx(v, s:base) == -1 && stridx(v, $VIMRUNTIME) == -1 && v !~ "after" }
let files = filter(globpath(&rtp, 'ftplugin/purescript.vim', 1, 1), Filter)
if len(files) > 0
  exec 'source ' . files[0]
  finish
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1

setlocal comments=s1fl:{-,mb:\ \ ,ex:-},:--\ \|,:--
setlocal commentstring=--\ %s
setlocal include=^import
setlocal includeexpr=printf('%s.purs',substitute(v:fname,'\\.','/','g'))

let s:PS = []
fun! InitPureScript()
  let dirs = map(
	\ findfile("psc-package.json", expand("%:p:h") . ";/", -1),
	\ { idx, val -> fnamemodify(val, ":p:h") }
	\ )
  if empty(dirs)
    let dirs = map(
	  \ findfile("bower.json", expand("%:p:h") . ";/", -1),
	  \ { idx, val -> fnamemodify(val, ":p:h") }
	  \ )
    if empty(dirs)
      return
    endif
  endif

  let path = expand("%:p")
  for p in s:PS
    if stridx(path, p[0], 0) == 0
      let &l:path=p[1]
      return
    endif
  endfor

  let dir = dirs[len(dirs) - 1]
  let gp = globpath(dir, "src/**/*.purs", v:true, v:true)
  if empty(gp)
    return
  endif

  let &l:path=join([dir, dir . "/bower_components/**", dir . "/src/**"], ",")
  call add(s:PS, [dir, &l:path])
endfun
call InitPureScript()

endif