Skip to content

Commit fe04f3f

Browse files
authored
Merge pull request #1695 from puremourning/java-specify-jdtls-location
Allow specifying the location of jdt.ls; this is useful for testing o…
2 parents 621efe8 + d4e21c6 commit fe04f3f

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

ycmd/completers/java/java_completer.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ def ShouldEnableJavaCompleter( user_options ):
114114
LOGGER.warning( "Not enabling java completion: Couldn't find java 11" )
115115
return False
116116

117-
if not os.path.exists( LANGUAGE_SERVER_HOME ):
117+
if not _PathToLauncherJar( user_options ):
118118
LOGGER.warning( 'Not using java completion: jdt.ls is not installed' )
119119
return False
120120

121-
if not _PathToLauncherJar():
122-
LOGGER.warning( 'Not using java completion: jdt.ls is not built' )
123-
return False
124-
125121
return True
126122

127123

128-
def _PathToLauncherJar():
124+
def _LanguageServerHome( user_options ):
125+
return user_options.get( 'java_jdtls_repository_path', LANGUAGE_SERVER_HOME )
126+
127+
128+
def _PathToLauncherJar( user_options ):
129129
# The file name changes between version of eclipse, so we use a glob as
130130
# recommended by the language server developers. There should only be one.
131131
launcher_jars = glob.glob(
132132
os.path.abspath(
133133
os.path.join(
134-
LANGUAGE_SERVER_HOME,
134+
_LanguageServerHome( user_options ),
135135
'plugins',
136136
'org.eclipse.equinox.launcher_*.jar' ) ) )
137137

@@ -183,7 +183,7 @@ def _CollectExtensionBundles( extension_path ):
183183
return extension_bundles
184184

185185

186-
def _LauncherConfiguration( workspace_root, wipe_config ):
186+
def _LauncherConfiguration( user_options, workspace_root, wipe_config ):
187187
if utils.OnMac():
188188
config = 'config_mac'
189189
elif utils.OnWindows():
@@ -211,9 +211,10 @@ def _LauncherConfiguration( workspace_root, wipe_config ):
211211
working_config = os.path.abspath( os.path.join( workspace_root,
212212
config ) )
213213
working_config_file = os.path.join( working_config, CONFIG_FILENAME )
214-
base_config_file = os.path.abspath( os.path.join( LANGUAGE_SERVER_HOME,
215-
config,
216-
CONFIG_FILENAME ) )
214+
base_config_file = os.path.abspath(
215+
os.path.join( _LanguageServerHome( user_options ),
216+
config,
217+
CONFIG_FILENAME ) )
217218

218219
if os.path.isdir( working_config ):
219220
if wipe_config:
@@ -285,7 +286,10 @@ def _WorkspaceDirForProject( workspace_root_path,
285286

286287
class JavaCompleter( language_server_completer.LanguageServerCompleter ):
287288
def __init__( self, user_options ):
289+
# Stuff used by _Reset have to be set here as super().__init__() calls it.
288290
self._workspace_path = None
291+
self._user_options = user_options
292+
289293
super().__init__( user_options )
290294

291295
self._server_keep_logfiles = user_options[ 'server_keep_logfiles' ]
@@ -316,7 +320,23 @@ def __init__( self, user_options ):
316320

317321
def DefaultSettings( self, request_data ):
318322
return {
319-
'bundles': self._bundles
323+
'bundles': self._bundles,
324+
325+
# This disables re-checking every open file on every change to every file.
326+
# But can lead to stale diagnostics. Unfortunately, this can be kind of
327+
# annoying, so we don't enable it by default. JDT does re-validate if you
328+
# force load a file, but there isn't a nice way to force it to revalidate
329+
# a specific file e.g. OnFileReadyToParse, so far as i know.
330+
# If users have perf problems, they can set this in the .ycm_extra_conf.py
331+
#
332+
# def Settings( **kwargs ):
333+
# return {
334+
# 'ls': {
335+
# 'java.edit.validateAllOpenBuffersOnChanges': False
336+
# }
337+
# }
338+
#
339+
# 'java.edit.validateAllOpenBuffersOnChanges': False
320340
}
321341

322342

@@ -420,7 +440,7 @@ def _Reset( self ):
420440
LOGGER.exception( 'Failed to clean up workspace dir %s',
421441
self._workspace_path )
422442

423-
self._launcher_path = _PathToLauncherJar()
443+
self._launcher_path = _PathToLauncherJar( self._user_options )
424444
self._launcher_config = None
425445
self._workspace_path = None
426446
self._java_project_dir = None
@@ -466,8 +486,9 @@ def StartServer( self,
466486
shutil.rmtree( self._workspace_path )
467487

468488
self._launcher_config = _LauncherConfiguration(
469-
self._workspace_root_path,
470-
wipe_config )
489+
self._user_options,
490+
self._workspace_root_path,
491+
wipe_config )
471492

472493
self._command = [ PATH_TO_JAVA ] + self._GetJvmArgs( request_data ) + [
473494
'-Dfile.encoding=UTF-8',

ycmd/completers/language_server/language_server_completer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,18 +2110,18 @@ def _UpdateServerWithFileContents( self, request_data ):
21102110

21112111

21122112
def _RefreshFileContentsUnderLock( self, file_name, contents, file_types ):
2113-
file_state = self._server_file_state[ file_name ]
2113+
file_state: lsp.ServerFileState = self._server_file_state[ file_name ]
2114+
old_state = file_state.state
21142115
action = file_state.GetDirtyFileAction( contents )
21152116

2116-
LOGGER.debug( 'Refreshing file %s: State is %s/action %s',
2117+
LOGGER.debug( 'Refreshing file %s: State is %s -> %s/action %s',
21172118
file_name,
2119+
old_state,
21182120
file_state.state,
21192121
action )
21202122

21212123
if action == lsp.ServerFileState.OPEN_FILE:
2122-
msg = lsp.DidOpenTextDocument( file_state,
2123-
file_types,
2124-
contents )
2124+
msg = lsp.DidOpenTextDocument( file_state, file_types, contents )
21252125

21262126
self.GetConnection().SendNotification( msg )
21272127
elif action == lsp.ServerFileState.CHANGE_FILE:
@@ -2131,7 +2131,6 @@ def _RefreshFileContentsUnderLock( self, file_name, contents, file_types ):
21312131
# the diffs. This isn't strictly necessary, but might lead to
21322132
# performance problems.
21332133
msg = lsp.DidChangeTextDocument( file_state, contents )
2134-
21352134
self.GetConnection().SendNotification( msg )
21362135

21372136

0 commit comments

Comments
 (0)