Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
cdbc4e53
Commit
cdbc4e53
authored
Mar 16, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Mar 16, 2021
Browse files
Put () in front when autocompleting functions
parent
c55bc613
Changes
1
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lspclientcompletion.cpp
View file @
cdbc4e53
...
...
@@ -318,16 +318,33 @@ public:
return
doc
->
characterAt
(
KTextEditor
::
Cursor
(
range
.
end
().
line
(),
range
.
end
().
column
()));
}
static
bool
isFunctionKind
(
LSPCompletionItemKind
k
)
{
return
k
==
LSPCompletionItemKind
::
Function
||
k
==
LSPCompletionItemKind
::
Method
;
}
void
executeCompletionItem
(
KTextEditor
::
View
*
view
,
const
KTextEditor
::
Range
&
word
,
const
QModelIndex
&
index
)
const
override
{
if
(
index
.
row
()
<
m_matches
.
size
())
{
auto
next
=
peekNextChar
(
view
->
document
(),
word
);
auto
matching
=
m_matches
.
at
(
index
.
row
()).
insertText
;
QChar
next
=
peekNextChar
(
view
->
document
(),
word
);
QString
matching
=
m_matches
.
at
(
index
.
row
()).
insertText
;
// if there is already a '"' or >, remove it, this happens with #include "xx.h"
if
((
next
==
QLatin1Char
(
'"'
)
&&
matching
.
endsWith
(
QLatin1Char
(
'"'
)))
||
(
next
==
QLatin1Char
(
'>'
)
&&
matching
.
endsWith
(
QLatin1Char
(
'>'
))))
{
matching
.
chop
(
1
);
}
// This is a function
const
auto
&
m
=
m_matches
.
at
(
index
.
row
());
if
(
isFunctionKind
(
m
.
kind
))
{
matching
+=
QStringLiteral
(
"()"
);
}
view
->
document
()
->
replaceText
(
word
,
matching
);
if
(
isFunctionKind
(
m
.
kind
))
{
// place the cursor in between (|)
view
->
setCursorPosition
({
view
->
cursorPosition
().
line
(),
view
->
cursorPosition
().
column
()
-
1
});
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment