Skip to content

Commit

Permalink
fix python completions in quarto
Browse files Browse the repository at this point in the history
  • Loading branch information
seeM committed Feb 25, 2025
1 parent d2ea969 commit c4d135e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
Hover,
InitializeParams,
InitializeResult,
InsertReplaceEdit,
InsertTextFormat,
Location,
MessageType,
Expand Down Expand Up @@ -522,15 +523,24 @@ def positron_completion(
)

# If Jedi knows how to complete the expression, use its suggestion.
if completion.complete is not None:
new_text = completion.complete
if new_text is not None:
# Using the text_edit attribute (instead of insert_text used in
# lsp_completion_item) notifies the client to use the text as is.
# lsp_completion_item) notifies the client to use the text as is,
# which is required to complete paths across `-` symbols,
# since the client may treat them as word boundaries.
# See https://github.com/posit-dev/positron/issues/5193.
jedi_completion_item.text_edit = TextEdit(
#
# Use InsertReplaceEdit instead of TextEdit since the latter ends up
# setting the deprecated vscode.CompletionItem.textEdit property
# in the client. Quarto also doesn't support the textEdit property.
# See https://github.com/posit-dev/positron/issues/6444.
jedi_completion_item.text_edit = InsertReplaceEdit(
new_text=new_text,
# Use a range that starts and ends at the cursor position to insert
# text at the cursor.
Range(params.position, params.position),
completion.complete,
insert=Range(params.position, params.position),
replace=Range(params.position, params.position),
)
completion_items.append(jedi_completion_item)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Hover,
HoverParams,
InitializeParams,
InsertReplaceEdit,
Location,
MarkupContent,
MarkupKind,
Expand Down Expand Up @@ -444,8 +445,11 @@ def assert_has_path_completion(
assert len(completions) == 1

expected_position = Position(0, character)
assert completions[0].text_edit == TextEdit(
Range(expected_position, expected_position), expected_completion
expected_range = Range(expected_position, expected_position)
assert completions[0].text_edit == InsertReplaceEdit(
new_text=expected_completion,
insert=expected_range,
replace=expected_range,
)


Expand Down

0 comments on commit c4d135e

Please sign in to comment.