Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add correct relative -> absolute path converter

For the :Rdebugger command, added the relative -> absolute path
converter. E.g. command :Rdebugger 'rackup config.ru' will be converted
to "'/usr/bin/rackup' config.ru". First, it tries to find place of the
script by 'which' command, if it is unsuccessful, then it assumes it is
relative path with root dir = current dir.

It also correctly works with spaces in directories, so Issue #37 is
fixed.
  • Loading branch information...
commit b49005f80705f0e849cf319a99c92eebf55b8bc4 1 parent fbc0d61
Anton Astashov authored
View
2  .gitattributes
@@ -0,0 +1,2 @@
+additionals/autoload/ruby_debugger.vim -diff
+vim/autoload/ruby_debugger.vim -diff
View
42 additionals/autoload/ruby_debugger.vim
@@ -99,6 +99,41 @@ function! s:get_tags(cmd)
endfunction
+" Converts command with relative path to absolute path. If given command
+" contains relative path, it will try to use 'which' on it first, and if
+" 'which' returns nothing, it will add current dir path to given command
+function! s:get_escaped_absolute_path(command)
+ " Remove leading and trailing quotes
+ let given_path = a:command
+ let given_path = substitute(given_path, '"', '\"', "g")
+ let given_path = substitute(given_path, "^'", '', "g")
+ let given_path = substitute(given_path, "'$", '', "g")
+ if given_path[0] == '/'
+ let absolute_path = given_path
+ else
+ let parts = split(given_path)
+ let relative_command = remove(parts, 0)
+ let arguments = join(parts)
+ let absolute_command = ""
+ " I don't know Windows analogue for 'which', if you know - feel free to add it here
+ if !(has("win32") || has("win64"))
+ let absolute_command = s:strip(system('which ' . relative_command))
+ endif
+ if empty(absolute_command)
+ let absolute_command = getcwd() . '/' . relative_command
+ endif
+ let absolute_path = "\"'" . absolute_command . "' " . arguments . '"'
+ endif
+ return absolute_path
+endfunction
+
+
+" Return a string without leading and trailing spaces and linebreaks.
+function! s:strip(input_string)
+ return substitute(substitute(a:input_string, "\n", '', 'g'), '(\s*\(.\{-}\)\s*', '\1', 'g')
+endfunction
+
+
" Shortcut for g:RubyDebugger.logger.debug
function! s:log_debug(string)
call g:RubyDebugger.logger.debug(a:string)
@@ -400,13 +435,8 @@ function! RubyDebugger.start(...) dict
call s:log_debug("Executing :Rdebugger...")
let g:RubyDebugger.server = s:Server.new(s:hostname, s:rdebug_port, s:debugger_port, s:runtime_dir, s:tmp_file, s:server_output_file)
let script_string = a:0 && !empty(a:1) ? a:1 : 'script/server webrick'
- let script_string_without_quotes = substitute(script_string, "'", "", "g")
- if script_string_without_quotes[0] != '/'
- let script_string_without_quotes = "'" . getcwd() . '/' . script_string_without_quotes . "'"
- endif
-
echo "Loading debugger..."
- call g:RubyDebugger.server.start(script_string_without_quotes)
+ call g:RubyDebugger.server.start(s:get_escaped_absolute_path(script_string))
let g:RubyDebugger.exceptions = []
for breakpoint in g:RubyDebugger.breakpoints
View
35 ruby_debugger/common.vim
@@ -28,6 +28,41 @@ function! s:get_tags(cmd)
endfunction
+" Converts command with relative path to absolute path. If given command
+" contains relative path, it will try to use 'which' on it first, and if
+" 'which' returns nothing, it will add current dir path to given command
+function! s:get_escaped_absolute_path(command)
+ " Remove leading and trailing quotes
+ let given_path = a:command
+ let given_path = substitute(given_path, '"', '\"', "g")
+ let given_path = substitute(given_path, "^'", '', "g")
+ let given_path = substitute(given_path, "'$", '', "g")
+ if given_path[0] == '/'
+ let absolute_path = given_path
+ else
+ let parts = split(given_path)
+ let relative_command = remove(parts, 0)
+ let arguments = join(parts)
+ let absolute_command = ""
+ " I don't know Windows analogue for 'which', if you know - feel free to add it here
+ if !(has("win32") || has("win64"))
+ let absolute_command = s:strip(system('which ' . relative_command))
+ endif
+ if empty(absolute_command)
+ let absolute_command = getcwd() . '/' . relative_command
+ endif
+ let absolute_path = "\"'" . absolute_command . "' " . arguments . '"'
+ endif
+ return absolute_path
+endfunction
+
+
+" Return a string without leading and trailing spaces and linebreaks.
+function! s:strip(input_string)
+ return substitute(substitute(a:input_string, "\n", '', 'g'), '(\s*\(.\{-}\)\s*', '\1', 'g')
+endfunction
+
+
" Shortcut for g:RubyDebugger.logger.debug
function! s:log_debug(string)
call g:RubyDebugger.logger.debug(a:string)
View
7 ruby_debugger/public.vim
@@ -10,13 +10,8 @@ function! RubyDebugger.start(...) dict
call s:log_debug("Executing :Rdebugger...")
let g:RubyDebugger.server = s:Server.new(s:hostname, s:rdebug_port, s:debugger_port, s:runtime_dir, s:tmp_file, s:server_output_file)
let script_string = a:0 && !empty(a:1) ? a:1 : 'script/server webrick'
- let script_string_without_quotes = substitute(script_string, "'", "", "g")
- if script_string_without_quotes[0] != '/'
- let script_string_without_quotes = "'" . getcwd() . '/' . script_string_without_quotes . "'"
- endif
-
echo "Loading debugger..."
- call g:RubyDebugger.server.start(script_string_without_quotes)
+ call g:RubyDebugger.server.start(s:get_escaped_absolute_path(script_string))
let g:RubyDebugger.exceptions = []
for breakpoint in g:RubyDebugger.breakpoints
View
42 vim/autoload/ruby_debugger.vim
@@ -99,6 +99,41 @@ function! s:get_tags(cmd)
endfunction
+" Converts command with relative path to absolute path. If given command
+" contains relative path, it will try to use 'which' on it first, and if
+" 'which' returns nothing, it will add current dir path to given command
+function! s:get_escaped_absolute_path(command)
+ " Remove leading and trailing quotes
+ let given_path = a:command
+ let given_path = substitute(given_path, '"', '\"', "g")
+ let given_path = substitute(given_path, "^'", '', "g")
+ let given_path = substitute(given_path, "'$", '', "g")
+ if given_path[0] == '/'
+ let absolute_path = given_path
+ else
+ let parts = split(given_path)
+ let relative_command = remove(parts, 0)
+ let arguments = join(parts)
+ let absolute_command = ""
+ " I don't know Windows analogue for 'which', if you know - feel free to add it here
+ if !(has("win32") || has("win64"))
+ let absolute_command = s:strip(system('which ' . relative_command))
+ endif
+ if empty(absolute_command)
+ let absolute_command = getcwd() . '/' . relative_command
+ endif
+ let absolute_path = "\"'" . absolute_command . "' " . arguments . '"'
+ endif
+ return absolute_path
+endfunction
+
+
+" Return a string without leading and trailing spaces and linebreaks.
+function! s:strip(input_string)
+ return substitute(substitute(a:input_string, "\n", '', 'g'), '(\s*\(.\{-}\)\s*', '\1', 'g')
+endfunction
+
+
" Shortcut for g:RubyDebugger.logger.debug
function! s:log_debug(string)
call g:RubyDebugger.logger.debug(a:string)
@@ -400,13 +435,8 @@ function! RubyDebugger.start(...) dict
call s:log_debug("Executing :Rdebugger...")
let g:RubyDebugger.server = s:Server.new(s:hostname, s:rdebug_port, s:debugger_port, s:runtime_dir, s:tmp_file, s:server_output_file)
let script_string = a:0 && !empty(a:1) ? a:1 : 'script/server webrick'
- let script_string_without_quotes = substitute(script_string, "'", "", "g")
- if script_string_without_quotes[0] != '/'
- let script_string_without_quotes = "'" . getcwd() . '/' . script_string_without_quotes . "'"
- endif
-
echo "Loading debugger..."
- call g:RubyDebugger.server.start(script_string_without_quotes)
+ call g:RubyDebugger.server.start(s:get_escaped_absolute_path(script_string))
let g:RubyDebugger.exceptions = []
for breakpoint in g:RubyDebugger.breakpoints
View
2  vim/doc/ruby_debugger.txt
@@ -229,7 +229,7 @@ For this, set some variables in your .vimrc. E.g.: >
let g:ruby_debugger_cucumber_path = 'c:\gembins\cucumber' " set Cucumber path
==============================================================================
-RUBY 1.9 *ruby-debugger-ruby19*
+RUBY 1.9 AND RAILS 3 *ruby-debugger-ruby19*
If you want to use vim-ruby-debugger with Ruby 1.9, the best way will be using
'rvm' (http://rvm.beginrescueend.com/). Install it and then install ruby 1.9:
Please sign in to comment.
Something went wrong with that request. Please try again.