mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Improve completions
If the completion cursor is in the middle of an identifier, start the completion matching before that token. GNOME Builder does this before sending us a cursor position, but VS Code does not.
This commit is contained in:
parent
54237d7976
commit
b2b50c6288
2 changed files with 6 additions and 3 deletions
|
@ -41,6 +41,10 @@ def complete(ast_node: ast.AstNode, tokens: T.List[Token], idx: int) -> T.Iterat
|
||||||
if token.start < idx <= token.end:
|
if token.start < idx <= token.end:
|
||||||
token_idx = i
|
token_idx = i
|
||||||
|
|
||||||
|
# if the current token is an identifier, move to the token before it
|
||||||
|
if tokens[token_idx].type == TokenType.IDENT:
|
||||||
|
token_idx -= 1
|
||||||
|
|
||||||
# collect the 5 previous non-skipped tokens
|
# collect the 5 previous non-skipped tokens
|
||||||
while len(prev_tokens) < 5 and token_idx >= 0:
|
while len(prev_tokens) < 5 and token_idx >= 0:
|
||||||
token = tokens[token_idx]
|
token = tokens[token_idx]
|
||||||
|
@ -80,8 +84,6 @@ class Completer:
|
||||||
if not any_match:
|
if not any_match:
|
||||||
return
|
return
|
||||||
|
|
||||||
print("completions", match_variables, self.func)
|
|
||||||
|
|
||||||
if self.ast_type is not None:
|
if self.ast_type is not None:
|
||||||
while ast_node is not None and not isinstance(ast_node, self.ast_type):
|
while ast_node is not None and not isinstance(ast_node, self.ast_type):
|
||||||
ast_node = ast_node.parent
|
ast_node = ast_node.parent
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Completion:
|
||||||
insert_text = self.snippet
|
insert_text = self.snippet
|
||||||
insert_text_format = InsertTextFormat.Snippet
|
insert_text_format = InsertTextFormat.Snippet
|
||||||
|
|
||||||
return {
|
result = {
|
||||||
"label": self.label,
|
"label": self.label,
|
||||||
"kind": self.kind,
|
"kind": self.kind,
|
||||||
"tags": [CompletionItemTag.Deprecated] if self.deprecated else None,
|
"tags": [CompletionItemTag.Deprecated] if self.deprecated else None,
|
||||||
|
@ -93,3 +93,4 @@ class Completion:
|
||||||
"insertText": insert_text,
|
"insertText": insert_text,
|
||||||
"insertTextFormat": insert_text_format,
|
"insertTextFormat": insert_text_format,
|
||||||
}
|
}
|
||||||
|
return { k: v for k, v in result.items() if v is not None }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue