7096 - Psi document model screwed up

My Identifier Highlighter plugin uses the Psi document model heavily. In EAP 7096 build, the ReferencesSearch.search function is returning the found elements in random order. In M1b and earlier, they were always returned in text offset or file order. This renders my plugin useless. I could workaround it by sorting by text offset, but I would rather not.

4 comments
Comment actions Permalink

Hello Shawn,

My Identifier Highlighter plugin uses the Psi document model heavily.
In EAP 7096 build, the ReferencesSearch.search function is returning
the found elements in random order. In M1b and earlier, they were
always returned in text offset or file order. This renders my plugin
useless. I could workaround it by sorting by text offset, but I would
rather not.


Please do, because the behavior you're seeing is by design and is not going
to change. The search for references is performed by multiple threads in
parallel on multicore machines, so the order of returned results is essentially
random. Always performing sorting on returned results would cause major performance
overhead for clients that do not care about order of results (and especially
for those who abort the search after processing only some of the results).

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

OK, I can do the sort.

However, can you confirm that the behavior change I am seeing is expected? I haven't changed machines or anything so I am using the same CPU (Intel Core Duo T2600 2.16GHz) I have always used. With M1b version, they are returned sorted by text offset, but 7096 build, they are random.

0
Comment actions Permalink

Perhaps it makes sense to include a PsiElementOrderComparator in the openapi. Something like this perhaps?

	{

		private static final PsiElementOrderComparator INSTANCE =
				new PsiElementOrderComparator();

		public int compare(PsiElement element1, PsiElement element2)
		{
			final int offset1 = element1.getTextOffset();
			final int offset2 = element2.getTextOffset();
			return offset1 - offset2;
		}

		public static PsiElementOrderComparator getInstance()
		{
			return INSTANCE;
		}
	}
]]>


Or is such a comparator already included?

Bas

0
Comment actions Permalink

Hello Bas,

Perhaps it makes sense to include a PsiElementOrderComparator in the
openapi. Something like this perhaps?

 class PsiElementOrderComparator implements Comparator
> {
> private static final PsiElementOrderComparator INSTANCE =
> new PsiElementOrderComparator();
> public int compare(PsiElement element1, PsiElement element2)
> {
> final int offset1 = element1.getTextOffset();
> final int offset2 = element2.getTextOffset();
> return offset1 - offset2;
> }
> public static PsiElementOrderComparator getInstance()
> {
> return INSTANCE;
> }
> }
> ]]>

Or is such a comparator already included?


PsiUtil.compareElementsByPosition() was recently added.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.