LuckyGeck / YcmdCompletion

Sublime Text 3 plugin for C++ code completion and error highlighting, based on Ycmd server
MIT License
41 stars 17 forks source link

Starting ycmd-server automatically? #5

Closed hassec closed 9 years ago

hassec commented 9 years ago

Hey,

I'm not sure if I did everything right, but is it correct, that I have to manually start the ycmd server everytime I want to use the Plugin? I think that is quite bothersome, since you have to create a new options file each time etc... If that is the case wouldn't it be nice if the YcmdCompletion could actually start the server automatically after opening a .cpp file? Would that be achievable?

LuckyGeck commented 9 years ago

Hi!

You can start ymcd server with needed configs once and then work with it as long as you wish. Ycmd server is removing configs after it's start (to keep HMAC keys secure), so you should create a copy of config file before launching ycmd instance. If you are on linux, you can do something like this: https://gist.github.com/LuckyGeck/18afaa12a24f9ade7cdf

I think, that starting ycmd from sublime can be done, but not in auto-mode (for example, I am currently using ycmd from remote machine). As I'm quite busy now and this issue is not critical, I think it can wait.

But pull requests are welcome!

hassec commented 9 years ago

Fixed with #6 so I guess we can close this right?

LuckyGeck commented 9 years ago

I've tested your PR. It doesn't work for me now (simply cannot start ycmd properly). Have you tested it? Maybe I have an old version of ycmd or OS? What is your setup (OS, sublime version)?

I'll return to this issue on Monday and will investigate this problem.

hassec commented 9 years ago

Yes sure, I even deleted all my setting to make sure I wasn't missing anything. I'm working with ST 3 Build 3083 on Linux 15.04. Do you have any error messages in the console? Did you set global_ycm_extra_conf in default_settings.json?

LuckyGeck commented 9 years ago

Message is the same as if no server has been started (http error). Yes, global_ycm_extra_conf is set. This default_settings.json works ok, when I start ycmd manually.

hassec commented 9 years ago

And no error when you start ST and the plugin is loaded? Is default_setting_path in options commented out? In both user and default?
Unfortunately I just realized that I did foget to comment out that settting.
see: hassec@97687207fc9211f3d1536c1ef51b1e28d4e25e8e

LuckyGeck commented 9 years ago

I've fixed this changes in local repo and i've made needed user settings. I've added more logging and all settings look good.

hassec commented 9 years ago

So when you start the ST 3 you get the message [Ycmd] Local Server started at : http://localhost:42018? But when you actually do something in .cpp file you get an error right?

LuckyGeck commented 9 years ago

Yep. When I look at htop (processes list), I see no ycmd process, but several monitor.py processes (that is not correct, as far as I understand).

hassec commented 9 years ago

yes that should not be happening. But since you said you get an http error 500 the server probably started but has some other malfunction. If the server wouldn't start correctly you would get a different error when you send a query. Like something along the line of errno 111 connection refused When you are in htop and press F4 and type ycmd do you not see any server instances?

hassec commented 9 years ago

Something else you could try is in the file http_client.py in _CallHttp change
readData = ..
to

try:
    httphandle = urlopen(req)
    readData = httphandle.read().decode('utf-8')
except Exception as e:
    print(e.read().decode('utf-8'))

just get a detailed look at the HTTP error.

hassec commented 9 years ago

Alright I just tested this on a different computer and everthing worked fine. It did not have ycmd nor ycmdCompletion installed before. This is what I did:

  1. cloned ycmd server and build it by just running ./build.py --clang-completer
  2. set a path to a global .ycm_extra_conf.py in default_settings.json, which lies in .../ycmd/ycmd
  3. install YcmdCompletion.(I just cloned my master, which is the same as yours.)
  4. Now I set my YcmdCompletion settings which included:
    • "use_auto_start_localserver": 1
    • "ycmd_path": "/home/.../ycmd/ycmd"
    • making sure that "default_settings_path": was commented out in both default and user settings.
LuckyGeck commented 9 years ago

I've succeeded in fixing this problem. Simply hardcoded path to python binary worked perfectly well. Sublime is started without my own PATH variable, so python, that is executed from shell is different from that is executed in Popen in sublime. Maybe we should move this setting to plugin config?

hassec commented 9 years ago

Alright I understand what the problem is. Normally the script used sys.executable but I had to change that since ST3 runs pyhton 3 and the server needs to run in python 2.7. What I don't understand is, why calling python in popen won't work for you... When you type python in your shell will it not start a python 2.7 interpreter? Sorry but I don't really understand this...

LuckyGeck commented 9 years ago

MacOS has default python in /usr/bin/python. It is python 2.7.6 (in my case) and is failing to run ycmd (i don't know why). I used brew package manager to setup python and it is placed in /usr/local/bin/python When i run which python in my terminal, i get /usr/local/bin/python. Sublime is started not from terminal, and so it get some default env vars from system. It leads to running default python.

P.S. I almost finished commit, that adds ability to set custom python bin path.

hassec commented 9 years ago

Alright I did not know that. Sorry about that! Then it definitely makes sense to have some kind of setting where the user specifies a python path :) Thanks for fixing it!

LuckyGeck commented 9 years ago

Commited in 3f48d7816ff43a5e40059fdb725a8b034833ceed