From 495ff87081dbfcdcfe7c28e4bd26690df41a32c8 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Wed, 26 Dec 2012 16:31:49 +0100 Subject: [PATCH] Added examples to API docs --- docs/source/plugin-api.rst | 61 +++++++++++++++++++++++++++++++++++++- jedi/api.py | 2 +- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/docs/source/plugin-api.rst b/docs/source/plugin-api.rst index 0af2e7ed..75b31bd1 100644 --- a/docs/source/plugin-api.rst +++ b/docs/source/plugin-api.rst @@ -51,4 +51,63 @@ Useful functions Examples -------- -TODO +Completions: + +.. sourcecode:: python + + >>> import jedi + >>> source = '''import json; json.l''' + >>> script = jedi.Script(source, 1, 19, '') + >>> script + + >>> completions = script.complete() + >>> completions + [, ] + >>> completions[1] + + >>> completions[1].complete + 'oads' + >>> completions[1].word + 'loads' + +Definitions: + +.. sourcecode:: python + + >>> import jedi + >>> source = '''def my_func(): + ... print 'called' + ... + ... alias = my_func + ... my_list = [1, None, alias] + ... inception = my_list[2] + ... + ... inception()''' + >>> script = jedi.Script(source, 8, 1, '') + >>> + >>> script.goto() + [] + >>> + >>> script.get_definition() + [] + +Related names: + +.. sourcecode:: python + + >>> import jedi + >>> source = '''x = 3 + ... if 1 == 2: + ... x = 4 + ... else: + ... del x''' + >>> script = jedi.Script(source, 5, 8, '') + >>> rns = script.related_names() + >>> rns + [, ] + >>> rns[0].start_pos + (3, 4) + >>> rns[0].is_keyword + False + >>> rns[0].text + 'x' diff --git a/jedi/api.py b/jedi/api.py index 1ec179f3..5f7f3cd4 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -59,7 +59,7 @@ class Script(object): :type line: int :param col: The column of the cursor (starting with 0). :type col: int - :param source_path: The path of the file in the file system, or ``None`` if + :param source_path: The path of the file in the file system, or ``''`` if it hasn't been saved yet. :type source_path: string or None :param source_encoding: The encoding of ``source``, if it is not a