def EchoErrorMessageForCurrentLine(self): vimsupport.EchoText('') if not self.isAlive(): return current_line, current_column = vimsupport.CurrentLineAndColumn() if not current_line in self.lined_diagnostics: return '' diagnostic = self.NearestDiagnostic(current_line, current_column) vimsupport.EchoTruncatedText(diagnostic['text'])
def EchoDetailedErrorMessage(self): if not self.isAlive(): return current_line, _ = vimsupport.CurrentLineAndColumn() if not current_line in self.lined_diagnostics: return full_text = '' for diagnostic in self.lined_diagnostics[current_line]: full_text += 'L%d:C%d %s\n' % (diagnostic['lnum'], diagnostic['col'], diagnostic['text']) vimsupport.EchoText(full_text[:-1])
def ErrorStatusForCurrentLine(self): if not self.isAlive(): return '' current_line, current_column = vimsupport.CurrentLineAndColumn() if not current_line in self.lined_diagnostics: return '' diagnostic = self.NearestDiagnostic(current_line, current_column) serverity_strings = [ 'ignored', 'note', 'warning', 'error', 'fatal', ] return serverity_strings[int(diagnostic['severity'])]
def GotoDefinition(self): if not self.isAlive(): return line, column = vimsupport.CurrentLineAndColumn() #TODO we may want to reparse source file actively here or by-pass the # reparsing to incoming source file monitor? response = self.wc.GetDefinition(vimsupport.CurrentBufferFileName(), line, column) if not response: log.warning('unable to get definition at %d:%d' % (line, column)) vimsupport.EchoTruncatedText('unable to get definition at %d:%d' % (line, column)) return location = response.location file_name = location.file_name line = location.line column = location.column vimsupport.GotoBuffer(file_name, line, column)
def CodeCompleteAtCurrent(self): if not self.isAlive(): return -1 if not self.OpenCurrentFile(): return -1 line, column = vimsupport.CurrentLineAndColumn() start_column, start_word = self._CalculateStartColumnAt( column, vimsupport.CurrentLine()) trigger_word = None if start_column: trigger_word = vimsupport.CurrentLine()[start_column - 1] # skip from ';' and '}' if trigger_word == ';' or trigger_word == '}' or trigger_word == ']': return -1 if not trigger_word in self._triggerCharacters: return -1 if not self._last_completions_pos == (line - 1, start_column): timeout_ms = GetIntValue('g:clangd#codecomplete_timeout') try: self._last_completions_pos = (line - 1, start_column) uri = GetUriFromFilePath(vimsupport.CurrentBufferFileName()) self._client.codeCompleteAt( uri, line - 1, start_column, timeout_ms=timeout_ms) except TimedOutError: log.warn('perform clang codecomplete timed out at %d:%d' % (line, column)) # fetch cachable completions tries = self._last_completions flat_completions = [] for kind, trie in tries.items(): flat_completions.extend(trie.searchPrefix(start_word)[0:10]) self._computed_completions_words = flat_completions return start_column + 1
def ShowCursorDetail(self): if not self.isAlive(): return line, column = vimsupport.CurrentLineAndColumn() #TODO we may want to reparse source file actively here or by-pass the # reparsing to incoming source file monitor? response = self.wc.GetCursorDetail(vimsupport.CurrentBufferFileName(), line, column) if not response: log.warning('unable to get cursor at %d:%d' % (line, column)) vimsupport.EchoTruncatedText('unable to get cursor at %d:%d' % (line, column)) return detail = response.detail message = 'Type: %s Kind: %s' % (detail.type, detail.kind) brief_comment = detail.brief_comment if brief_comment: message += ' ' message += brief_comment vimsupport.EchoText(message)
def GetCompletions(self): if len(self._last_completions) == 0: return {'words': [], 'refresh': 'always'} _, column = vimsupport.CurrentLineAndColumn() words = self._computed_completions_words return {'words': words, 'refresh': 'always'}