Skip to content

Commit 6c80e82

Browse files
committed
Normalize file paths
1 parent 4b48633 commit 6c80e82

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

autoload/OmniSharp/util.vim

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,20 @@ function! OmniSharp#util#TranslatePathForClient(filename) abort
276276
if filename =~# '\$metadata\$'
277277
let filename = OmniSharp#util#TempDir() . '/' . fnamemodify(filename, ':t')
278278
endif
279-
return fnamemodify(filename, ':.')
279+
280+
let modifiers = get(g:, 'OmniSharp_filename_modifiers', ':.')
281+
282+
if modifiers ==# 'relative'
283+
let common = escape(getcwd(), '\')
284+
let result = ''
285+
while substitute(filename, common . s:dir_separator, '', '') ==# filename
286+
let common = fnamemodify(common, ':h')
287+
let result .= '..' . s:dir_separator
288+
endwhile
289+
return result . substitute(filename, common . s:dir_separator, '', '')
290+
endif
291+
292+
return fnamemodify(filename, modifiers)
280293
endfunction
281294

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

doc/omnisharp-vim.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ Use this option to enable syntastic integration >
410410
-------------------------------------------------------------------------------
411411
3.7 MISCELLANEOUS *omnisharp-miscellaneous-options*
412412

413+
*g:OmniSharp_filename_modifiers*
414+
File paths returned from the server are normalized using Vim
415+
|filename-modifiers|. The |g:OmniSharp_filename_modifiers| variable allows
416+
configuring which modifiers are used.
417+
Additionally, the special value "relative" may be used to force all paths into
418+
a relatve format, e.g. "../../project/file.cs".
419+
Default: :. >
420+
let g:OmniSharp_filename_modifiers = ':p:~'
421+
<or >
422+
let g:OmniSharp_filename_modifiers = 'relative'
423+
<
413424
*g:OmniSharp_lookup_metadata*
414425
When using `OmniSharpGotoDefinition` and `OmniSharpPreviewDefinition`,
415426
fall back to looking up metadata for compiled types.

0 commit comments

Comments
 (0)