-
-
Notifications
You must be signed in to change notification settings - Fork 92
feat(lsp): implement go to definition/references & rename symbol #885
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
feat(lsp): implement go to definition/references & rename symbol #885
Conversation
PR SummaryThis PR introduces core IDE-like features leveraging Language Server Protocol (LSP), including "Go to definition", "Go to references", and "Rename symbol". It enhances the Changes
autogenerated by presubmit.ai |
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.
🚨 Pull request needs attention.
Review Summary
Commits Considered (10)
- f723f32: fix(main): register text action buttons and fix huge files not loading
- f21d972: feat(main): implement definition, references and rename symbol LSP actions
- 51be902: feat(main): add dialog for displaying code items
- a66acf4: chore(main): remove unused imports
- 29e1609: fix(main): remove debug toast
- 026479a: feat(main): allow registration of text action items
- b632359: chore(resources): remove unused strings
- 73230ec: fix(main): replace close with correct discard text
- 16d2bbd: feat(resources): add icons for LSP actions
- 80db80f: fix(lsp-support): respect user theme for signature window
Files Processed (13)
- core/main/src/main/assets/supported_locales.json (1 hunk)
- core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt (3 hunks)
- core/main/src/main/java/com/rk/libcommons/editor/KarbonEditor.kt (5 hunks)
- core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt (1 hunk)
- core/main/src/main/java/com/rk/tabs/EditorTab.kt (8 hunks)
- core/main/src/main/java/com/rk/xededitor/ui/activities/main/MainContent.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/EditorSearch.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/FileActionDialog.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/FindingsDialog.kt (1 hunk)
- core/resources/src/main/res/drawable/edit_note.xml (1 hunk)
- core/resources/src/main/res/drawable/jump_to_element.xml (1 hunk)
- core/resources/src/main/res/drawable/manage_search.xml (1 hunk)
- core/resources/src/main/res/values/strings.xml (2 hunks)
Actionable Comments (2)
-
core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt [136-141]
possible bug: "Address potential NullPointerExceptions in LSP requests."
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [275-275]
possible bug: "Handle nullability when accessing workspace edit changes."
Skipped Comments (5)
-
core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt [135-142]
performance: "Avoid blocking calls on the default dispatcher."
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [68-72]
readability: "Review whitespace trimming in code snippets."
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [124-144]
maintainability: "Refactor duplicated logic for extracting definition details."
-
core/main/src/main/java/com/rk/tabs/EditorTab.kt [418-435]
possible bug: "Review LSP connection flow to ensure language is always set."
-
core/main/src/main/java/com/rk/tabs/EditorTab.kt [217-220]
maintainability: "Remove redundant error check for rename input."
| lspEditor!!.languageServerWrapper.requestManager!!.definition( | ||
| DefinitionParams( | ||
| TextDocumentIdentifier(fileObject!!.getAbsolutePath()), | ||
| Position(editor.cursor.leftLine, editor.cursor.leftColumn) | ||
| ) | ||
| )!!.get(Timeout[Timeouts.EXECUTE_COMMAND].toLong(), TimeUnit.MILLISECONDS) |
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.
The use of the !! operator on lspEditor and languageServerWrapper.requestManager assumes these objects are never null after connect is called. While connect is intended to initialize lspEditor, there might be edge cases (e.g., connection failure, disposeAsync being called) where they could be null, leading to a NullPointerException. Consider handling nullability explicitly, perhaps by returning a nullable type or throwing a more specific exception if the LSP connection is not ready.
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.
This method won't be called if there was a language server connection failure.
| return@launch | ||
| } | ||
|
|
||
| val edits = changes[file.toUri().toString()]!! |
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.
The line val edits = changes[file.toUri().toString()]!! assumes that changes will always contain an entry for the current file's URI. If changes is empty or the current file's URI is not a key, this will result in a NullPointerException. A safer approach would be to use changes[file.toUri().toString()]?.let { ... } or check for its existence before force-unwrapping.
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.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- a52b165: fix(main): replace hardcoded string with XML resource
Files Processed (13)
- core/main/src/main/assets/supported_locales.json (1 hunk)
- core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt (3 hunks)
- core/main/src/main/java/com/rk/libcommons/editor/KarbonEditor.kt (5 hunks)
- core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt (1 hunk)
- core/main/src/main/java/com/rk/tabs/EditorTab.kt (8 hunks)
- core/main/src/main/java/com/rk/xededitor/ui/activities/main/MainContent.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/EditorSearch.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/FileActionDialog.kt (1 hunk)
- core/main/src/main/java/com/rk/xededitor/ui/components/FindingsDialog.kt (1 hunk)
- core/resources/src/main/res/drawable/edit_note.xml (1 hunk)
- core/resources/src/main/res/drawable/jump_to_element.xml (1 hunk)
- core/resources/src/main/res/drawable/manage_search.xml (1 hunk)
- core/resources/src/main/res/values/strings.xml (2 hunks)
Actionable Comments (4)
-
core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt [136-141]
possible bug: "Potential NullPointerException in LSP requests"
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [114-114]
possible bug: "Potential NullPointerException in LSP action"
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [269-274]
possible bug: "Potential NullPointerException when applying workspace edits"
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [275-278]
possible bug: "Unsafe null assertion in event emission"
Skipped Comments (3)
-
core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt [141-141]
performance: "Blocking call with timeout in LSP request"
-
core/main/src/main/java/com/rk/libcommons/editor/LspActions.kt [290-290]
maintainability: "Missing newline at end of file"
-
core/main/src/main/java/com/rk/tabs/EditorTab.kt [217-218]
maintainability: "Redundant blank check for rename value"
| lspEditor!!.languageServerWrapper.requestManager!!.definition( | ||
| DefinitionParams( | ||
| TextDocumentIdentifier(fileObject!!.getAbsolutePath()), | ||
| Position(editor.cursor.leftLine, editor.cursor.leftColumn) | ||
| ) | ||
| )!!.get(Timeout[Timeouts.EXECUTE_COMMAND].toLong(), TimeUnit.MILLISECONDS) |
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.
The use of lspEditor!! and languageServerWrapper.requestManager!! assumes these objects are never null. While connect is intended to initialize lspEditor, there might be edge cases where they could be null, leading to a NullPointerException. Consider handling nullability explicitly, perhaps by returning a nullable type or throwing a more specific exception if the LSP connection is not ready. This applies to all request* methods.
| ) { editor -> | ||
| scope.launch(Dispatchers.Default) { | ||
| runCatching { | ||
| val eitherDefinitions = baseLspConnectorProvider()!!.requestDefinition(editor) |
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.
The baseLspConnectorProvider()!! call here can lead to a NullPointerException if the provider returns null. Although shouldShow checks for true, the action block itself doesn't re-verify or handle the null case. It's safer to use a nullable check or a let block to ensure baseLspConnector is not null before proceeding.
| if (changes.size > 1) { | ||
| toast(strings.rename_symbol_multiple_files) | ||
| return@launch | ||
| } | ||
|
|
||
| val edits = changes[file.toUri().toString()]!! |
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.
The line val edits = changes[file.toUri().toString()]!! assumes that changes will always contain an entry for the current file's URI. If changes is empty or the current file's URI is not a key, this will result in a NullPointerException. A safer approach would be to use changes[file.toUri().toString()]?.let { ... } or check for its existence before force-unwrapping. The if (changes.size > 1) check is a limitation, but the !! is a direct bug.
| baseLspConnectorProvider()!!.getEventManager()!!.emitAsync(EventType.applyEdits) { | ||
| put("edits", edits) | ||
| put(editor.text) | ||
| } |
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.
Similar to other !! usages, baseLspConnectorProvider()!!.getEventManager()!! can cause a NullPointerException if either baseLspConnectorProvider() or getEventManager() returns null. It's important to handle these nullability cases explicitly to prevent crashes.
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.
✅ LGTM!
Review Summary
Commits Considered (1)
- e3cec89: fix(soraX): soraX changes
Files Processed (1)
- soraX (1 hunk)
Actionable Comments (0)
Skipped Comments (0)
This reverts commit e3cec89.
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.
This PR adds IDE-like features such as
Go to definition,Go to referencesorRename symboland fixes several issues.Changes
sora-editorCompletableDeferred<Unit>())Discardinstead of undescriptiveClose)Current limitations & issues
DocumentChangesis not yet supported intextDocument/rename(Shouldn't be important for renaming symbols)applyEditsshould revert all edits in one step Rosemoe/sora-editor#722)Caution
In the
BaseLspConnector.ktwe currently create a newLspProjectfor every single file. I'm pretty sure though that multiple files should share the sameLspProjectbecause otherwise the language server might not be able to handle e.g. rename symbol actions across different files. This is just a guess. Reference:https://github.com/Xed-Editor/Xed-Editor/blob/3f7dbb4a909d9877e4c299da50b12c847565f941/core/main/src/main/java/com/rk/libcommons/editor/BaseLspConnector.kt#L58C13-L58C64