Python - Truncate suffix based on relevant context
Implements #248 (closed).
Algorithm:
- Parse the whole prefix+suffix to get the full tree.
- Find the context node around the cursor using the algorithm described on !284 (merged).
- Convert the cursor point (which is relative to the whole prefix+suffix) to a relative point within the context node.
- Split the context node on this relative point and yield the truncated suffix.
Design choices:
This takes a conservative approach as it will keep the bigger context when available. Examples:
- Class within class: it will keep the outer class context, regardless of the cursor being inside the nested class or not.
- Function within function: it will keep the outer function context.
- Method within a class: it will keep the outer class context.
How it is being applied to the engine:
- The context truncation happens before the length-based truncation.
- There is not change to the prefix.
Possible Follow-ups:
- This approach is based on a prioritized list of known tree-sitter node-types. But some symbols should be at the same level (decorated_function and function_definition for example).
Edited by Bruno Cardoso