ternjs / tern_for_sublime

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

Error: Could not find a definition #19

Closed psyrendust closed 9 years ago

psyrendust commented 11 years ago

With the following code sample, placing my cursor in the middle of the function doSomething on line 4 foo.doSo[cursor here]mething('one', 'two'); hitting alt+. returns Error: Could not find a definition

function Thing(){}
Thing.prototype.doSomething = function(arg1, arg2) {};
var foo = new Thing();
foo.doSomething('one', 'two');
marijnh commented 11 years ago

Works for me, both in sublime text and in the online demo. Is your Tern version up to date?

psyrendust commented 11 years ago

Sublime Plugin

tern_for_sublime/package.json

{
  "name": "tern_for_sublime",
  "license": "MIT",
  "version": "0.2.1",
  "author": "Marijn Haverbeke <marijnh@gmail.com>",
  "description": "Sublime Text package for Tern",
  "repository": {
    "type": "git",
    "url": "git://github.com/marijnh/tern_for_sublime.git"
  },
  "dependencies": {
    "tern": ">=0.2"
  }
}

Tern Node Package

tern_for_sublime/node_modules/package.json

{
  "name": "tern",
  "license": "MIT",
  "version": "0.3.0",
  "author": {
    "name": "Marijn Haverbeke",
    "email": "marijnh@gmail.com"
  },
  "description": "A JavaScript code analyzer for deep, cross-editor language support",
  "main": "lib/tern.js",
  "bin": {
    "tern": "./bin/tern"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/marijnh/tern.git"
  },
  "scripts": {
    "test": "./bin/test"
  },
  "dependencies": {
    "acorn": "0.3",
    "glob": "3",
    "minimatch": "0.2"
  },
  "devDependencies": {
    "codemirror": "git://github.com/marijnh/CodeMirror.git",
    "typescript": "0.8.3"
  },
  "readme": "# Tern\n\nThis is [Tern][1]. Tern is a stand-alone, editor-independent\nJavaScript analyzer that can be used to improve the JavaScript\nintegration of existing editors.\n\nThanks to a group of generous [crowd funders][2], Tern is open-source\nsoftware, under an MIT license.\n\nThere are currently [Emacs][emacs], [Vim][vim], and [Sublime Text][st]\nplugins available, and built-in support in [Brackets][brackets] and \n[Edge Code][edge_code]. \n\nFor further documentation, see the [project page][1] and the\n[manual][3].\n\n[1]: http://ternjs.net\n[2]: http://www.indiegogo.com/projects/tern-intelligent-javascript-editing\n[3]: http://ternjs.net/doc/manual.html\n\n[emacs]: http://ternjs.net/doc/manual.html#emacs\n[vim]: https://github.com/marijnh/tern_for_vim\n[st]: https://github.com/marijnh/tern_for_sublime\n[brackets]: http://brackets.io\n[edge_code]: http://html.adobe.com/edge/code\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/marijnh/tern/issues"
  },
  "_id": "tern@0.3.0",
  "dist": {
    "shasum": "f6f02b17f829cbe3b4bb9716283a42fc6870ac50"
  },
  "_from": "tern@0.3.0",
  "_resolved": "http://registry.npmjs.org/tern/-/tern-0.3.0.tgz"
}

Node Version

± |master ✗| → node --version
v0.8.23

I'm also have this in my Sublime/Packages/User/Pathway.py

This is to fix Sublime Build issues for things like Grunt and SASS. I've tried removing this file to see if this was causing an issue and still had no luck.

import os

HOME = os.environ['HOME']
os.environ['PATH'] = '/usr/local/bin:'
os.environ['PATH'] += HOME+'/.nvm/v0.8.23/bin:'
os.environ['PATH'] += HOME+'/.rvm/gems/ruby-1.9.3-p392/bin:'
os.environ['PATH'] += HOME+'/.rvm/gems/ruby-1.9.3-p392@global/bin:'
os.environ['PATH'] += HOME+'/.rvm/rubies/ruby-1.9.3-p392/bin:'
os.environ['PATH'] += HOME+'/.rvm/bin:/usr/bin:'
os.environ['PATH'] += '/usr/bin:'
os.environ['PATH'] += '/bin:'
os.environ['PATH'] += '/usr/sbin:'
os.environ['PATH'] += '/sbin:'
print 'PATH = ' + os.environ['PATH']
marijnh commented 11 years ago

How odd. I downgraded my tern to 0.3.0, but still see the correct behavior. The PATH shouldn't come into it -- if it fails to run the Tern server, you'd get a different error ('couldn't find a definition' comes from inside the server).

Does jump-to-definition fail in general, or just in this specific case? Do other things, like completion of locally defined variables, work as expected?

tutysara commented 10 years ago

I could jump to the definition of - doSomething in the above code. I get 'Couldn't find a definition' for most of the angularjs variables that I had tried.

var deferred = $q.defer();
deferred.resolve({});

I couldn't jump to the definition(source) of resolve method in deferred variable. Can ternjs do things like jumping to source in libraries?

marijnh commented 10 years ago

Can ternjs do things like jumping to source in libraries?

Nope, not unless the library was analyzed locally (rather than loaded from a description JSON file, as Angular is)

marekkaczkowski commented 9 years ago

Marijn can you add some sample project with requirejs config? Looks like baseURL is ignored. Jump to def only works for dependencies defined as somefile.js and ternjs is looking for those files in project root dir. In other cases data in tern.py/TernJumpToDef:503 is empty so we're getting "Could not find a definition".

marijnh commented 9 years ago

Can you give me an example project where the requirejs plugin fails to find the proper file?

psyrendust commented 9 years ago

@marijnh I'd like to go ahead and close this issue. Would you be ok with that?

marijnh commented 9 years ago

Yes, let's close