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
3c38133e
Commit
3c38133e
authored
May 10, 2021
by
Mark Nauwelaerts
Browse files
lspclient: perform binary diagnostic search as fallback resort
parent
153c8710
Changes
1
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lspclientpluginview.cpp
View file @
3c38133e
...
...
@@ -1986,12 +1986,32 @@ public:
QStandardItem
*
targetItem
=
nullptr
;
if
(
topItem
)
{
int
count
=
topItem
->
rowCount
();
int
first
=
0
,
last
=
count
;
// let's not run wild on a linear search in a flood of diagnostics
// user is already in enough trouble as it is ;-)
if
(
count
>
50
)
{
count
=
0
;
// instead, let's *assume* sorted and use binary search to get closer
// it probably is sorted, so it should work out
// if not, at least we tried (without spending/wasting more on sorting)
auto
getLine
=
[
topItem
,
count
](
int
index
)
{
Q_ASSERT
(
index
>=
0
);
Q_ASSERT
(
index
<
count
);
auto
range
=
topItem
->
child
(
index
)
->
data
(
RangeData
::
RangeRole
).
value
<
LSPRange
>
();
return
range
.
start
().
line
();
};
int
first
=
0
,
last
=
count
-
1
;
int
target
=
pos
.
line
();
while
(
first
+
1
<
last
)
{
int
middle
=
first
+
(
last
-
first
)
/
2
;
Q_ASSERT
(
first
!=
middle
);
Q_ASSERT
(
middle
!=
last
);
if
(
getLine
(
middle
)
<
target
)
{
first
=
middle
;
}
else
{
last
=
middle
;
}
}
}
for
(
int
i
=
0
;
i
<
coun
t
;
++
i
)
{
for
(
int
i
=
first
;
i
<
las
t
;
++
i
)
{
auto
item
=
topItem
->
child
(
i
);
auto
range
=
item
->
data
(
RangeData
::
RangeRole
).
value
<
LSPRange
>
();
if
((
onlyLine
&&
pos
.
line
()
==
range
.
start
().
line
())
||
(
range
.
contains
(
pos
)))
{
...
...
Write
Preview
Markdown
is supported
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