Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tern not respecting .tern-config in home directory. #2857

Closed
natealcedo opened this issue Dec 18, 2017 · 8 comments
Closed

Tern not respecting .tern-config in home directory. #2857

natealcedo opened this issue Dec 18, 2017 · 8 comments

Comments

@natealcedo
Copy link

Tern does not provide auto completion with a custom NODE_PATH when loading a global .tern-config in the home directory. I just did a reinstall of my vim with and am using YouCompleteMe which uses tern. Previous to this installation, I was able to do something like this NODE_PATH=src vim . and I would be able to get auto completions and tern would be able to find files. If I do a :TernDef, the files are not found.

With this reisntall though this is no longer the case and I now have to copy over my .tern-config from my home directory into my project directory as .tern-project to get the same behaviour.

Take a look at these pictures. the Tern config points to the one in my home directory.
global

No auto complete is provided.
local-no-complete

However when I use a local .tern-project.
local

Things work as usual.
local-complete

I only noticed this behaviour because I had to setup my computer fresh. I usually save my dotfiles and have a script that copies them over. So on my other machine, everything works perfectly. But on a fresh install it doesnt work.

They are exactly the same file. I just copied it over doing something like this. cat ~/.tern-config >> .tern-project

This is what my current config file looks like

{
  "plugins": {
    "es_modules": {},
    "node": {},
    "modules": {}
  },
  "libs": [
    "ecma5",
    "ecma6",
    "browser"
    ],
    "ecmaVersion": 6
}
@micbou
Copy link
Collaborator

micbou commented Dec 18, 2017

That's because we changed which working directory is used by Tern when a .tern-config file is found in PR ycm-core/ycmd#875. The home directory is now used as the working directory (instead of Vim working directory). You need to set NODE_PATH to an absolute path (or to a path relative to your home directory) and things will work.

Honestly, I didn't think of that use case when implementing the changes in PR ycm-core/ycmd#875 (I thought the working directory didn't really matter when a .tern-config was found). I guess we should revert to the old behavior.

@natealcedo
Copy link
Author

So for this to work as I expect I just have to do this src=~/pathtoworkingdirectory vim .?

@micbou
Copy link
Collaborator

micbou commented Dec 18, 2017

Rather NODE_PATH=/path/to/src vim . where /path/to/src is an absolute path.

@natealcedo
Copy link
Author

Ah I see. Is this something that you guys will consider reverting? I use NODE_PATH in my projects which help to make imports easier since I don't have to do deep nested imports and it's a cleaner approach.

@micbou
Copy link
Collaborator

micbou commented Dec 18, 2017

Yes. See PR ycm-core/ycmd#886. We are even going to improve the behavior by handling the scenario where the user want to switch to another project without a .tern-project file. This will be possible by changing Vim working directory to that project and restarting the Tern server:

:cd /path/to/another/project
:YcmCompleter RestartServer

Users currently have to restart the ycmd server for this to work:

:cd /path/to/another/project
:YcmRestartServer

@natealcedo
Copy link
Author

Ok that is great news. Thanks for the quick response! Looking forward to this PR being merged :)

@natealcedo
Copy link
Author

For those who are facing this issue and want a short NODE_PATH that is generic enough you can do something like this provided you open vim in the repo directory NODE_PATH=$(pwd)/src vim .

zzbot added a commit to ycm-core/ycmd that referenced this issue Dec 22, 2017
…puremourning

[READY] Use current working directory in JavaScript completer

Use the Client working directory instead of the home directory when no `.tern-project` file is found. If no working directory is given (no `working_dir` field in the request), we fall back to ycmd working directory. See issue ycm-core/YouCompleteMe#2857.

Once this is merged, we'll update YCM to always include the working directory in the request as done in PR ycm-core/YouCompleteMe#2827.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/886)
<!-- Reviewable:end -->
@natealcedo
Copy link
Author

Since the pull request fixing this issue has been merged I'm going to close this issue. Thanks @micbou

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants