diff --git a/CMakeLists.txt b/CMakeLists.txt index c99127cb5..bf898dd45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,11 +79,16 @@ endif() # Bindings find_package(PythonInterp) if (PYTHONINTERP_FOUND) + set(NVIM "nvim" CACHE STRING "Path to nvim executable") add_custom_target(bindings - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py nvim ${CMAKE_SOURCE_DIR}/src/auto + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py ${NVIM} ${CMAKE_SOURCE_DIR}/src/auto WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "Generating bindings" ) + + add_custom_target(bindings-preview + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py ${NVIM} + ) endif() diff --git a/bindings/function_static.cpp b/bindings/function_static.cpp index 1969ab4c7..d44645296 100644 --- a/bindings/function_static.cpp +++ b/bindings/function_static.cpp @@ -6,6 +6,6 @@ const QList Function::knownFunctions = QList() {% for param in f.parameters %} << QString("{{param.neovim_type}}") {% endfor %} - , {% if f.can_fail%}true{%else%}false{%endif%}) + , false) {% endfor %} ; diff --git a/bindings/generate_bindings.py b/bindings/generate_bindings.py index a12a53f0c..6f5f0653b 100644 --- a/bindings/generate_bindings.py +++ b/bindings/generate_bindings.py @@ -54,6 +54,7 @@ class NeovimTypeVal: 'String': 'QByteArray', 'Object': 'QVariant', 'Array': 'QVariantList', + 'Dictionary': 'QVariantMap', } # msgpack extension types EXTTYPES = { @@ -109,6 +110,9 @@ class Function: """ Representation for a Neovim API Function """ + + # Attributes names that we support, see src/function.c for details + __KNOWN_ATTRIBUTES = set(['name', 'parameters', 'return_type', 'can_fail', 'deprecated_since', 'since', 'method', 'async', 'impl_name', 'noeval', 'receives_channel_id']) def __init__(self, nvim_fun): self.valid = False self.fun = nvim_fun @@ -121,21 +125,34 @@ def __init__(self, nvim_fun): except UnsupportedType as ex: print('Found unsupported type(%s) when adding function %s(), skipping' % (ex,self.name)) return + + u_attrs = self.unknown_attributes() + if u_attrs: + print('Found unknown attributes for function %s: %s' % (self.name, u_attrs)) + self.argcount = len(self.parameters) - self.can_fail = self.fun.get('can_fail', False) # Build the argument string - makes it easier for the templates self.argstring = ', '.join(['%s %s' % (tv.native_type, tv.name) for tv in self.parameters]) self.valid = True + def is_method(self): + return self.fun.get('method', False) + def is_async(self): + return self.fun.get('async', False) + def deprecated(self): + return self.fun.get('deprecated_since', None) + + def unknown_attributes(self): + attrs = set(self.fun.keys()) - Function.__KNOWN_ATTRIBUTES + return attrs + def real_signature(self): params = '' for p in self.parameters: params += '%s %s' % (p.native_type, p.name) params += ', ' notes = '' - if self.can_fail: - notes += '!fails' return '%s %s(%s) %s' % (self.return_type.native_type,self.name,params, notes) def signature(self): params = '' @@ -143,8 +160,6 @@ def signature(self): params += '%s %s' % (p.neovim_type, p.name) params += ', ' notes = '' - if self.can_fail: - notes += '!fails' return '%s %s(%s) %s' % (self.return_type.neovim_type,self.name,params, notes) @@ -160,8 +175,12 @@ def print_api(api): sig = fundef.signature() realsig = fundef.real_signature() print('\t%s'% sig) + deprecated = fundef.deprecated() + if deprecated: + print('\t- Deprecated: %d' % deprecated) if sig != realsig: - print('\t[aka %s]\n' % realsig) + print('\t- Native: %s\n' % realsig) + print('') elif key == 'types': print('Data Types') @@ -176,7 +195,7 @@ def print_api(api): elif key == 'features': pass else: - print('Unknown API info attribute: %s', key) + print('Unknown API info attribute: %s' % key) if __name__ == '__main__': @@ -212,5 +231,5 @@ def print_api(api): generate_file(name, outpath, **env) else: - print('Neovim api info:') + print('API info for %s:' % nvim) print_api(api) diff --git a/bindings/neovim.cpp b/bindings/neovim.cpp index d776e8899..6ebd67e07 100644 --- a/bindings/neovim.cpp +++ b/bindings/neovim.cpp @@ -69,11 +69,9 @@ void Neovim::handleResponseError(quint32 msgid, Function::FunctionId fun, const switch(fun) { {% for f in functions %} -{% if f.can_fail %} case Function::NEOVIM_FN_{{f.name.upper()}}: emit err_{{f.name}}(errMsg, res); break; -{% endif %} {% endfor %} default: m_c->setError(NeovimConnector::RuntimeMsgpackError, QString("Received error for function that should not fail: %s").arg(fun)); diff --git a/bindings/neovim.h b/bindings/neovim.h index cba72eb1f..fbde269f5 100644 --- a/bindings/neovim.h +++ b/bindings/neovim.h @@ -23,6 +23,9 @@ protected slots: NeovimConnector *m_c; public slots: {% for f in functions %} +{% if f.deprecated() %} + // DEPRECATED +{% endif %} // {{f.signature()}} MsgpackRequest* {{f.name}}({{f.argstring}}); {% endfor %} @@ -30,9 +33,7 @@ public slots: signals: {% for f in functions %} void on_{{f.name}}({{f.return_type.native_type}}); -{% if f.can_fail %} void err_{{f.name}}(const QString&, const QVariant&); -{% endif%} {% endfor %} }; diff --git a/src/function.cpp b/src/function.cpp index f1ab0a03d..5eec1ac84 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -75,10 +75,6 @@ bool Function::operator==(const Function& other) return false; } - if ( this->can_fail != other.can_fail ) { - return false; - } - if ( this->return_type != other.return_type ) { return false; } @@ -134,10 +130,18 @@ Function Function::fromVariant(const QVariant& fun) // Deprecated } else if ( it.key() == "receives_channel_id" ) { // Internal + } else if ( it.key() == "impl_name" ) { + // Internal + } else if ( it.key() == "method" ) { + // Internal + } else if ( it.key() == "noeval" ) { + // API only function } else if ( it.key() == "deferred" || it.key() == "async" ) { // Internal, "deferred" renamed "async" in neovim/ccdeb91 + } else if ( it.key() == "deprecated_since" || it.key() == "since" ) { + // Creation/Deprecation } else { - qWarning() << "Unsupported function attribute"<< it.key() << it.value(); + qDebug() << "Unsupported function attribute"<< it.key() << it.value(); } }