Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python completions in Quarto #6471

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
Hover,
InitializeParams,
InitializeResult,
InsertReplaceEdit,
InsertTextFormat,
Location,
MessageType,
Expand All @@ -89,7 +90,6 @@
SymbolInformation,
TextDocumentIdentifier,
TextDocumentPositionParams,
TextEdit,
WorkspaceEdit,
WorkspaceSymbolParams,
)
Expand Down Expand Up @@ -522,15 +522,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
Loading