Exemple #1
0
 def process_go_to_definition(self, result, req_id):
     if isinstance(result, list):
         if len(result) > 0:
             result = result[0]
             result['file'] = process_uri(result['uri'])
         else:
             result = None
     elif isinstance(result, dict):
         result['file'] = process_uri(result['uri'])
     if req_id in self.req_reply:
         self.req_reply[req_id](LSPRequestTypes.DOCUMENT_DEFINITION, {
             'params': result
         })
Exemple #2
0
    def apply_edit(self, response):
        logger.debug("Editing: {0}".format(response['label']))
        response = response['edit']
        folders = list(self.watched_folders.keys())
        assigned_files = {folder: [] for folder in self.watched_folders}
        if 'documentChanges' in response:
            for change in response['documentChanges']:
                if 'textDocument' in change:
                    uri = change['textDocument']['uri']
                    path = process_uri(uri)
                    change['textDocument']['path'] = path
                    workspace = match_path_to_folder(folders, path)
                    assigned_files[workspace].append({path: change})
                elif 'uri' in change:
                    path = process_uri(change['uri'])
                    change['path'] = path
                    workspace = match_path_to_folder(folders, path)
                    assigned_files[workspace].append({path: change})
                elif 'oldUri' in change:
                    old_path = process_uri(change['oldUri'])
                    change['old_path'] = old_path
                    new_path = process_uri(change['newUri'])
                    change['new_path'] = new_path
                    workspace = match_path_to_folder(folders, new_path)
                    assigned_files[workspace].append({old_path: change})
        elif 'changes' in response:
            changes = response['changes']
            uris = list(changes.keys())
            for uri in uris:
                path = process_uri(uri)
                change = changes.pop(uri)
                workspace = match_path_to_folder(folders, path)
                assigned_files[workspace].append({path: change})

        for workspace in assigned_files:
            workspace_edits = assigned_files[workspace]
            workspace_instance = self.watched_folders[workspace]['instance']
            workspace_instance.handle_response(
                LSPRequestTypes.WORKSPACE_APPLY_EDIT, {
                    'params': {
                        'edits': workspace_edits,
                        'language': self.language
                    }
                })
Exemple #3
0
    def handle_symbol_response(self, response):
        folders = list(self.watched_folders.keys())
        assigned_symbols = {folder: [] for folder in self.watched_folders}
        for symbol_info in response:
            location = symbol_info['location']
            path = process_uri(location['uri'])
            location['file'] = path
            workspace = match_path_to_folder(folders, path)
            assigned_symbols[workspace].append(symbol_info)

        for workspace in assigned_symbols:
            workspace_edits = assigned_symbols[workspace]
            workspace_instance = self.watched_folders[workspace]['instance']
            workspace_instance.handle_response(
                LSPRequestTypes.WORKSPACE_SYMBOL, {'params': workspace_edits})