Skip to content

Commit 0b535aa

Browse files
committed
support enhanced gf in html (not just js) for ng-include
1 parent 8b31b8a commit 0b535aa

4 files changed

Lines changed: 108 additions & 67 deletions

File tree

plugin/angular.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ nnoremap <silent> <Plug>AngularGfTabjump :<C-U>exe <SID>FindFileBasedOnAngularSe
199199
200200
augroup angular_gf
201201
autocmd!
202-
autocmd FileType javascript command! -buffer AngularGoToFile :call s:FindFileBasedOnAngularServiceUnderCursor('open')
203-
autocmd FileType javascript nmap <buffer> gf <Plug>AngularGfJump
204-
autocmd FileType javascript nmap <buffer> <C-W>f <Plug>AngularGfSplit
205-
autocmd FileType javascript nmap <buffer> <C-W><C-F> <Plug>AngularGfSplit
206-
autocmd FileType javascript nmap <buffer> <C-W>gf <Plug>AngularGfTabjump
202+
autocmd FileType javascript,html command! -buffer AngularGoToFile :call s:FindFileBasedOnAngularServiceUnderCursor('open')
203+
autocmd FileType javascript,html nmap <buffer> gf <Plug>AngularGfJump
204+
autocmd FileType javascript,html nmap <buffer> <C-W>f <Plug>AngularGfSplit
205+
autocmd FileType javascript,html nmap <buffer> <C-W><C-F> <Plug>AngularGfSplit
206+
autocmd FileType javascript,html nmap <buffer> <C-W>gf <Plug>AngularGfTabjump
207207
augroup END
208208

209209
augroup angular_alternate

spec/alternate_spec.rb

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22

33
describe "alternate" do
44

5-
def should_alternate_from_a_to_b(file_a, file_b)
6-
vim.edit file_a
7-
current_file_name.should eq file_a
8-
vim.command 'A'
9-
current_file_name.should eq file_b
10-
end
11-
12-
def should_alternate_between(file_a, file_b)
13-
code_path = file_a
14-
test_path = file_b
15-
setup_filesystem(code_path, test_path)
16-
should_alternate_from_a_to_b(code_path, test_path)
17-
should_alternate_from_a_to_b(test_path, code_path)
18-
FileUtils.rm(file_a)
19-
FileUtils.rm(file_b)
20-
end
21-
225
specify "pairs that should work" do
236
should_alternate_between('app/src/poo.js', 'test/unit/poo.js')
247
should_alternate_between('app/src/poo.js', 'test/unit/pooSpec.js')
@@ -36,5 +19,24 @@ def should_alternate_between(file_a, file_b)
3619
vim.command 'A'
3720
current_file_name.should eq file_a
3821
end
39-
end
4022

23+
private
24+
25+
def should_alternate_from_a_to_b(file_a, file_b)
26+
vim.edit file_a
27+
current_file_name.should eq file_a
28+
vim.command 'A'
29+
current_file_name.should eq file_b
30+
end
31+
32+
def should_alternate_between(file_a, file_b)
33+
code_path = file_a
34+
test_path = file_b
35+
setup_filesystem(code_path, test_path)
36+
should_alternate_from_a_to_b(code_path, test_path)
37+
should_alternate_from_a_to_b(test_path, code_path)
38+
FileUtils.rm(file_a)
39+
FileUtils.rm(file_b)
40+
end
41+
42+
end

spec/gf_definition_spec.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
describe "gf definition" do
44

5-
def find_definition(string_to_find_by)
6-
write_file('starting-file.js', <<-EOF)
7-
#{string_to_find_by}
8-
EOF
9-
10-
vim.edit 'starting-file.js'
11-
current_file_name.should eq "starting-file.js"
12-
vim.command 'AngularGoToFile'
13-
end
14-
155
specify "should be found by same name but without js" do
166
setup_filesystem('app/js/poo.js')
177
find_definition('poo')
@@ -41,5 +31,17 @@ def find_definition(string_to_find_by)
4131
find_definition('poo')
4232
current_file_name.should eq "./app/js/piles-of-poo.js"
4333
end
44-
end
4534

35+
private
36+
37+
def find_definition(string_to_find_by)
38+
write_file('starting-file.js', <<-EOF)
39+
#{string_to_find_by}
40+
EOF
41+
42+
vim.edit 'starting-file.js'
43+
current_file_name.should eq "starting-file.js"
44+
vim.command 'AngularGoToFile'
45+
end
46+
47+
end

spec/gf_file_spec.rb

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,98 @@
22

33
describe "gf file" do
44

5-
def html_file_at(filename)
6-
safe_write_file(filename)
7-
end
8-
9-
def do_gf_from_directive!(template_url = 'my-customer.html')
10-
write_file('directive.js', <<-EOF)
11-
angular.module('docsTemplateUrlDirective', [])
12-
.controller('Controller', ['$scope', function($scope) {
13-
$scope.customer = {
14-
name: 'Naomi',
15-
address: '1600 Amphitheatre'
16-
};
17-
}])
18-
.directive('myCustomer', function() {
19-
return {
20-
templateUrl: '#{template_url}'
21-
};
22-
});
23-
EOF
24-
25-
vim.edit 'directive.js'
26-
current_file_name.should eq "directive.js"
27-
vim.normal '/my-cust<CR>'
28-
#vim.normal 'gf'
29-
vim.command 'AngularGoToFile'
5+
specify "default behavior for directive" do
6+
html_file_at('my-customer.html')
7+
do_gf_from_directive_that_references!('my-customer.html')
8+
current_file_name.should eq "my-customer.html"
309
end
3110

32-
specify "default behavior" do
11+
specify "default behavior for view" do
3312
html_file_at('my-customer.html')
34-
do_gf_from_directive!
13+
do_gf_from_view_that_references!('my-customer.html')
3514
current_file_name.should eq "my-customer.html"
3615
end
3716

3817
specify "when html in app/templates and directive references full path" do
3918
html_file_at('app/templates/my-customer.html')
40-
do_gf_from_directive!('app/templates/my-customer.html')
19+
do_gf_from_directive_that_references!('app/templates/my-customer.html')
4120
current_file_name.should eq "app/templates/my-customer.html"
4221
end
4322

4423
specify "when html in app/templates and directive references path minus app" do
4524
html_file_at('app/templates/my-customer.html')
46-
do_gf_from_directive!('templates/my-customer.html')
25+
do_gf_from_directive_that_references!('templates/my-customer.html')
4726
current_file_name.should eq "app/templates/my-customer.html"
4827
end
4928

50-
specify "when html in app subdirectory" do
29+
specify "when html in app/templates and view references path minus app" do
30+
html_file_at('app/templates/my-customer.html')
31+
do_gf_from_view_that_references!('templates/my-customer.html')
32+
current_file_name.should eq "app/templates/my-customer.html"
33+
end
34+
35+
specify "when html in app/views and view references path minus app" do
36+
html_file_at('app/views/my-customer.html')
37+
do_gf_from_view_that_references!('views/my-customer.html')
38+
current_file_name.should eq "app/views/my-customer.html"
39+
end
40+
41+
specify "when html in app subdirectory and directive references path minus app" do
5142
html_file_at('app/my-customer.html')
52-
do_gf_from_directive!
43+
do_gf_from_directive_that_references!('my-customer.html')
5344
current_file_name.should eq "app/my-customer.html"
5445
end
5546

56-
specify "when html in random unsupported subdirectory" do
47+
specify "when html in random unsupported subdirectory that directive is not referencing" do
5748
html_file_at('wut/my-customer.html')
58-
do_gf_from_directive!
49+
do_gf_from_directive_that_references!('my-customer.html')
5950
current_file_name.should eq "directive.js"
6051
end
6152

53+
private
54+
55+
def html_file_at(filename)
56+
safe_write_file(filename)
57+
end
58+
59+
def do_gf(starting_file, starting_file_contents)
60+
write_file(starting_file, starting_file_contents)
61+
62+
vim.edit starting_file
63+
current_file_name.should eq starting_file
64+
vim.normal '/my-cust<CR>'
65+
#vim.normal 'gf'
66+
vim.command 'AngularGoToFile'
67+
end
68+
69+
def do_gf_from_directive_that_references!(template_url)
70+
starting_file = 'directive.js'
71+
72+
do_gf(starting_file, <<-EOF)
73+
angular.module('docsTemplateUrlDirective', [])
74+
.controller('Controller', ['$scope', function($scope) {
75+
$scope.customer = {
76+
name: 'Naomi',
77+
address: '1600 Amphitheatre'
78+
};
79+
}])
80+
.directive('myCustomer', function() {
81+
return {
82+
templateUrl: '#{template_url}'
83+
};
84+
});
85+
EOF
86+
end
87+
88+
def do_gf_from_view_that_references!(template_url)
89+
starting_file = 'hot.html'
90+
91+
do_gf(starting_file, <<-EOF)
92+
<div class="totally-awesome"
93+
ng-if="readyToRock"
94+
ng-include src="'#{template_url}'">
95+
</div
96+
EOF
97+
end
98+
6299
end

0 commit comments

Comments
 (0)