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: only use optionalReplacementSpan if client supports InsertReplace #584

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

rchl
Copy link
Member

@rchl rchl commented Sep 10, 2022

@@ -63,7 +63,7 @@ export function asCompletionItem(entry: tsp.CompletionEntry, optionalReplacement
}

let insertText = entry.insertText;
const replacementSpan = entry.replacementSpan || optionalReplacementSpan;
const replacementSpan = entry.replacementSpan || (features.completionInsertReplaceSupport ? optionalReplacementSpan : undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest removing unnecessary code bellow:

- const replacementSpan = entry.replacementSpan || (features.completionInsertReplaceSupport ? optionalReplacementSpan : undefined);
+ const replacementSpan = entry.replacementSpan || optionalReplacementSpan;

...

- if (replacementRange) {
+ if (replacementRange && features.completionInsertReplaceSupport) {
    if (!insertText) {
        insertText = item.label;
    }
-    if (features.completionInsertReplaceSupport) {
      const insertRange = lsp.Range.create(replacementRange.start, position);
      item.textEdit = lsp.InsertReplaceEdit.create(insertText, insertRange, replacementRange);
-    } else {
-        item.textEdit = lsp.TextEdit.replace(replacementRange, insertText);
-    }
} else {
    item.insertText = insertText;
}

Copy link
Member Author

@rchl rchl Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound right. The replacementRange can also come from the entry.replacementSpan itself in which case we want to create a replace TextEdit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, you are right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try out this PR tomorrow.

@predragnikolic
Copy link
Contributor

Just to document that this PR addresses this comment #583 (comment)

Copy link
Contributor

@predragnikolic predragnikolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can verify that this PR brings back the same behavior as prior to InsertReplaceSupport for servers that do not have insertReplaceSupport.

@rchl rchl merged commit 899ba6b into master Sep 12, 2022
@rchl rchl deleted the fix/completion-replace branch September 12, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants