ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

optimize installation detection of node & tern for alternative configurations like nvm #88

Open soenkekluth opened 8 years ago

soenkekluth commented 8 years ago

first of all the plugin won't work if you use nvm (https://github.com/creationix/nvm) for managing and installing node on your system (osx in my case)

well I am not a python guy, but why don't you just check if node and tern are available as services instead of - or before determining the path to each installation? thats the part that fails.

nvm is a quite common tool to install and manage node and parallel node installations.

I think an easy way to solve this without going too deep (into trouble) would be an option to set the node path and or the tern path in the package settings.

what do you think? its quite a hassle to get the plugin running with nvm...

kmpkt commented 8 years ago

+1

alanmoo commented 8 years ago

@soenkekluth, just to confirm it looks like the keyboard shortcuts work for jumping to definitions and back, but the autocomplete doesn't work, is that right? That's what I'm experiencing with nvm as my node manager, at least.

marijnh commented 8 years ago

Have you tried setting the tern_command option to whatever should be invoked on your system to start the Tern server?

margaritis commented 8 years ago

You can try the following:

  1. Create Node and Tern symlinks.

    ln -s `which node` /usr/local/bin/node
    ln -s `which tern` /usr/local/bin/tern
  2. Update your Sublime preferences by adding the following configuration

    "tern_command":[
       "/usr/local/bin/node",
       "/usr/local/bin/tern"
    ]

I am using the above setup on all my machines and it seems to work flawlessly. @soenkekluth @kmpkt @alanmoo let me know how it works for you guys

P.S I have updated the documentation section in order to include the above configuration

alanmoo commented 8 years ago

What happens when you change node version in NVM? If I'm understanding your suggestion correctly, @margaritis, it looks like that would point the executable /Users/Alan/.nvm/versions/node/v4.1.1/bin/node at whatever version of node is installed on my system, defeating the purpose of NVM. Or am I misunderstanding?

alanmoo commented 8 years ago

Ok, I got it working with the following in Tern's sublime settings:

"tern_command": ["/Users/Alan/.nvm/versions/node/v4.1.1/bin/node","/Users/Alan/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/node_modules/tern/bin/tern"]

Probably not ideal and I have a feeling it will break in the future, but at least I've got it working for now, hope this can help someone else. Part of my problem was that I wasn't clear on the params for tern_command, in that [0] needed to be my path to Node.

chigix commented 8 years ago

@alanmoo I agree. I also have been encountered such a case that I have a particular node binary provided for SUBLIME ONLY, rather than other application sharing system wide node configuration. So I modified the tern_command string building with node_path configuration support in #127