Skip to content

Commit

Permalink
Include check for dashcase . <ng type> .js [#18]
Browse files Browse the repository at this point in the history
  • Loading branch information
natchiketa committed Jun 17, 2016
1 parent 095b93a commit 7b1448c
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions plugin/angular.vim
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function! s:Find(...) abort
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))

if l:num < 1
echo "angular.vim says: '".query."' not found"
throw "AngularQueryNotFound"
return
endif

Expand Down Expand Up @@ -107,6 +107,16 @@ function! s:dashcase(word) abort
return word
endfunction

function! s:dashcasewithngtype(word) abort
let word = substitute(a:word,'::','/','g')
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
let word = substitute(word,'_\([a-zA-Z]\+\)$','.\1','g')
let word = substitute(word,'_','-','g')
let word = tolower(word)
return word
endfunction

function! s:FindFileBasedOnAngularServiceUnderCursor(cmd) abort
let l:fileundercursor = expand('<cfile>')

Expand All @@ -127,13 +137,26 @@ function! s:FindFileBasedOnAngularServiceUnderCursor(cmd) abort

let l:wordundercursor = expand('<cword>')
let l:dashcased = s:dashcase(l:wordundercursor)
let l:filethatmayexist = l:dashcased . '.js'

if exists('g:angular_filename_convention') && (g:angular_filename_convention == 'camelcased' || g:angular_filename_convention == 'titlecased')
call <SID>Find(l:wordundercursor . '.js', a:cmd)
else
call <SID>Find(l:filethatmayexist, a:cmd)
endif
let l:ngdotcased = s:dashcasewithngtype(l:wordundercursor)
let l:filethatmayexistverbatim = l:wordundercursor . '.js'
let l:filethatmayexistdashcase = l:dashcased . '.js'
let l:filethatmayexistngdotcase = l:ngdotcased . '.js'

let l:queries = [
\ l:filethatmayexistverbatim,
\ l:filethatmayexistdashcase,
\ l:filethatmayexistngdotcase
\ ]

for query in l:queries
try
call <SID>Find(query, a:cmd)
catch 'AngularQueryNotFound'
if (query == l:filethatmayexistngdotcase)
echo "angular.vim says: '".join(l:queries, ', ')."' not found"
endif
endtry
endfor
endfunction

function! s:SubStr(originalstring, pattern, replacement) abort
Expand Down

0 comments on commit 7b1448c

Please sign in to comment.