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
Implement completionItem/resolve
#432
base: main
Are you sure you want to change the base?
Conversation
completionItem/resolve
.completionItem/resolve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for looking into this @LebJe. I’ll need to look into why sourcektid
doesn’t return cursor info for the USR. Maybe @benlangmuir has an idea if this is something that’s supported or what might be going wrong here from the top of his head.
For now, I’ve added some comments inline.
{ | ||
return TextDocumentIdentifier(DocumentURI(string: textDocURI)) | ||
} else { | ||
fatalError("Missing textDocURI in CompletionItem.data: \(data ?? "(CompletionItem.data is nil)")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we should make any assumptions about the requests sent to us by the client and, in particular, not crash if it is malformed. Could we return a failure value (e.g.nil
) here instead of fatalError
ing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is TextDocumentIdentifier(DocumentURI(string: ""))
ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are not using this computed property at all, so let’s just remove it.
Sources/LanguageServerProtocol/SupportTypes/CompletionItem.swift
Outdated
Show resolved
Hide resolved
Sources/LanguageServerProtocol/SupportTypes/CompletionItem.swift
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
public static var method: String = "completionItem/resolve" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the method
property is always the first property in a request type. Could you move it up to match this style?
Cursor info on USRs only works on a subset of USRs for nominal types IIRC. Please don't use this functionality. We should never have added it. The way I would implement this would be
|
@benlangmuir, are you saying I should:
With this approach though, it is still impossible to get full documentation. Is there something I'm not noticing in the
Was the implementation never finished, or is something causing cursor info via USRs on things other than nominal types to not work? |
{ | ||
return TextDocumentIdentifier(DocumentURI(string: textDocURI)) | ||
} else { | ||
fatalError("Missing textDocURI in CompletionItem.data: \(data ?? "(CompletionItem.data is nil)")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are not using this computed property at all, so let’s just remove it.
@@ -169,18 +169,23 @@ extension SwiftLanguageServer { | |||
// Map SourceKit's not_recommended field to LSP's deprecated | |||
let notRecommended = (value[self.keys.not_recommended] as Int?).map({ $0 != 0 }) | |||
|
|||
let kind: sourcekitd_uid_t? = value[self.keys.kind] | |||
let kind = (value[self.keys.kind] as sourcekitd_uid_t?)?.asCompletionItemKind(self.values) ?? .value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you need to refactor kind
anymore? I think the previous version read better 😉
@@ -169,18 +169,23 @@ extension SwiftLanguageServer { | |||
// Map SourceKit's not_recommended field to LSP's deprecated | |||
let notRecommended = (value[self.keys.not_recommended] as Int?).map({ $0 != 0 }) | |||
|
|||
let kind: sourcekitd_uid_t? = value[self.keys.kind] | |||
let kind = (value[self.keys.kind] as sourcekitd_uid_t?)?.asCompletionItemKind(self.values) ?? .value | |||
var data: [String: LSPAny] = ["textDocURI": .string(snapshot.document.uri.stringValue)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to define the magic "textDocURI"
string as a static property on CompletionItem
instead of repeating it throughout the codebase? IIUC it’s not part of the LSP standard but just a key that you’re using for the opaque data
dictionary.
Same for "usr"
Something along these lines is what I had in mind for an initial implementation, but I haven't thought through the details of whether it makes sense to clear it vs. extend the data, etc.
No, that's correct in the current API. We should separate out two possible goals here:
I'm not sure one way or the other whether that second item is a good idea -- it's certainly reasonable to ask for the full documentation of a completion item, but doing so _by default using the existing API _ is more a question of how it corresponds to what LSP editors are expecting. If we do want to return the full documentation, I think a better foundation for that is looking up information from a code-completion item in the current session, and potentially adding more lazy APIs to support that in sourcekitd, rather than via cursor info with a USR. CC @rintaro
It was never properly implemented. I think there were some partial attempts to extend it, but they were unmaintainable and later removed. |
This pull request adds support for
completionItem/resolve
to SourceKit-LSP.Unfortunately, the tests are disabled (and this PR is a draft) because SourceKit cannot provide
cursorinfo
via an USR for anything other than things likestruct
s:Test Code:
To test the above code, type something like
E.a
, orA.init
, and see if the `` is rendered as a code block in the completion popup.Perhaps this is related to this issue.