Load code completion options programmatically

Hello guys.

I would like to implement resharper plugin which should, when needed, load available code completions to some kind of a list and then insert some extra items to the list of possible completions.

Could anyone tell me if this is actually possible with the SDK and pinpoint exact methods/classes to use?

Many thanks!!!

6 comments
Comment actions Permalink
Official comment

Hi Rotter!
It's possible, take a look at documentation.

Comment actions Permalink

Slava Trenogin Hello, I did check documentation and made some progress.

What I would like to do is to programmatically get list of code completions inside method "AddLookupItems" and the add my own items based on the existing list.

Is there any way? I need to get List<ILookupItem> of items which are to be shown. I tried this code inside "AddLookupItems" to get the list

IReadOnlyList<ILookupItem> lookupItemList = context.GetData<IReadOnlyList<ILookupItem>>(CSharpCompletionKeys.BasicCompletionResultKey);

but it does not work. What I essentially need is to duplicate each existing code-completion entry, so that resulting code completion list show each entry twice (don't ask why).

Please, can you direct me at correct existing method to load existing code-completions?

0
Comment actions Permalink

Rotter, IItemsCollector which is passed to you in AddLookupItems method contains all already added items before you. See Items property.
If you want to be the last one in the chain of completion providers (to check all added items) set IsFinal property to true in your provider. 

0
Comment actions Permalink

Will check it out. Thanks. Perhaps one last question.

The list from IItemsCollector contains many types of "LookupItem<T>", for example "LookupItem<MethodsInfo>", "LookupItem<ConstructorInfo>" - depending on the type of code completion item. Problem is that those item do not implement "ICloneable" interface, thus cannot be easily "cloned", so the only way of inserting "duplicate" items is to use for example "CSharpLookupItemFactory.Instance.CreateDeclaredElementLookupItem()" or "CSharpLookupItemFactory.Instance.CreateConstructorLookupItem()", again depending on the item type. Problem with these methods is that they sometimes take arguments which cannot be deduced from already existing "LookupItem<T>" item.

Or is there another simpler and cleaner way?

0
Comment actions Permalink

I'm afraid there is no simpler way.
As some trade-off you can create universal TextLookupItem from each of original lookup items.
But then you'll lose some smart behaviour of original ones, like parentheses inserting or something else. 

0
Comment actions Permalink

That's actually quite good idea, thank you once more.

0

Please sign in to leave a comment.