简体   繁体   中英

Can the Spell Checker Framework used for code hinting?

I was looking at the Spell Checker Framework and was wondering if I can use this to implement code hinting in my app. Can I implement a custom 'code' dictionary? Just wondering if this is a possible approach to code completion before embarking.

Good code completion (in my personal opinion) is context sensitive and should only show completions for things that are in scope and are applicable to the current position within code. For example, in java it doesn't really make sense to show method name completions outside of a method. It makes sense to do plain spell checking against an English language dictionary for code comments, but not for method and variable names, etc.

If you want a fully functional code editor I think you need to come up with your own editor (eg, not use TextView per se) and do your own completions, perhaps using the system spell checker API to spell check code comments. You might want to look at the source code for TextView.java and Editor.java for ideas on how to implement your own code editor and completion UI at the editor level (maybe in conjunction with other open source code editors).

If your needs are relatively simple you might be able to get by by adding spans of type SuggestionSpan to the text in the TextView (this is what the spell checker does) with your completion info.

The spelling framework is basically designed to check one or more words against a dictionary without much regard to context. (See SpellCheckerSession. You don't get a lot of context.)

Another thing: While actively composing text (entering a word) completions are usually handled by the input method, which shows the completions (usually) in a word choice list in the soft input area. You probably don't want those completions/suggestions since the input method only handles completions for editor types as defined by InputType and if you try to spoof your editor as, say, plain text, you would probably get less than ideal results. In your case you probably want to handle the completions in the editor (sort of like they way TextView handles suggestions when tapping on misspelled words) and ensure your editor disables the IME suggestions via TYPE_TEXT_FLAG_NO_SUGGESTIONS (which disables the spell checker as well). I guess you could also write an input method to go along with your editor if you are really ambitious.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM