Skip to content

Commit 1cc36a2

Browse files
committed
Separate filename modify from location parsing
1 parent 01b7c79 commit 1cc36a2

File tree

8 files changed

+65
-40
lines changed

8 files changed

+65
-40
lines changed

autoload/OmniSharp/actions/definition.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ function! s:CBGotoDefinition(opts, location, metadata) abort
7878
let found = 0
7979
endif
8080
else
81-
let found = OmniSharp#locations#Navigate(a:location, a:opts.editcommand)
81+
let location = OmniSharp#locations#Modify(a:location)
82+
let found = OmniSharp#locations#Navigate(location, a:opts.editcommand)
8283
endif
8384
if has_key(a:opts, 'Callback') && !went_to_metadata
8485
call a:opts.Callback(found)
@@ -96,7 +97,8 @@ function! s:CBPreviewDefinition(opts, location, metadata) abort
9697
echo 'Not found'
9798
endif
9899
else
99-
call OmniSharp#locations#Preview(a:location)
100+
let location = OmniSharp#locations#Modify(a:location)
101+
call OmniSharp#locations#Preview(location)
100102
echo fnamemodify(a:location.filename, ':.')
101103
endif
102104
endfunction

autoload/OmniSharp/actions/implementations.vim

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ function! s:CBFindImplementations(target, opts, locations) abort
4949
if numImplementations == 0
5050
echo 'No implementations found'
5151
elseif numImplementations == 1
52-
call OmniSharp#locations#Navigate(a:locations[0])
52+
let location = OmniSharp#locations#Modify(a:locations[0])
53+
call OmniSharp#locations#Navigate(location)
5354
else " numImplementations > 1
54-
call OmniSharp#locations#SetQuickfix(a:locations,
55+
let locations = OmniSharp#locations#Modify(a:locations)
56+
call OmniSharp#locations#SetQuickfix(locations,
5557
\ 'Implementations: ' . a:target)
5658
endif
5759
if has_key(a:opts, 'Callback')
@@ -60,17 +62,17 @@ function! s:CBFindImplementations(target, opts, locations) abort
6062
return numImplementations
6163
endfunction
6264

63-
function! s:CBPreviewImplementation(locs, ...) abort
64-
let numImplementations = len(a:locs)
65+
function! s:CBPreviewImplementation(locations, ...) abort
66+
let numImplementations = len(a:locations)
6567
if numImplementations == 0
6668
echo 'No implementations found'
6769
else
68-
call OmniSharp#locations#Preview(a:locs[0])
69-
let fname = fnamemodify(a:locs[0].filename, ':.')
70+
let location = OmniSharp#locations#Modify(a:locations[0])
71+
call OmniSharp#locations#Preview(location)
7072
if numImplementations == 1
71-
echo fname
73+
echo location.filename
7274
else
73-
echo fname . ': Implementation 1 of ' . numImplementations
75+
echo location.filename . ': Implementation 1 of ' . numImplementations
7476
endif
7577
endif
7678
endfunction

autoload/OmniSharp/actions/symbols.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ function! s:CBFindSymbol(filter, locations) abort
3333
echo 'No symbols found'
3434
return
3535
endif
36+
let locations = OmniSharp#locations#Modify(a:locations)
3637
if g:OmniSharp_selector_ui ==? 'clap'
37-
call clap#OmniSharp#FindSymbols(a:locations)
38+
call clap#OmniSharp#FindSymbols(locations)
3839
elseif g:OmniSharp_selector_ui ==? 'unite'
39-
call unite#start([['OmniSharp/findsymbols', a:locations]])
40+
call unite#start([['OmniSharp/findsymbols', locations]])
4041
elseif g:OmniSharp_selector_ui ==? 'ctrlp'
41-
call ctrlp#OmniSharp#findsymbols#setsymbols(a:locations)
42+
call ctrlp#OmniSharp#findsymbols#setsymbols(locations)
4243
call ctrlp#init(ctrlp#OmniSharp#findsymbols#id())
4344
elseif g:OmniSharp_selector_ui ==? 'fzf'
44-
call fzf#OmniSharp#FindSymbols(a:locations)
45+
call fzf#OmniSharp#FindSymbols(locations)
4546
else
4647
let title = 'Symbols' . (len(a:filter) ? ': ' . a:filter : '')
47-
call OmniSharp#locations#SetQuickfix(a:locations, title)
48+
call OmniSharp#locations#SetQuickfix(locations, title)
4849
endif
4950
endfunction
5051

autoload/OmniSharp/actions/usages.vim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ function! s:CBFindUsages(target, locations) abort
4747
let numUsages = len(a:locations)
4848
if numUsages == 0
4949
echo 'No usages found'
50-
elseif get(g:, 'OmniSharp_selector_findusages', '') ==? 'fzf'
51-
call fzf#OmniSharp#FindUsages(a:locations, a:target)
50+
return 0
51+
endif
52+
53+
let locations = OmniSharp#locations#Modify(a:locations)
54+
if get(g:, 'OmniSharp_selector_findusages', '') ==? 'fzf'
55+
call fzf#OmniSharp#FindUsages(locations, a:target)
5256
elseif get(g:, 'OmniSharp_selector_findusages', '') ==? 'clap'
53-
call clap#OmniSharp#FindUsages(a:locations, a:target)
57+
call clap#OmniSharp#FindUsages(locations, a:target)
5458
else
55-
call OmniSharp#locations#SetQuickfix(a:locations, 'Usages: ' . a:target)
59+
call OmniSharp#locations#SetQuickfix(locations, 'Usages: ' . a:target)
5660
endif
5761
return numUsages
5862
endfunction

autoload/OmniSharp/actions/usings.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ endfunction
4646
function! s:CBFixUsings(opts, locations) abort
4747
let numAmbiguous = len(a:locations)
4848
if numAmbiguous > 0
49-
call OmniSharp#locations#SetQuickfix(a:locations, 'Ambiguous usings')
49+
let locations = OmniSharp#locations#Modify(a:locations)
50+
call OmniSharp#locations#SetQuickfix(locations, 'Ambiguous usings')
5051
endif
5152
if has_key(a:opts, 'Callback')
5253
call a:opts.Callback(numAmbiguous)

autoload/OmniSharp/locations.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
let s:save_cpo = &cpoptions
22
set cpoptions&vim
33

4+
let s:dir_separator = fnamemodify('.', ':p')[-1 :]
5+
6+
function! OmniSharp#locations#Modify(locations) abort
7+
" a:locations may be either a single 'quickfix' location, or list of locations
8+
let locs = copy(type(a:locations) == type([]) ? a:locations : [a:locations])
9+
for location in locs
10+
let location.filename = OmniSharp#locations#ModifyPath(location.filename)
11+
endfor
12+
return type(a:locations) == type([]) ? locs : locs[0]
13+
endfunction
14+
15+
function! OmniSharp#locations#ModifyPath(filename) abort
16+
let modifiers = get(g:, 'OmniSharp_filename_modifiers', ':.')
17+
18+
if modifiers ==# 'relative'
19+
let filename = fnamemodify(a:filename, ':p')
20+
let common = escape(getcwd(), '\')
21+
let relpath = substitute(filename, '^' . common . s:dir_separator, '', '')
22+
let relprefix = ''
23+
while relpath ==# filename && common !=# fnamemodify(common, ':h')
24+
let common = fnamemodify(common, ':h')
25+
let relpath = substitute(filename, '^' . common . s:dir_separator, '', '')
26+
let relprefix .= '..' . s:dir_separator
27+
endwhile
28+
if common !=# fnamemodify(common, ':h')
29+
return relprefix . relpath
30+
endif
31+
let modifiers = ':p'
32+
endif
33+
34+
return fnamemodify(a:filename, modifiers)
35+
endfunction
36+
437
" Navigate to location.
538
" a:location: A location dict, or list of location dicts. The location or
639
" locations have the same format as a quickfix list entry.

autoload/OmniSharp/util.vim

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,25 +280,7 @@ function! OmniSharp#util#TranslatePathForClient(filename) abort
280280
let filename = OmniSharp#util#TempDir() . '/' . fnamemodify(filename, ':t')
281281
endif
282282

283-
let modifiers = get(g:, 'OmniSharp_filename_modifiers', ':.')
284-
285-
if modifiers ==# 'relative'
286-
let filename = fnamemodify(filename, ':p')
287-
let common = escape(getcwd(), '\')
288-
let relpath = substitute(filename, '^' . common . s:dir_separator, '', '')
289-
let relprefix = ''
290-
while relpath ==# filename && common !=# fnamemodify(common, ':h')
291-
let common = fnamemodify(common, ':h')
292-
let relpath = substitute(filename, '^' . common . s:dir_separator, '', '')
293-
let relprefix .= '..' . s:dir_separator
294-
endwhile
295-
if common !=# fnamemodify(common, ':h')
296-
return relprefix . relpath
297-
endif
298-
let modifiers = ':p'
299-
endif
300-
301-
return fnamemodify(filename, modifiers)
283+
return fnamemodify(filename, ':p')
302284
endfunction
303285

304286
function! OmniSharp#util#TranslatePathForServer(filename) abort

doc/omnisharp-vim.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ File paths returned from the server are normalized using Vim
415415
|filename-modifiers|. The |g:OmniSharp_filename_modifiers| variable allows
416416
configuring which modifiers are used.
417417
Additionally, the special value "relative" may be used to force all paths into
418-
a relatve format, e.g. "../../project/file.cs".
418+
a relative format, e.g. "../../project/file.cs".
419419
Default: :. >
420420
let g:OmniSharp_filename_modifiers = ':p:~'
421421
<or >

0 commit comments

Comments
 (0)