ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.43k stars 2.8k forks source link

Is there any plan to support `workspace.workspaceEdit.resourceOperations` #4267

Open fortime opened 1 day ago

fortime commented 1 day ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

Is there any plan to support workspace.workspaceEdit.resourceOperations?

bstaletic commented 1 day ago

Hmm... so far, we have not implemented those for a mix of many reasons:

None of which are a hard "no".

Would you mind sharing a minimal example and steps that would make jdt respond with a rename operation?

puremourning commented 1 day ago

Can probably just rename a class in Java as the files have to match the class name.

fortime commented 20 hours ago

Here is the steps:

  1. Apply this patch to ycmd, commit id: 8b61f198. The commit id of YouCompleteMe is 63ab13e9.
    
    diff --git a/ycmd/completers/java/java_completer.py b/ycmd/completers/java/java_completer.py
    index 33803957..03dbc1c4 100644
    --- a/ycmd/completers/java/java_completer.py
    +++ b/ycmd/completers/java/java_completer.py
    @@ -660,3 +660,13 @@ class JavaCompleter( language_server_completer.LanguageServerCompleter ):
           *language_server_completer._LspLocationToLocationAndDescription(
             request_data, item[ 'from' ] ) )
     return result
    +
    +
    +  def ExtraCapabilities( self ):
    +    return {
    +      'workspace': {
    +        'workspaceEdit': {
    +          'resourceOperations': [ 'create', 'rename', 'delete' ],
    +        }
    +      }
    +    }
    diff --git a/ycmd/completers/language_server/language_server_completer.py b/ycmd/completers/language_server/language_server_completer.py
    index 489e15d0..ebc45b11 100644
    --- a/ycmd/completers/language_server/language_server_completer.py
    +++ b/ycmd/completers/language_server/language_server_completer.py
    @@ -3587,6 +3587,8 @@ def WorkspaceEditToFixIt( request_data,
    """Converts a LSP workspace edit to a ycmd FixIt suitable for passing to
    responses.BuildFixItResponse."""
  1. Create a maven project. The rename operation won't be returned in a single java source file.

    mvn archetype:generate -DgroupId=test -DartifactId=test-resource-op -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.5 -DinteractiveMode=false
  2. Go into the project. And open a java file with vim.

    cd test-resource-op
    vim src/main/java/test/App.java
  3. Move the cursor to the class name, and run YcmCompleter RefactorRename App1. The rename operation will appear in the log file.

BTW, there is another issue here. In WorkspaceEditToFixIt, it checks if there is changes in the response. In above case, jdt returns both changes and documentChanges, and documentChanges is being ignored.

puremourning commented 19 hours ago

BTW, there is another issue here. In WorkspaceEditToFixIt

Hardly surprising given that is only used with the capability you just added.