-
Notifications
You must be signed in to change notification settings - Fork 304
[SR-16104] SourceKit-LSP: Add support for RenameRequest #498
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
Comments
I'd like to try working on this. Would I be correct in saying it would be very similar to |
|
@ahoppen does that mean |
The SourceKit-LSP |
rdar://95587948 |
@ahoppen I was just looking at the |
Oh, you’re right. I didn’t realize we were doing an index lookup for |
Hi all, is there any new progress on this function request? |
I’m interested in trying to implement this, because I don’t use Xcode and it bothers me every day how many must-have LSP features are missing. Is anyone actively working on this already, and are there any roadblocks I should be aware of? |
I don’t think anyone is actively working on this and I can’t think of any roadblocks that I know of. @stackotter If you want to work on this, that would be great. If you’ve got any questions, don’t hesitate to ask! The comments I added last year should also still be up-to date and give you the first pointers on where to start. |
Awesome! I've started working on trying to get a very crude implementation of I'm running into an issue where It seems like all multi-file functionality just plain isn't working (cross-file code completion etc.). Not really sure how to go about fixing this. I think it's probably an issue with my development setup and mismatching versions or something? Swift toolchain: EDITI compared the build dirs of two projects (one built with 5.7 and one built with the latest dev toolchain) and it looks like the one built with the dev toolchain is missing a |
Hey @stackotter, Sorry for the delayed reply. I just double-checked and the That being said, it is odd that the index is |
Also: Could you try running SourceKit-LSP with an environment variable |
In trying to set up a reproduction case, the index stopped being nil 😅 it was probably a misconfiguration in neovim that I didn't have in VSCode. However, now I'm running into the issue of I investigated why go to definition (which also uses It's almost as if the index is empty? I'm on commit |
Could it be that you haven’t built your package yet when Could you try the following
|
I hadn't built it after the last time I cleaned it 🤦♂️ It seems that it works in VSCode now (ish). Thanks for the tips :) I can successfully get a list of all references to a given non-local symbol now (not sure of the formal word for that, I mean things that aren't local vars). For renaming of local variables I assume that I'll need to deal with the open file's AST. Annoyingly, the ranges of all of the symbols returned are wrong (the start and end locations are both just the start location of the symbol). I think VSCode doesn't like this because it completely ignores any TextEdits I return. However, I've even tried hardcoding an end index adjustment specifically for the symbol I'm attempting to rename, and it still ignores the renames. I'll look into it a bit more later this week, but if you have any insight from your experience of sourcekit-lsp internals that would be useful. It would also be handy if there was a way to inspect why the lsp client is silently ignoring the changes in the rename responses, but I don't know if there is. I've included my current rename implementation in case there's something obviously wrong func rename(
_ req: Request<RenameRequest>,
workspace: Workspace,
languageService: ToolchainLanguageServer
) {
let symbolInfo = SymbolInfoRequest(textDocument: req.params.textDocument, position: req.params.position)
let index = self.workspaceForDocument(uri: req.params.textDocument.uri)?.index
let callback = callbackOnQueue(self.queue) { (result: LSPResult<SymbolInfoRequest.Response>) in
let extractedResult = self.extractIndexedOccurrences(result: result, index: index) { (usr, index) in
let roles: SymbolRole = .all
return index.occurrences(ofUSR: usr, roles: roles)
}
let workspaceEdit: Result<WorkspaceEdit?, ResponseError> = extractedResult.map { result in
var changes: [DocumentURI: [TextEdit]] = [:]
for occurence in result {
var documentEdits = changes[occurence.location.uri] ?? []
documentEdits.append(TextEdit(
range: occurence.location.range,
newText: req.params.newName
))
changes[occurence.location.uri] = documentEdits
}
return WorkspaceEdit(
changes: changes,
documentChanges: [], // TODO: Implement file renaming when relevant?
changeAnnotation: [:]
)
}
req.reply(workspaceEdit)
}
let request = Request(symbolInfo, id: req.id, clientID: ObjectIdentifier(self),
cancellation: req.cancellationToken, reply: callback)
languageService.symbolInfo(request)
} |
That’s good to hear. I was worried something was wrong with how we build the index.
Yes, that sounds about right to me.
I think the index only contains the start location of an occurrence, not the entire range. You will need to determine the token’s range yourself. I would imagine that the easiest way to do it would be to inspect the SwiftSyntax tree (I think there should already be one available in
Looks good to me. Nothing major that jumps to my mind. |
@stackotter are you still pursuing this? |
Nah sorry, I got busy with other projects and uni, I’m happy for someone else to try, or else I might get back to it at some point. |
Looks like you are working on this now @ahoppen? I would love to build LSP to check it out, however I am having issues. Is it possible that |
Which |
I have installed the latest version of the |
You need to point the Swift VS Code extension to the open source toolchain snapshot. For example by adding the following to your "swift.path": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-01-08-a.xctoolchain/usr/bin", |
Thank you for this feature! I tested it using development snapshot and it worked 🔥 Do you know when it should be available in Xcode? I'm not sure what's the cycle? Is it going to be included in the next Xcode version? |
Rename is merged into the |
Additional Detail from JIRA
md5: 8028e8b5f474f8ce22efadde5bd6c30a
Issue Description:
Add support for RenameRequest message.
The text was updated successfully, but these errors were encountered: