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

Sourcekit-LSP stops working after a cancel of completion #1890

Open
angelozerr opened this issue Dec 15, 2024 · 5 comments
Open

Sourcekit-LSP stops working after a cancel of completion #1890

angelozerr opened this issue Dec 15, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@angelozerr
Copy link

Swift version

Last

Platform

Windows 11

Editor

LSP4IJ (Free LSP support for IJ)

Description

Hi,

I contact you because I'm trying to consume Sourcekit-LSP with LSP4IJ a free LSP support for IntelliJ.

If you want to test it, please read https://github.com/redhat-developer/lsp4ij/blob/main/docs/user-defined-ls/sourcekit-lsp.md after installing LSP4IJ

All features are working pretty well (hover, highlight, semantic tokens, call hierarchy, etc) except completion. Completion is working pretty well if you type characters in the editor slowly, but as soon as you are typing quickly in the editor, the Sourcekit-LSP breaks all LSP features (no highlight, no hover, no completion, etc).

Please note that all language servers that I have tested like Go, Rust, etc are working pretty well. First I though it was a problem with didChange, but I send the same didChange notification than vscode.

After spending a lot of time to discover the usecase which causes the problem, I have noticed that this problem occurs when completion is cancelled.

As soon as I am typing quickly in the editor, it send cancelRequest for completion and after that the Sourcekit-LSP is down (it gives me some response but with cancel and not only for completion, for highlight, hover etc).

It have the impression that I have the similar problem than Emacs-LSP emacs-lsp/lsp-mode#3028 but I find it is very strange to kill the Sourcekit-LSP when LSP client cancels the completion.

I have the impression that I don't send the proper triggerChars for completion after completion is cancelled. Perhaps I need to set triggerChars to 3 when completion is canceled but I have no problem with other LSP language servers?

I wanted just to share my problem.

Any help are welcome! Thanks!

Steps to Reproduce

No response

Logging

No response

@angelozerr angelozerr added the bug Something isn't working label Dec 15, 2024
@ahoppen
Copy link
Member

ahoppen commented Dec 15, 2024

Synced to Apple’s issue tracker as rdar://141508699

@ahoppen
Copy link
Member

ahoppen commented Dec 15, 2024

Thanks for the report, @angelozerr. Which version of SourceKit-LSP are you using? If you're using a Swift development snapshot, there was an issue with cancellation that sound similar and which I fixed recently (#1857).

If that's not it, could you run sourcekit-lsp diagnose and attach the diagnostics bundle to this issue? That should help us determine what's going wrong.

@angelozerr
Copy link
Author

angelozerr commented Dec 16, 2024

Which version of SourceKit-LSP are you using?

Swift version 6.0.2 (swift-6.0.2-RELEASE)
Target: x86_64-unknown-windows-msvc

First here my simple test. I have in my project just this file and I'm trying to open completion after name.:

var name = ""
name.

If I open completion slowly, it works great. If I write quickly some character after name. there is a cancelRequest (done by IntelliJ LSP client when completion is not relevant) and after that SourceKit-LSP is down.

Here the generated file with sourcekit-lsp diagnose:

sourcekit-lsp-32248.0.log

This diagnose is very strange because we have the impression that everything is working pretty well, but it is not true.

Here the LSP traces that I have in my IntelliJ LSP console:

lsp-traces.txt

If you see my LSP trace, completion is working upon the (8) completion request which report a cancel:

[Trace - 16:06:41] Sending request 'textDocument/completion - (8)'.
Params: {
  "context": {
    "triggerKind": 2,
    "triggerCharacter": "."
  },
  "textDocument": {
    "uri": "file:///C:/Users/azerr/IdeaProjects/untitled13/test.swift"
  },
  "position": {
    "line": 1,
    "character": 5
  }
}


[Trace - 16:06:41] Sending notification '$/cancelRequest'
Params: {
  "id": "8"
}

And after that if I reopen completion, there are none LSP response of textDocument/completion although in the diagnose there are some LSP response?

After debugging the LSP client, it seems that SourceKit-LSP doesn't write any response in the input stream. We can send request but there are no answer from the SourceKit-LSP language server although the SourceKit-LSP process is alive?

The diagnose displays a response of the 9 request:

---[org.swift.sourcekit-lsp:request-9] default 2024-12-16 14:00:28.4370 +0000
Received request "9": textDocument/completion
{
  "context" : {
    "triggerCharacter" : ".",
    "triggerKind" : 2
  },
  "position" : {
    "character" : 5,
    "line" : 1
  },
  "textDocument" : {
    "uri" : "file:///C:/Users/azerr/IdeaProjects/untitled13/test.swift"
  }
}
---[org.swift.sourcekit-lsp:request-9] default 2024-12-16 14:00:28.8400 +0000
Succeeded (took 402.39715576171875ms)
textDocument/completion
CompletionList
{
  "isIncomplete" : true,
  "items" : [
    {
      "deprecated" : false,
      "detail" : "Void",
      "documentation" : {
        "kind" : "markdown",
        "value" : "Appends the given character to the string."
      },
      "filterText" : "append(:)",
      "insertText" : "append(${1:Character})",
      "insertTextFormat" : 2,
      "kind" : 2,
      "label" : "append(c: Character)",
      "textEdit" : {
        "newText" : "append(${1:Character})",
        "range" : {
          "end" : {
            "character" : 5,
            "line" : 1
          },
          "start" : {
            "character" : 5,
            "line" : 1
          }
        }
      }
    },

and in my LSP trace you can see just:

[Trace - 16:06:41] Sending request 'textDocument/completion - (9)'.
Params: {
  "context": {
    "triggerKind": 1
  },
  "textDocument": {
    "uri": "file:///C:/Users/azerr/IdeaProjects/untitled13/test.swift"
  },
  "position": {
    "line": 1,
    "character": 6
  }
}

without response.

Please note that you can see a cancel of request 9:

[Trace - 16:06:41] Sending notification '$/cancelRequest'
Params: {
  "id": "9"
}

but this cancel occurs when completion is closed (I'm waiting for some times before closing it).

@ahoppen
Copy link
Member

ahoppen commented Dec 19, 2024

Oh, I suppose the cancellation of the code completion request somehow gets the code completion session that SourceKit-LSP maintains with sourcekitd in an invalid state. I can debug this in the new year.

@angelozerr
Copy link
Author

Thanks so much @ahoppen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants