Skip to content

Commit

Permalink
Respect server support for didChangeWorkspaceFolders notification
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Jan 27, 2024
1 parent 9ee0241 commit 9aab2b3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,14 @@ def _RefreshFileContentsUnderLock( self, file_name, contents, file_types ):

if action == lsp.ServerFileState.OPEN_FILE:
# First check if we need to inform the server of a new workspace.
workspace_for_file = self.GetWorkspaceForFilepath( file_name )
if workspace_for_file not in self._server_workspace_dirs:
self._server_workspace_dirs.add( workspace_for_file )
msg = lsp.DidChangeWorkspaceFolders( workspace_for_file )
self.GetConnection().SendNotification( msg )
# TODO: This check could be done once, after initialize response is
# received, and then saved in self._workspace_notification_supported.
if _ServerSupportsWorkspaceFoldersChangeNotif( self._server_capabilities )
workspace_for_file = self.GetWorkspaceForFilepath( file_name )
if workspace_for_file not in self._server_workspace_dirs:
self._server_workspace_dirs.add( workspace_for_file )
msg = lsp.DidChangeWorkspaceFolders( workspace_for_file )
self.GetConnection().SendNotification( msg )

msg = lsp.DidOpenTextDocument( file_state, file_types, contents )

Expand Down Expand Up @@ -3590,6 +3593,12 @@ def DecodeModifiers( self, tokenModifiers ):
return tokens


def _ServerSupportsWorkspaceFoldersChangeNotif( server_capabilities ):
workspace = server_capabilities.get( 'workspace', {} )
workspace_folders = workspace.get( 'workspaceFolders', {} )
return _IsCapabilityProvided( workspace_folders, 'changeNotification' )


def _IsCapabilityProvided( capabilities, query ):
capability = capabilities.get( query )
return bool( capability ) or capability == {}
Expand Down

0 comments on commit 9aab2b3

Please sign in to comment.