MCPcopy Create free account
hub / github.com/KDE/kdevelop / execute

Method execute

plugins/clang/codecompletion/context.cpp:229–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227 }
228
229 void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
230 {
231 QString repl = m_replacement;
232 DUChainReadLocker lock;
233
234 if(!m_declaration){
235 return;
236 }
237
238 if(m_declaration->isFunctionDeclaration()) {
239 const auto functionType = m_declaration->type<FunctionType>();
240
241 // protect against buggy code that created the m_declaration,
242 // to mark it as a function but not assign a function type
243 if (!functionType)
244 return;
245
246 auto doc = view->document();
247
248 // Function pointer?
249 bool funcptr = false;
250 const auto line = doc->line(word.start().line());
251 auto pos = word.end().column() - 1;
252 while ( pos > 0 && (line.at(pos).isLetterOrNumber() || line.at(pos) == QLatin1Char(':')) ) {
253 pos--;
254 if ( line.at(pos) == QLatin1Char('&') ) {
255 funcptr = true;
256 break;
257 }
258 }
259
260 auto restEmpty = doc->characterAt(word.end() + KTextEditor::Cursor{0, 1}) == QChar();
261
262 bool didAddParentheses = false;
263 if ( !funcptr && doc->characterAt(word.end()) != QLatin1Char('(') ) {
264 repl += QLatin1String("()");
265 didAddParentheses = true;
266 }
267 view->document()->replaceText(word, repl);
268 if (functionType->indexedArgumentsSize() && didAddParentheses) {
269 view->setCursorPosition(word.start() + KTextEditor::Cursor(0, repl.size() - 1));
270 }
271 auto returnTypeIntegral = functionType->returnType().dynamicCast<IntegralType>();
272 if ( restEmpty && !funcptr && returnTypeIntegral && returnTypeIntegral->dataType() == IntegralType::TypeVoid ) {
273 // function returns void and rest of line is empty -- nothing can be done with the result
274 if (functionType->indexedArgumentsSize() ) {
275 // we placed the cursor inside the ()
276 view->document()->insertText(view->cursorPosition() + KTextEditor::Cursor(0, 1), QStringLiteral(";"));
277 }
278 else {
279 // we placed the cursor after the ()
280 view->document()->insertText(view->cursorPosition(), QStringLiteral(";"));
281 view->setCursorPosition(view->cursorPosition() + KTextEditor::Cursor{0, 1});
282 }
283 }
284 } else {
285 view->document()->replaceText(word, repl);
286 }

Callers

nothing calls this directly

Calls 15

QCharClass · 0.85
indexedArgumentsSizeMethod · 0.80
dataTypeMethod · 0.80
CursorClass · 0.70
isFunctionDeclarationMethod · 0.45
documentMethod · 0.45
lineMethod · 0.45
startMethod · 0.45
columnMethod · 0.45
endMethod · 0.45
atMethod · 0.45
setCursorPositionMethod · 0.45

Tested by

no test coverage detected