Expand description
Name resolution for the LSP’s go-to-definition and signature help
(src/lsp.rs): over the open document, and from there into the modules it
imports and the classes it defines.
The document is parsed with the runtime’s own parser and every binding is
filed under the scope Python gives it: the module, a function (its
parameters and everything it assigns, minus global names), or a class body.
A name at the cursor resolves the way the compiler resolves it — the
innermost function outward, class bodies skipped from inside their methods,
then the module — to the binding in that scope nearest above the cursor, or
the first one when every binding comes later (a module function called from
a function defined above it).
An attribute resolves the way it does at run time for the receivers whose
value the document itself determines: self.x / cls.x in a method — the
enclosing class, its instance attributes (self.x = … in any of its
methods) and then its bases, left to right — a class the document defines,
and a module it imports. An imported name resolves into the imported
module’s file, found as sys.path[0] finds it — beside the document — or,
for a relative import, in the document’s package; a name that module itself
imports is followed on.
Positions are 0-based (line, character) with character counted in
chars, as the rest of the server counts them.
Structs§
- Signature
- A signature to show: the label, each parameter’s text, the active parameter, and the docstring.
- Target
- Where a definition is:
fileisNonefor the open document;lineandcharacterare 0-based andlenis the name’s length in chars (0 for a module, which is the start of its file).
Functions§
- definition
definition_atwithin the open document only, as(line0, char0, length).- definition_
at - Go-to-definition: where the name under the cursor is bound, in the open
document or in a module it imports.
docis the document’s own path, which the imports are found relative to.Nonefor a builtin, an attribute of a value the document does not determine, or a name bound nowhere it can see. - signature_
help - Signature help for the call the cursor is inside, when its callee is a
function or class the document can see: defined in it, imported from a
module beside it, or a method reached through
self, a class or a module (a class shows__init__withoutself, and so does a method called onself). - signature_
help_ at signature_help, with the document’s path to find its imports from.