diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-21 06:22:42 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-03-21 06:22:42 -0700 |
commit | 7e2f1500f34098be4a0cc0b2130cffb3a729793b (patch) | |
tree | 18e9a0b5e4136d8379f583fdd2069748f6648ac8 /parser.c | |
parent | c2dec325d87de8be8917e7b52f118f4664a9e13a (diff) | |
download | txr-7e2f1500f34098be4a0cc0b2130cffb3a729793b.tar.gz txr-7e2f1500f34098be4a0cc0b2130cffb3a729793b.tar.bz2 txr-7e2f1500f34098be4a0cc0b2130cffb3a729793b.zip |
listener: completion sensitive for slots and methods.
When completing .prefix[TAB], .(prefix[TAB] or .[prefix[TAB],
restrict identifiers to the appropriate namespace. The former
will report only symbols from the relevant package which are
struct slots; the latter further restricts it to those which
are static slots defined as functions.
* lib.c (symbol_visible): Static function becomes extern.
* lib.h (symbol_visible): Declared.
* parser.c (find_matching_syms): par parameter is renamed
kind and can hold additional values 'S' (slots) and 'M'
(methods). New get_slot_syms function is used to fetch the
slots, as necessary, instead of the visible syms, if the
kind is 'S' or 'M'. The same loop as before (with the minor
change of recognizing 'S' and 'M' also) performs the prefix
matching.
(provide_completions): Recognize . .( and .[ prefix,
calculating the kind argument of find_matching_syms in
a new way.
* struct.c (get_slot_syms): New function.
* struct.h (get_slot_syms): Declared.
* txr.1: Add some notes about this under the description of
completion. The full rules are not given though; let the
user discover.
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -686,18 +686,20 @@ static val get_visible_syms(val package, int is_cur) static void find_matching_syms(lino_completions_t *cpl, val package, val prefix, - val line_prefix, char par, + val line_prefix, char kind, val force_qualify) { - int is_cur = package == cur_package; + val is_cur = tnil(package == cur_package); val qualify = tnil(force_qualify || !is_cur); val pkg_name = if2(qualify, if3(package == keyword_package && !force_qualify, lit(""), package_name(package))); - val syms; + val syms = ((kind == 'S' || kind == 'M') + ? hash_keys((get_slot_syms(package, is_cur, tnil(kind == 'M')))) + : get_visible_syms(package, is_cur != nil)); - for (syms = get_visible_syms(package, is_cur); syms; syms = cdr(syms)) { + for ( ; syms; syms = cdr(syms)) { val sym = car(syms); val name = symbol_name(sym); val found = if3(cpl->substring, @@ -707,7 +709,7 @@ static void find_matching_syms(lino_completions_t *cpl, if (found) { val comple; - switch (par) { + switch (kind) { case '(': if (!fboundp(sym) && !mboundp(sym) && !special_operator_p(sym)) continue; @@ -716,6 +718,9 @@ static void find_matching_syms(lino_completions_t *cpl, if (!boundp(sym) && !lookup_fun(nil, sym)) continue; break; + case 'M': + case 'S': + break; default: break; } @@ -812,13 +817,19 @@ static void provide_completions(const char *data, char prev = (end > data) ? end[-1] : 0; char pprev = (end > data + 1) ? end[-2] : 0; int quote = (pprev == '^' || pprev == '\'' || pprev == '#'); - int meth = (pprev == '.'); int ppar = (pprev == '('); int dwim = (prev == '['); - char par = (!pprev || (!quote && !meth && !ppar) || dwim) ? prev : 0; + int par = (prev == '('); + int slot = (prev == '.'); + int meth = (pprev == '.') && (dwim || par); + char kind = (slot + ? 'S' + : (meth + ? 'M' + : (!pprev || (!quote && !ppar) || dwim) ? prev : 0)); find_matching_syms(cpl, or2(package, cur_package), - sym_pfx, line_pfx, par, if2(package, null(keyword))); + sym_pfx, line_pfx, kind, if2(package, null(keyword))); } } } |