def CodeActionCallback(self, context): params = context['params'] context = params['context'] if context != self.code_action_cache or 'result' not in context: logger.debug('filtered a CodeActionCallback.') return res = context['result'] seleted_item = res[params['seleted_item']] if 'edit' in seleted_item: res = workspace_edit.WorkspaceEdit(seleted_item['edit']) self._do_action(res) if 'command' in seleted_item: pass # TODO
def Format(self, context): if 'documentFormattingProvider' not in self.capabilities: self._show_msg('Format is not supported.') return params = context['params'] uri = self._lsp.PathToUri(params['buffer_path']) res = self._lsp.formatting(uri, self.engine_format_setting).GetResponse() if 'error' in res: self._show_msg(res['error']['message']) return res = res['result'] if res is None: self._show_msg('nothing to format.') return res = workspace_edit.WorkspaceEdit({'changes': {uri: res}}) self._do_action(res) self._show_msg('Formatted.')
def _handle_edit(self): while 1: try: response = self._lsp.GetRequestOrNotification( 'workspace/applyEdit') try: res = workspace_edit.WorkspaceEdit( response['params']['edit']) self._do_action(res) applied = True except Exception as e: logger.exception(e) applied = False logger.debug(response) self._lsp.applyEdit_response(response['id'], applied) except Exception as e: logger.exception(e)
def OnTypeFormatting(self, context): if 'documentOnTypeFormattingProvider' not in self.capabilities: self._show_msg('OnTypeFormatting is not supported.') return params = context['params'] uri = params['buffer_path'] uri = self._lsp.PathToUri(uri) start_position = params['buffer_position'] res = self._lsp.onTypeFormatting( uri, start_position['line'], start_position['colum'], '\n', self.engine_format_setting).GetResponse() if 'error' in res: self._show_msg(res['error']['message']) return res = res['result'] if res is None: return res = workspace_edit.WorkspaceEdit({'changes': {uri: res}}) self._do_action(res)
def Rename(self, context): if 'renameProvider' not in self.capabilities: self._show_msg('Rename is not supported.') return if 'is_callback' in context and context['is_callback']: self._rename_callabck(context) return params = context['params'] text = params['buffer_content'] text = "\n".join(text) version = params['buffer_id'] uri = params['buffer_path'] uri = self._lsp.PathToUri(uri) start_position = params['buffer_position'] position = { 'line': start_position['line'], 'character': start_position['colum'] } new_name = params['new_name'] res = self._lsp.rename(uri, self.languageId, text, version, position, new_name).GetResponse() if 'error' in res: self._show_msg(res['error']['message']) return res = res['result'] if res is None: self._show_msg("Failded to get rename info from language server.") return self.rename_id += 1 rename_info = {'rename_id': self.rename_id, 'res': res} self.rename_info[self.rename_id] = rename_info del self.rename_info[self.rename_id] # for now res = workspace_edit.WorkspaceEdit(res) self._do_action(res)