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: lsp bugs #579

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -85,9 +85,16 @@ open class SignatureHelpWindow(editor: CodeEditor) : EditorPopupWindow(

open fun show(signatureHelp: SignatureHelp) {
this.signatureHelp = signatureHelp
renderSignatureHelp()
updateWindowSizeAndLocation()
show()

if (signatureHelp.activeSignature != null && signatureHelp.activeParameter != null) {
renderSignatureHelp()
updateWindowSizeAndLocation()
show()
} else {
Log.d("SignatureHelpWindow", "activeSignature or activeParameter is null")
return
}

}


Expand Down Expand Up @@ -132,6 +139,7 @@ open class SignatureHelpWindow(editor: CodeEditor) : EditorPopupWindow(

val activeSignatureIndex = signatureHelp.activeSignature
val activeParameterIndex = signatureHelp.activeParameter

val signatures = signatureHelp.signatures

val renderStringBuilder = SpannableStringBuilder()
Expand All @@ -145,6 +153,8 @@ open class SignatureHelpWindow(editor: CodeEditor) : EditorPopupWindow(
Log.d("SignatureHelpWindow", "activeSignature is out of range")
return
}



// Get only the activated signature
for (i in 0..activeSignatureIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,33 @@ class ApplyEditsEvent : EventListener {
override val eventName: String = "textDocument/applyEdits"

override fun handle(context: EventContext) {
val editList: List<TextEdit> = context.get("edits")
val editList: List<ArrayList<TextEdit>> = context.get("edits")
val content = context.getByClass<Content>() ?: return

editList.forEach { textEdit: TextEdit ->
val range = textEdit.range
val text = textEdit.newText
var startIndex =
content.getCharIndex(range.start.line, range.start.character)
var endIndex =
content.getCharIndex(range.end.line, range.end.character)
if (endIndex < startIndex) {
Logger.instance(this.javaClass.name)
.w(
"Invalid location information found applying edits from %s to %s",
range.start,
range.end
)
val diff = startIndex - endIndex
endIndex = startIndex
startIndex = endIndex - diff
editList.forEach { list: ArrayList<TextEdit> ->
Copy link
Contributor

@dingyi222666 dingyi222666 Apr 3, 2024

Choose a reason for hiding this comment

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

No changes needed here. Consider modifying completionItem.additionalTextEdits at

to remove listOf, and then test to see if it works properly.

list.forEach { textEdit : TextEdit ->
val range = textEdit.range
val text = textEdit.newText
var startIndex =
content.getCharIndex(range.start.line, range.start.character)
var endIndex =
content.getCharIndex(range.end.line, range.end.character)
if (endIndex < startIndex) {
Logger.instance(this.javaClass.name)
.w(
"Invalid location information found applying edits from %s to %s",
range.start,
range.end
)
val diff = startIndex - endIndex
endIndex = startIndex
startIndex = endIndex - diff
}
content.replace(startIndex, endIndex, text)
}
content.replace(startIndex, endIndex, text)
}
}


}

val EventType.applyEdits: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ class DocumentChangeEvent : AsyncEventListener() {
editor: LspEditor,
data: ContentChangeEvent
): List<TextDocumentContentChangeEvent> {
val text = data.changedText.toString()
val text = data.editor.text.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not comply with the LSP specification; what is required here is text for an incremental change. Please clarify why there is a need to modify this part, and if possible, provide a project that can reproduce the related bug. I will look into it.

return listOf(
editor.uri.createTextDocumentContentChangeEvent(
createRange(
data.changeStart,
data.changeEnd
),
if (data.action == ContentChangeEvent.ACTION_DELETE) "" else text
)
)
Expand Down