Skip to content

Commit 4015d8c

Browse files
authored
Merge pull request #188 from equalsraf/tb-bindings
Multiple improvements to binding generation
2 parents 2831d3f + b1bfc0f commit 4015d8c

File tree

6 files changed

+46
-19
lines changed

6 files changed

+46
-19
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ endif()
7979
# Bindings
8080
find_package(PythonInterp)
8181
if (PYTHONINTERP_FOUND)
82+
set(NVIM "nvim" CACHE STRING "Path to nvim executable")
8283
add_custom_target(bindings
83-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py nvim ${CMAKE_SOURCE_DIR}/src/auto
84+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py ${NVIM} ${CMAKE_SOURCE_DIR}/src/auto
8485
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
8586
COMMENT "Generating bindings"
8687
)
88+
89+
add_custom_target(bindings-preview
90+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bindings/generate_bindings.py ${NVIM}
91+
)
8792
endif()
8893

8994

bindings/function_static.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const QList<Function> Function::knownFunctions = QList<Function>()
66
{% for param in f.parameters %}
77
<< QString("{{param.neovim_type}}")
88
{% endfor %}
9-
, {% if f.can_fail%}true{%else%}false{%endif%})
9+
, false)
1010
{% endfor %}
1111
;

bindings/generate_bindings.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class NeovimTypeVal:
5454
'String': 'QByteArray',
5555
'Object': 'QVariant',
5656
'Array': 'QVariantList',
57+
'Dictionary': 'QVariantMap',
5758
}
5859
# msgpack extension types
5960
EXTTYPES = {
@@ -109,6 +110,9 @@ class Function:
109110
"""
110111
Representation for a Neovim API Function
111112
"""
113+
114+
# Attributes names that we support, see src/function.c for details
115+
__KNOWN_ATTRIBUTES = set(['name', 'parameters', 'return_type', 'can_fail', 'deprecated_since', 'since', 'method', 'async', 'impl_name', 'noeval', 'receives_channel_id'])
112116
def __init__(self, nvim_fun):
113117
self.valid = False
114118
self.fun = nvim_fun
@@ -121,30 +125,41 @@ def __init__(self, nvim_fun):
121125
except UnsupportedType as ex:
122126
print('Found unsupported type(%s) when adding function %s(), skipping' % (ex,self.name))
123127
return
128+
129+
u_attrs = self.unknown_attributes()
130+
if u_attrs:
131+
print('Found unknown attributes for function %s: %s' % (self.name, u_attrs))
132+
124133
self.argcount = len(self.parameters)
125-
self.can_fail = self.fun.get('can_fail', False)
126134

127135
# Build the argument string - makes it easier for the templates
128136
self.argstring = ', '.join(['%s %s' % (tv.native_type, tv.name) for tv in self.parameters])
129137
self.valid = True
130138

139+
def is_method(self):
140+
return self.fun.get('method', False)
141+
def is_async(self):
142+
return self.fun.get('async', False)
143+
def deprecated(self):
144+
return self.fun.get('deprecated_since', None)
145+
146+
def unknown_attributes(self):
147+
attrs = set(self.fun.keys()) - Function.__KNOWN_ATTRIBUTES
148+
return attrs
149+
131150
def real_signature(self):
132151
params = ''
133152
for p in self.parameters:
134153
params += '%s %s' % (p.native_type, p.name)
135154
params += ', '
136155
notes = ''
137-
if self.can_fail:
138-
notes += '!fails'
139156
return '%s %s(%s) %s' % (self.return_type.native_type,self.name,params, notes)
140157
def signature(self):
141158
params = ''
142159
for p in self.parameters:
143160
params += '%s %s' % (p.neovim_type, p.name)
144161
params += ', '
145162
notes = ''
146-
if self.can_fail:
147-
notes += '!fails'
148163
return '%s %s(%s) %s' % (self.return_type.neovim_type,self.name,params, notes)
149164

150165

@@ -160,8 +175,12 @@ def print_api(api):
160175
sig = fundef.signature()
161176
realsig = fundef.real_signature()
162177
print('\t%s'% sig)
178+
deprecated = fundef.deprecated()
179+
if deprecated:
180+
print('\t- Deprecated: %d' % deprecated)
163181
if sig != realsig:
164-
print('\t[aka %s]\n' % realsig)
182+
print('\t- Native: %s\n' % realsig)
183+
165184
print('')
166185
elif key == 'types':
167186
print('Data Types')
@@ -176,7 +195,7 @@ def print_api(api):
176195
elif key == 'features':
177196
pass
178197
else:
179-
print('Unknown API info attribute: %s', key)
198+
print('Unknown API info attribute: %s' % key)
180199

181200
if __name__ == '__main__':
182201

@@ -212,5 +231,5 @@ def print_api(api):
212231
generate_file(name, outpath, **env)
213232

214233
else:
215-
print('Neovim api info:')
234+
print('API info for %s:' % nvim)
216235
print_api(api)

bindings/neovim.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ void Neovim::handleResponseError(quint32 msgid, Function::FunctionId fun, const
6969

7070
switch(fun) {
7171
{% for f in functions %}
72-
{% if f.can_fail %}
7372
case Function::NEOVIM_FN_{{f.name.upper()}}:
7473
emit err_{{f.name}}(errMsg, res);
7574
break;
76-
{% endif %}
7775
{% endfor %}
7876
default:
7977
m_c->setError(NeovimConnector::RuntimeMsgpackError, QString("Received error for function that should not fail: %s").arg(fun));

bindings/neovim.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ protected slots:
2323
NeovimConnector *m_c;
2424
public slots:
2525
{% for f in functions %}
26+
{% if f.deprecated() %}
27+
// DEPRECATED
28+
{% endif %}
2629
// {{f.signature()}}
2730
MsgpackRequest* {{f.name}}({{f.argstring}});
2831
{% endfor %}
2932

3033
signals:
3134
{% for f in functions %}
3235
void on_{{f.name}}({{f.return_type.native_type}});
33-
{% if f.can_fail %}
3436
void err_{{f.name}}(const QString&, const QVariant&);
35-
{% endif%}
3637

3738
{% endfor %}
3839
};

src/function.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ bool Function::operator==(const Function& other)
7575
return false;
7676
}
7777

78-
if ( this->can_fail != other.can_fail ) {
79-
return false;
80-
}
81-
8278
if ( this->return_type != other.return_type ) {
8379
return false;
8480
}
@@ -134,10 +130,18 @@ Function Function::fromVariant(const QVariant& fun)
134130
// Deprecated
135131
} else if ( it.key() == "receives_channel_id" ) {
136132
// Internal
133+
} else if ( it.key() == "impl_name" ) {
134+
// Internal
135+
} else if ( it.key() == "method" ) {
136+
// Internal
137+
} else if ( it.key() == "noeval" ) {
138+
// API only function
137139
} else if ( it.key() == "deferred" || it.key() == "async" ) {
138140
// Internal, "deferred" renamed "async" in neovim/ccdeb91
141+
} else if ( it.key() == "deprecated_since" || it.key() == "since" ) {
142+
// Creation/Deprecation
139143
} else {
140-
qWarning() << "Unsupported function attribute"<< it.key() << it.value();
144+
qDebug() << "Unsupported function attribute"<< it.key() << it.value();
141145
}
142146
}
143147

0 commit comments

Comments
 (0)