summary
這裏使用的插件是elpy,代碼跳轉使用的是jedi
問題:No definition found
代碼結構:
1
2
3
4
5
6
7
8
9
10╰─➤ tree elpy_q
elpy_q
├── __init__.py
├── __main__.py
├── sub
│ ├── __init__.py
│ └── sub.py
└── sub2
├── __init__.py
└── sub2.py</p><p>2 directories, 6 files
code
__main__.py
1
2
3
41│from sub2.sub2 import test2
2│
3│
4│test2()
sub.py
1
2
3
4
51│import os
2│
3│
4│def test():
5│ print('sub: ' + os.getcwd())
sub2.py
1
2
3
4
5
61│from sub.sub import test
2│
3│
4│def test2():
5│ print('sub2 call sub')
6│ test()
analysis
1
2
3
4
5
6
71707│(defun elpy-goto-definition ()
1708│ "Go to the definition of the symbol at point, if found."
1709│ (interactive)
1710│ (let ((location (elpy-rpc-get-definition)))
1711│ (if location
1712│ (elpy-goto-location (car location) (cadr location))
1713│ (error "No definition found"))))1
2
3
4
5
6
7
8
92721│(defun elpy-rpc--get-rpc-buffer ()
2722│ "Return the RPC buffer associated with the current buffer,
2723│creating one if necessary."
2724│ (when (not (elpy-rpc--process-buffer-p elpy-rpc--buffer))
2725│ (setq elpy-rpc--buffer
2726│ (or (elpy-rpc--find-buffer (elpy-library-root)
2727│ elpy-rpc-python-command)
2728│ (elpy-rpc--open (elpy-library-root)
2729│ elpy-rpc-python-command))))1
2
3
4
5
6
7
8
9
101226│(defun elpy-library-root ()
1227│ "Return the root of the Python package chain of the current buffer.
1228│
1229│That is, if you have /foo/package/module.py, it will return /foo,
1230│so that import package.module will pick up module.py."
1231│ (locate-dominating-file default-directory
1232│ (lambda (dir)
1233│ (not (file-exists-p
1234│ (format "%s/__init__.py"
1235│ dir))))))1
2
3
427│ def __init__(self, project_root):
28│ self.project_root = project_root
29│ self.completions = {}
30│ sys.path.append(project_root)1
2
3
427│ def __init__(self, project_root):
28│ self.project_root = project_root
29│ self.completions = {}
30│ sys.path.append(project_root)1
2
3
4
5(locate-dominating-file default-directory
(lambda (dir)
(not (file-exists-p
(format "%s/__init__.py"
dir))))))
Reflection
代碼不規範,主函數怎麼能定義在包裏呢?