jedihttp


Ⅰ. 插件描述

Simple http wrapper around jedi

Ⅱ. 基本信息

创建日期:  2015-04-04
使用用户:  1
Github星:  42
插件作者:  Andrea Cedraro

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'vheon/jedihttp'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'vheon/jedihttp'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'vheon/jedihttp'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vheon/jedihttp

Ⅳ. 文档说明

# JediHTTP

Build Status
Build status
Coverage Status

A simple http/json wrapper around [jedi][].

Why

It's only purpose for me is to integrate it with [YouCompleteMe][] allowing to
run [jedi][] under python3 and get python3 completions, but that would not
exclude other uses :). At the moment not all the API It has been wrapped.

Command-line

For starting the server, after you have cloned it somewhere:

python /path/to/JediHTTP/jedihttp.py [options]

Options

--host ADDRESS

If not specified, 127.0.0.1 is used.

--port PORT

Listen on PORT. If not specified, will use any available port.

--log LEVEL

Set logging level to LEVEL. Available levels, from most verbose to least
verbose, are: debug, info, warning, error, and critical. Default value
is info.

--hmac-secret-file PATH

PATH is the path of a JSON file containing a key named hmac_secret. Its value
will be used as the secret for HMAC Auth and the file will be deleted as soon
as it's read.

--idle-suicide-seconds SECONDS

Set the number of SECONDS without any requests sent to the server before it
shuts down. Default is 0 meaning that the server never shuts itself down.
Setting a nonzero value to this option (e.g. 1800 for half an hour) is
recommended in case the client dies without being able to stop the server.

--check-interval-seconds SECONDS

Set the interval in SECONDS to check server inactivity. Default is 600
seconds (10 minutes). Clients should not need to change this value.

API

I thought JediHTTP as a simple wrapper around Jedi so its JSON API resembles
the original python one very much so for more information about what the
parameters are and what they represent look at the original docs
[jedi-plugin-api][].

POST /healthy

Return a 200 status code if the server is up.

POST /ready

Return a 200 status code if the server is up. Is the same as /healthy.

POST /completions

Parameters:

{
  "source": "def f():\n  pass",
  "line": 1,
  "col": 0,
  "path": "/home/user/code/src/file.py",
  "settings": {
    "add_bracket_after_function": true,
    ...
  } // Jedi settings. Optional.
}

Response:

{
  "completions": [
    {
      "module_path": "/usr/lib/python2.7/os.py", // Shows the file path of a module.
      "name": "name", // Name of variable/function/class/module.
      "type": "type", // Type of the completion (module, class, instance, etc.)
      "line": 4,  // The line where the definition occurs (starting with 1).
      "column": 2, // The column where the definition occurs (starting with 0).
      "docstring": "A document string for this completion object.",
      "description": "A textual description of the object."
    },
    ...
  ]
}

POST /gotodefinition

Parameters:

{
  "source": "def f():\n  pass",
  "line": 1,
  "col": 0,
  "path": "/home/user/code/src/file.py",
  "settings": {} // Jedi settings. Optional.
}

Response:

{
  "definitions": [
    {
      "module_path": "/usr/lib/python2.7/os.py", // Shows the file path of a module.
      "name": "name", // Name of variable/function/class/module.
      "type": "type", // Type of the completion (module, class, instance, etc.)
      "line": 3,  // The line where the definition occurs (starting with 1).
      "column": 1, // The column where the definition occurs (starting with 0).
      "in_builtin_module": false, // Whether this is a builtin module.
      "is_keyword": false,
      "docstring": "A document string for this Definition object.",
      "description": "A description of the Definition object.",
      "full_name": "Dot-separated path of this object."
    },
    ...
  ]
}

POST /gotoassignment

Parameters:

{
  "source": "def f():\n  pass",
  "line": 1,
  "col": 0,
  "path": "/home/user/code/src/file.py",
  "follow_imports": true, // Optional (default is false).
  "settings": {} // Jedi settings. Optional.
}

Response:

{
  "definitions": [
    {
      "module_path": "/usr/lib/python2.7/os.py", // Shows the file path of a module.
      "name": "name", // Name of variable/function/class/module.
      "type": "type", // Type of the completion (module, class, instance, etc.)
      "line": 3,  // The line where the definition occurs (starting with 1).
      "column": 1 // The column where the definition occurs (starting with 0).
      "in_builtin_module": false, // Whether this is a builtin module.
      "is_keyword": false,
      "docstring": "A document string for this Definition object.",
      "description": "A description of the Definition object.",
      "full_name": "Dot-separated path of this object."
    },
    ...
  ]
}

POST /usages

Parameters:

{
  "source": "def f():\n  pass\n\na = f()\nb = f()",
  "line": 1,
  "col": 4,
  "path": "/home/user/code/src/file.py",
  "settings": {
    "additional_dynamic_modules": "/path/to/a/file.py"
  } // Jedi settings. Optional.
}

Response:

{
  "definitions": [
    {
      "module_path": "/home/user/code/src/file.py",
      "name": "f",
      "type": "function",
      "in_builtin_module": false,
      "line": 1,
      "column": 4,
      "docstring": "",
      "description": "def f",
      "full_name": "file.f",
      "is_keyword": false
    },
    {
      "module_path": "/home/user/code/src/file.py",
      "name": "f",
      "type": "statement",
      "in_builtin_module": false,
      "line": 4,
      "column": 4,
      "docstring": "",
      "description": "a = f()",
      "full_name": "file",
      "is_keyword": false
    },
    {
      "module_path": "/home/user/code/src/file.py",
      "name": "f",
      "type": "statement",
      "in_builtin_module": false,
      "line": 5,
      "column": 4,
      "docstring": "",
      "description": "b = f()",
      "full_name": "file",
      "is_keyword": false
    }
  ]
}

POST /names

Parameters:

{
  "source": "import os\n\nCONSTANT = 1\n\ndef test():\n  pass",
  "path": "/home/user/code/src/file.py"
  "all_scopes": false, // Optional (default is false).
  "definitions": true, // Optional (default is true).
  "references": false, // Optional (default is false).
  "settings": {} // Jedi settings. Optional.
}

Response:

{
  "definitions": [
    {
      "module_path": "/home/usr/code/src/file.py",
      "name": "os",
      "type": "import",
      "in_builtin_module": false,
      "line": 1,
      "column": 7,
      "docstring": "",
      "description": "import os",
      "full_name": "os",
      "is_keyword": false
    },
    {
      "module_path": "/home/usr/code/src/file.py",
      "name": "CONSTANT",
      "type": "statement",
      "in_builtin_module": false,
      "line": 3,
      "column": 0,
      "docstring": "",
      "description": "CONSTANT = 1",
      "full_name": "names",
      "is_keyword": false
    },
    {
      "module_path": "/home/usr/code/src/file.py",
      "name": "test",
      "type": "function",
      "in_builtin_module": false,
      "line": 5,
      "column": 4,
      "docstring": "test()\n\n",
      "description": "def test",
      "full_name": "names.test",
      "is_keyword": false
    }
  ]
}

POST /preload_module

Parameters:

{
  "modules": [ "numpy", ... ]
}

Response:

true

POST /shutdown

Shut down the server.

Response:

true

In case of errors

Response:

{
  "exception": "ValueError"
  "message": "`column` parameter is not in a valid range.",
  "traceback": "Traceback ..."
}

status code: 500

HMAC Auth

If the server is started with the --hmac-file-secret then the JediHTTP will
require every request and response has to be HMAC signed based on the secred
provided in the file putting the HMAC signature in a header called x-jedihttp-hmac

Assuming || stands for concatenation:

  • requests signature: HMAC( HMAC( body ) || HMAC( http method ) || HMAC( request path ) ).
    For example, HMAC(HMAC('foo') || HMAC('GET') || HMAC('/healthy'))
  • Responses: HMAC( body )

Disclaimer

I'm not a python programmer but I'm using this to experiment with python a bit.

添加新评论