artur-shaik / vim-javacomplete2

DEPRECATED in favor of jc.nvim
Vim License
974 stars 83 forks source link

Paths in groovy temp file are not escaped under windows #422

Closed stewartmatheson closed 3 years ago

stewartmatheson commented 5 years ago

Actual behavior (Required!)

"e:\code\retroforums\RetroforumsApplication.java" [unix] 14L, 335C
Error detected while processing function <SNR>14_JobVimOnErrorHandler[3]..javacomplete#classpath#gradle#BuildClasspathHandler:
line   49:
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\stewart\AppData\Local\Temp\VIAD0FF.tmp' line: 1
* What went wrong:
Could not compile initialization script 'C:\Users\stewart\AppData\Local\Temp\VIAD0FF.tmp'.
> startup failed:
  initialization script 'C:\Users\stewart\AppData\Local\Temp\VIAD0FF.tmp': 1: unexpected char: '\' @ line 1, column 28.
     rootProject{apply from: 'C:\Users\stewart\vimfiles\plugged\vim-javacomplete2\classpath.gradle'}
                                ^
  1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s

It looks like the issue is with the code generated in the tmpfile that is then executed. See

https://github.com/artur-shaik/vim-javacomplete2/blob/master/autoload/javacomplete/classpath/gradle.vim

 \ . g:JavaComplete_Home. g:FILE_SEP. "classpath.gradle'}"], 

which is line 111 in master at the time of this writing. Should the path be escaped somehow? It looks like the windows the windows path contains black slashes that require escaping.

Currently it will generate something like

C:\Users\stewart\AppData\Local\Temp\VIAD0FF.tmp

however it looks like it should be generating something more like

C:\\\\Users\\\\stewart\\\\AppData\\\\Local\\\\Temp\\\\VIAD0FF.tmp

based on this SO post: https://stackoverflow.com/questions/6377295/replace-backslashes-in-a-string-using-java-groovy

I would have some sort of path escape function somewhere in vimscript and be called conditionally when the OS is windows. Would that be the easiest solution or could you some how change the windows slash to \\\\ and not \?

Expected behavior (Required!)

The operation not to show an error message

The steps to reproduce actual behavior (Required!)

  1. Run windows
  2. install vim and this plugin
  3. use the spring init page to create a base spring boot project
  4. open the project in vim then open any .java file

Environment (Required!)

Q&A

Screenshot (Optional)

The output of :redir and :message (Optional)

artur-shaik commented 5 years ago

@DonnieWest can you participate?

DonnieWest commented 5 years ago

@stewartmatheson I'm afraid I don't have a windows computer to test. Could you submit a PR?