angelozerr / tern-node-express

A Tern plugin adding support for express web application framework for node.
http://expressjs.com/
MIT License
56 stars 4 forks source link

Express Request auto-completion issue #7

Closed ghost closed 9 years ago

ghost commented 9 years ago

There is something I still don't grab as res... is not showing express request verbs as expected but some other API syntax:

screen shot 2014-10-02 at 09 23 56

In this case I was looking for res.params or res.param from initial .p but only got a .pipe() or a .propertyIsEnumerable() methods that don't belong to existing node-express.js definitions...

ghost commented 9 years ago

Something else I notice regarding the same topic is about the res.send() autocompletion that seems to be working fine in demo but was not defined in existing node-express.js definitions — for an obvious cause: you don't send a request but receive it — in my understanding...

ghost commented 9 years ago

OOPs - my mistake: it's not res for Response but req for Request — I should know as I am doing this very same mistake from years by now: res.send() is fine indeed...

But I am still confused about res.pipe() (etc) as this one doesn't belong to tern-node-express as far as I know.

Is Tern using its multiple plugins alltogether?

If so then that would be a serious issue as you could autocomplete your code wrong — I mean: for another irrelevent API.

angelozerr commented 9 years ago

But I am still confused about res.pipe() (etc) as this one doesn't belong to tern-node-express as far as I know.

Ok let's me explain the power of tern:)

Express Request extends Node.js http.IncomingMessage (see source at https://github.com/strongloop/express/blob/master/lib/request.js#L20)

http.IncomingMessage extends stream.Readable.prototype which extends stream which defines pipe methods.

The pipe from the compeltion comes from https://github.com/angelozerr/tern-node-express/blob/master/demos/resources/ternjs/tern/plugin/node.js#L313

tern-express-node extends this tern node plugin (which manages for instance require method).

To declare extension with Tern, you can use "!proto". See https://github.com/angelozerr/tern-node-express/blob/master/node-express.js#L196

Request: {
        "!type": "fn()",
        prototype : {
          "!proto" : "http.IncomingMessage.prototype",
...
ghost commented 9 years ago

Thank you for your explanations — I now understand the "unknown" verbs I can see are inherited from the tern-node plugin: I should have guessed...

I am still having a strange problem this morning as new verbs added to node-express.js in Request: {} definitions are not showing up in the CodeMirror demo as expected.

BTW - how do you type a Boolean return value in Tern syntax? Like in:

      acceptsCharsets: {
          "!type": "fn(type: string) -> boolean",
          "!url": "http://expressjs.com/4x/api.html#req.acceptsCharsets",
          "!doc": "Check if the given charset are acceptable."                        
      },
ghost commented 9 years ago

One more question: what will happen if tern-node-express plugin redefines a verb already defined in tern-node plugin?

angelozerr commented 9 years ago

I am still having a strange problem this morning as new verbs added to node-express.js in Request: {} definitions are not showing up in the CodeMirror demo as expected.

If compeltion doesn't work, it means that you have errors spc for your JSON Type Definition. See your error console of your web browser to know the error.

BTW - how do you type a Boolean return value in Tern syntax? Like in:

It's bool. I suggest you to read http://ternjs.net/doc/manual.html#typedef

One more question: what will happen if tern-node-express plugin redefines a verb already defined in tern-node plugin?

I have never done that, you should try.

angelozerr commented 9 years ago

I close this issue