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

Bump JDT.ls version to 1.31.0 #1727

Merged
merged 3 commits into from Jan 16, 2024
Merged

Bump JDT.ls version to 1.31.0 #1727

merged 3 commits into from Jan 16, 2024

Conversation

tonitch
Copy link
Contributor

@tonitch tonitch commented Jan 13, 2024

Change version of jdt.ls from 1.26.0 to 1.31.0

Adding support to java 21


This change is Reviewable

@bstaletic
Copy link
Collaborator

This should solve the GoTo tests:

diff --git a/ycmd/tests/java/subcommands_test.py b/ycmd/tests/java/subcommands_test.py
index 02af0ae03..39fed0c0b 100644
--- a/ycmd/tests/java/subcommands_test.py
+++ b/ycmd/tests/java/subcommands_test.py
@@ -537,6 +537,37 @@ class SubcommandsTest( TestCase ):
                  ErrorMatcher( RuntimeError, 'Unknown type' ) )
 
 
+  @SharedYcmd
+  def test_Subcommands_GoToDeclaration_NoLocation( self, app ):
+    filepath = PathToTestFile( 'simple_eclipse_project',
+                               'src',
+                               'com',
+                               'test',
+                               'TestLauncher.java' )
+    contents = ReadFile( filepath )
+
+    # Virtual call of getWidgetInfo - don't know the concrete implementation.
+    # Here GoToDefinition jumps to the interface method declaration and
+    # GoToDeclaration does nothing...
+    event_data = BuildRequest( filepath = filepath,
+                               filetype = 'java',
+                               line_num = 34,
+                               column_num = 59,
+                               contents = contents,
+                               command_arguments = [ 'GoToDeclaration' ],
+                               completer_target = 'filetype_default' )
+
+    response = app.post_json( '/run_completer_command',
+                              event_data,
+                              expect_errors = True )
+
+    assert_that( response.status_code,
+                 equal_to( requests.codes.internal_server_error ) )
+
+    assert_that( response.json,
+                 ErrorMatcher( RuntimeError, 'Cannot jump to location' ) )
+
+
   @WithRetry()
   @SharedYcmd
   def test_Subcommands_GoTo_NoLocation( self, app ):
@@ -2012,7 +2043,7 @@ class SubcommandsTest( TestCase ):
                         'filepath': TEST_JAVA },
           'description': 'GoTo works for unicode identifiers' }
       ],
-      [ 'GoTo', 'GoToDefinition', 'GoToDeclaration' ] ):
+      [ 'GoTo', 'GoToDefinition' ] ):
       with self.subTest( command = command, test = test ):
         RunGoToTest( app,
                      test[ 'description' ],
@@ -2023,6 +2054,31 @@ class SubcommandsTest( TestCase ):
                      has_entries( test[ 'response' ] ) )
 
 
+  @SharedYcmd
+  def test_Subcommands_GoToDeclaration( self, app ):
+    source = PathToTestFile( 'simple_eclipse_project',
+                             'src',
+                             'com',
+                             'test',
+                             'TestWidgetImpl.java' )
+    destination = PathToTestFile( 'simple_eclipse_project',
+                                  'src',
+                                  'com',
+                                  'test',
+                                  'AbstractTestWidget.java' )
+    # Seems to be the only place GoToDeclaration actually works.
+    RunGoToTest( app,
+                 'GoToDeclaration works on an override definition.',
+                 source,
+                 23,
+                 17,
+                 'GoToDeclaration',
+                 has_entries( {
+                   'line_num': 17,
+                   'column_num': 17,
+                   'filepath': destination } ) )
+
+
   @SharedYcmd
   def test_Subcommands_GoToType( self, app ):
     for test in [

@bstaletic
Copy link
Collaborator

And here's the diff for all the failing tests:

diff --git a/ycmd/tests/java/subcommands_test.py b/ycmd/tests/java/subcommands_test.py
index 02af0ae03..d31657b26 100644
--- a/ycmd/tests/java/subcommands_test.py
+++ b/ycmd/tests/java/subcommands_test.py
@@ -537,6 +537,37 @@ class SubcommandsTest( TestCase ):
                  ErrorMatcher( RuntimeError, 'Unknown type' ) )
 
 
+  @SharedYcmd
+  def test_Subcommands_GoToDeclaration_NoLocation( self, app ):
+    filepath = PathToTestFile( 'simple_eclipse_project',
+                               'src',
+                               'com',
+                               'test',
+                               'TestLauncher.java' )
+    contents = ReadFile( filepath )
+
+    # Virtual call of getWidgetInfo - don't know the concrete implementation.
+    # Here GoToDefinition jumps to the interface method declaration and
+    # GoToDeclaration does nothing...
+    event_data = BuildRequest( filepath = filepath,
+                               filetype = 'java',
+                               line_num = 34,
+                               column_num = 59,
+                               contents = contents,
+                               command_arguments = [ 'GoToDeclaration' ],
+                               completer_target = 'filetype_default' )
+
+    response = app.post_json( '/run_completer_command',
+                              event_data,
+                              expect_errors = True )
+
+    assert_that( response.status_code,
+                 equal_to( requests.codes.internal_server_error ) )
+
+    assert_that( response.json,
+                 ErrorMatcher( RuntimeError, 'Cannot jump to location' ) )
+
+
   @WithRetry()
   @SharedYcmd
   def test_Subcommands_GoTo_NoLocation( self, app ):
@@ -1020,9 +1051,11 @@ class SubcommandsTest( TestCase ):
               'text': "Create constant 'Wibble'",
               'kind': 'quickfix',
               'chunks': contains_exactly(
-                ChunkMatcher( '\n\nprivate static final String Wibble = null;',
+                ChunkMatcher( '\n\nprivate static final String Wibble = null;'
+                              '\n\n  private void Wimble( Wibble w ) {'
+                              '\n    if ( w == Wibble',
                               LocationMatcher( filepath, 16, 4 ),
-                              LocationMatcher( filepath, 16, 4 ) ),
+                              LocationMatcher( filepath, 19, 21 ) ),
               ),
             } ),
             has_entries( {
@@ -1056,27 +1089,29 @@ class SubcommandsTest( TestCase ):
               'text': "Create local variable 'Wibble'",
               'kind': 'quickfix',
               'chunks': contains_exactly(
-                ChunkMatcher( 'Object Wibble;\n    ',
+                ChunkMatcher( 'Object Wibble;\n    if ( w == Wibble',
                               LocationMatcher( filepath, 19, 5 ),
-                              LocationMatcher( filepath, 19, 5 ) ),
+                              LocationMatcher( filepath, 19, 21 ) ),
               ),
             } ),
             has_entries( {
               'text': "Create field 'Wibble'",
               'kind': 'quickfix',
               'chunks': contains_exactly(
-                ChunkMatcher( '\n\nprivate Object Wibble;',
+                ChunkMatcher( '\n\nprivate Object Wibble;'
+                              '\n\n  private void Wimble( Wibble w ) {'
+                              '\n    if ( w == Wibble',
                               LocationMatcher( filepath, 16, 4 ),
-                              LocationMatcher( filepath, 16, 4 ) ),
+                              LocationMatcher( filepath, 19, 21 ) ),
               ),
             } ),
             has_entries( {
               'text': "Create parameter 'Wibble'",
               'kind': 'quickfix',
               'chunks': contains_exactly(
-                ChunkMatcher( ', Object Wibble',
+                ChunkMatcher( ', Object Wibble ) {\n    if ( w == Wibble',
                               LocationMatcher( filepath, 18, 32 ),
-                              LocationMatcher( filepath, 18, 32 ) ),
+                              LocationMatcher( filepath, 19, 21 ) ),
               ),
             } ),
             has_entries( {
@@ -1485,6 +1520,10 @@ class SubcommandsTest( TestCase ):
             has_entries( {
               'text': "Sort Members for 'TestLauncher.java'"
             } ),
+            has_entries( {
+              'text': 'Surround with try/catch',
+              'chunks': instance_of( list )
+            } ),
           )
         } )
       }
@@ -1545,8 +1584,17 @@ class SubcommandsTest( TestCase ):
           'text': "Create method 'doUnicødeTes(String)'",
           'kind': 'quickfix',
           'chunks': contains_exactly(
-            ChunkMatcher( 'private void doUnicødeTes(String test2) {\n}\n\n\n',
-                          LocationMatcher( TEST_JAVA, 20, 3 ),
+            ChunkMatcher(
+              'doUnicødeTes( test );\n\n'
+              '    TéstClass tésting_with_unicøde = new TéstClass();\n'
+              '    return tésting_with_unicøde.a_test;\n'
+              '  }\n\n\n'
+              '  private void doUnicødeTes(String test2) {\n'
+              '    // TODO Auto-generated method stub\n'
+              '    throw new UnsupportedOperationException('
+              '"Unimplemented method \'doUnicødeTes\'");\n'
+              '}\n\n\n',
+                          LocationMatcher( TEST_JAVA, 13, 10 ),
                           LocationMatcher( TEST_JAVA, 20, 3 ) ),
           ),
         } ),
@@ -2012,7 +2060,7 @@ class SubcommandsTest( TestCase ):
                         'filepath': TEST_JAVA },
           'description': 'GoTo works for unicode identifiers' }
       ],
-      [ 'GoTo', 'GoToDefinition', 'GoToDeclaration' ] ):
+      [ 'GoTo', 'GoToDefinition' ] ):
       with self.subTest( command = command, test = test ):
         RunGoToTest( app,
                      test[ 'description' ],
@@ -2023,6 +2071,31 @@ class SubcommandsTest( TestCase ):
                      has_entries( test[ 'response' ] ) )
 
 
+  @SharedYcmd
+  def test_Subcommands_GoToDeclaration( self, app ):
+    source = PathToTestFile( 'simple_eclipse_project',
+                             'src',
+                             'com',
+                             'test',
+                             'TestWidgetImpl.java' )
+    destination = PathToTestFile( 'simple_eclipse_project',
+                                  'src',
+                                  'com',
+                                  'test',
+                                  'AbstractTestWidget.java' )
+    # Seems to be the only place GoToDeclaration actually works.
+    RunGoToTest( app,
+                 'GoToDeclaration works on an override definition.',
+                 source,
+                 23,
+                 17,
+                 'GoToDeclaration',
+                 has_entries( {
+                   'line_num': 17,
+                   'column_num': 17,
+                   'filepath': destination } ) )
+
+
   @SharedYcmd
   def test_Subcommands_GoToType( self, app ):
     for test in [

@bstaletic
Copy link
Collaborator

The last test failure is fixed by this commit: bstaletic@3b72abc

@tonitch Feel free to cherry-pick that commit.
@puremourning I don't think I've introduced any regressions, but a second pair of eyes would not hurt.

@puremourning
Copy link
Member

The last test failure is fixed by this commit: bstaletic@3b72abc

change LGTM. if the tests pass then I'm happy to assume no regressions :)

Copy link

codecov bot commented Jan 14, 2024

Codecov Report

Merging #1727 (47e3431) into master (b34008a) will decrease coverage by 0.04%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1727      +/-   ##
==========================================
- Coverage   95.47%   95.44%   -0.04%     
==========================================
  Files          83       83              
  Lines        8177     8159      -18     
  Branches      163      163              
==========================================
- Hits         7807     7787      -20     
- Misses        320      322       +2     
  Partials       50       50              

tonitch and others added 3 commits January 16, 2024 14:06
Adding support to java 21
Fixed-By: @bstaletic
Related: #1727
The GoTo subcommand might have multiple LSP handlers associated with it.
Mostly, it is `textDocument/definition` and `textDocument/declaration`.

Normally, we cycle through handlers until one of two things happens:

1. The handler returns more than one location.
2. The handler returns a single location, but that doese not contain the
   cursor.

This breaks if any of the handlers throws an exception. When that
happens, we immediately propagate the error, instead of trying the next
handler. However, we can not simply swallow exceptions, because there's
a possibility for all handlers to throw. Or some throws and some return
zero locations.

Current idea:

1. Do not throw as soon as a handler reports zero locations.
2. If the current handler returns more than a single location, replace
   previous result with the current one.
3. If there's more than one location or the single location does not
   contain cursor, break out of the loop - we have valid results.
   Otherwise, move to the next handler.
4. After exiting the handler loop, if the results are falsey, *now*
   throw an exception.
Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not trust JDT with the newest code action changes, so had to execute them manually.
Things seem to be working fine.

:lgtm:

Reviewed 2 of 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @tonitch)

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed all commit messages.
Reviewable status: :shipit: complete! 2 of 2 LGTMs obtained (waiting on @tonitch)

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 2 of 2 LGTMs obtained (waiting on @tonitch)

Copy link
Contributor

mergify bot commented Jan 16, 2024

Thanks for sending a PR!

@mergify mergify bot merged commit 7bc5d08 into ycm-core:master Jan 16, 2024
15 checks passed
@tonitch tonitch deleted the jdtls-1310-versionBump branch January 16, 2024 17:34
bstaletic added a commit to ycm-core/YouCompleteMe that referenced this pull request Feb 18, 2024
Changes since the last update:

ycm-core/ycmd#1728 YcmShowDetailedDiagnostic should now match what is echoed on the command line.
ycm-core/ycmd#1731 Add support for `workspace/didChangeWorkspaceFolders` LSP notification.
ycm-core/ycmd#1730 LSP servers are now updated with latest server state afer reset
ycm-core/ycmd#1727 Update JDT to version 1.31.0
ycm-core/ycmd#1726 C# symbol search filtering fix
ycm-core/ycmd#1724 C# GoToDocumentOutline consistency patch
ycm-core/ycmd#1723 Implement GoToDocumentOutline in C#
ycm-core/ycmd#1716 Display tsserver tags in detailed info and GetDoc

`workspace/didChangeWorkspaceFolders` seems to be working fine for java,
rust and go, but should be considered experimental. Definitely more
field experience is needed.
What it should do is allow LSP servers to understand multiple projects
in the same vim instance.
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

Successfully merging this pull request may close these issues.

None yet

3 participants