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

lsp-sourcekit can't get complete candidates #18

Open
stardiviner opened this issue May 26, 2021 · 8 comments
Open

lsp-sourcekit can't get complete candidates #18

stardiviner opened this issue May 26, 2021 · 8 comments

Comments

@stardiviner
Copy link

company-mode displays error in minibuffer:

Company: An error occurred in auto-begin
Company: backend company-capf error "request cancelled" with args (candidates let)

Then I enabled lsp-mode debug with:

(setq lsp-log-io t
      lsp-print-io t)

In buffer *lsp-log: sourcekit-ls:55049*:

[Trace - 05:53:52 PM] Received response 'textDocument/codeAction - (53)' in 28ms.
Result: []


[Trace - 05:53:58 PM] Sending request 'textDocument/codeAction - (54)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "range": {
    "start": {
      "line": 8,
      "character": 0
    },
    "end": {
      "line": 8,
      "character": 0
    }
  },
  "context": {
    "diagnostics": []
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/codeAction - (54)' in 22ms.
Result: []


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 54
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 0
        },
        "end": {
          "line": 8,
          "character": 0
        }
      },
      "rangeLength": 0,
      "text": "l"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [],
  "version": 54,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'l' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 54,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 55
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 1
        },
        "end": {
          "line": 8,
          "character": 1
        }
      },
      "rangeLength": 0,
      "text": "e"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'l' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 55,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'le' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 55,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 56
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 2
        },
        "end": {
          "line": 8,
          "character": 2
        }
      },
      "rangeLength": 0,
      "text": "t"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'le' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 56,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    }
  ],
  "version": 56,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending request 'textDocument/completion - (55)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "position": {
    "line": 8,
    "character": 3
  },
  "context": {
    "triggerKind": 3
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/completion - (55)' in 2ms.
Result: {
  "code": -32800,
  "message": "request cancelled"
}


[Trace - 05:53:58 PM] Sending request 'textDocument/completion - (56)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "position": {
    "line": 8,
    "character": 3
  },
  "context": {
    "triggerKind": 3
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/completion - (56)' in 42ms.
Result: {
  "code": -32800,
  "message": "request cancelled"
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 57
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 0
        },
        "end": {
          "line": 8,
          "character": 3
        }
      },
      "rangeLength": 3,
      "text": ""
    }
  ]
}


[Trace - 05:54:00 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    }
  ],
  "version": 57,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:54:00 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [],
  "version": 57,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/willSave'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "reason": 1
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/didSave'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 57
  }
}
@rksm
Copy link

rksm commented Jul 23, 2021

Running into the same problem.

The problem seems to be with lsp-completion--get-context that is used as a parameter to the completion request. For whatever reason, lsp-completion--cache gets set with an incomplete marker. The context sets specific :trigger-kind in this case which seems to break the completions.

Unfortunately, just deactivating caching with (setq lsp-completion-no-cache 't) doesn't seem to be enough, the :incomplete marker is still set.

So the quick'n dirty hack that might very well break other things:

(defun sourcekit-lsp-completion-fix (method &rest args)
  "Quick'n dirty fix for https://github.com/emacs-lsp/lsp-sourcekit/issues/18"
  (when (and (eq major-mode 'swift-mode) (string-equal method "textDocument/completion"))
    (message "%s" method)
    (lsp-completion--clear-cache)))

(advice-add 'lsp-request :before 'sourcekit-lsp-completion-fix)

@stardiviner
Copy link
Author

@rksm Hi, thanks for diving into the problem. I tried your method. Still have problem.
When lsp-sourcekit completing, got error Company: backend company-capf error "request cancelled" with args (candidates hel).

I enabled the lsp log, but have not got special output.

I guess current latest version company-capf incompatible with lsp-sourcekit or lsp-mode.

@wibed
Copy link

wibed commented Sep 7, 2021

emacs-lsp/lsp-mode#3028

and

#20

seem to be related to this issue. i too had no luck clearing the cache or disabling it for company
as company still would block containing the cancel error

@stardiviner have you found a workaround?

@stardiviner
Copy link
Author

I still don't got a solution. sorry @wibed

@wibed
Copy link

wibed commented Sep 8, 2021

emacs-lsp/lsp-mode#2970

this issue with pr seems related to the problem

@stardiviner
Copy link
Author

After overview this issue, seems still no good solution yet. Temporary typing code literally.

@wibed
Copy link

wibed commented Sep 9, 2021

@stardiviner over at emacs-lsp/lsp-mode#3028 the actual problem has been stated

@stardiviner
Copy link
Author

Glad the patch pr will coming soon. Thanks for your effort on this issue. 😄

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

No branches or pull requests

3 participants