bobbylight / AutoComplete

A code completion library for Swing text components, with special support for RSyntaxTextArea.
BSD 3-Clause "New" or "Revised" License
166 stars 55 forks source link

AutoComplete tree #46

Closed mmakrzem closed 5 years ago

mmakrzem commented 7 years ago

I want to be able to auto compete based on the dot key. Ie I have something like:

ABC.DEF ABC.GHI ABC.KLM ABZ.STU ABZ.XYZ

if user types AB and then autoCompletes, I want to only show ABC and ABZ as the two valid options. If user types ABC. and then autoCompletes, I want to only show DEF, GHI, and KLM as the 3 only valid options.

How do I set that up? I can create BasicCompletion's for ABC and ABZ to get the first part working, but how do I get the second part to work? I want the auto complete list to be context dependent. The dot key doesn't seem to get recognized properly when doing completions.

olegvasylenko commented 7 years ago

You may add several completion from your example: ABC. ABZ. ABC.DEF ABC.GHI ABC.KLM ABZ.STU ABZ.XYZ

Create completion provider which return completion if completion input text starts from entered text but no dots anymore after entered text inside of input text. Then create your local list renderer and render properly only the last part of completion input text (after last dot I meant). Add renderer to completion provider. I hope it written clearly more or less. Such approach helped us.

bobbylight commented 5 years ago

The other approach besides that suggested by @olegvasylenko is to write your own CompletionProvider that does a more in-depth analysis of the text before the caret - if there are no dots, return X, otherwise return Y. This was the approach I took for code completion for things like Java.

It's nontrivial but not too bad. Unfortunately there's nothing in the library to help with this directly.