diff options
author | 2011-02-15 19:09:48 -0500 | |
---|---|---|
committer | 2011-02-15 19:09:48 -0500 | |
commit | 283770beb51385270e60d75d11d63759dac6854f (patch) | |
tree | 72b426ae3b6cd7db638d37e43a327983a528fc55 | |
parent | 3de0163b245b386c122737e10780975e71100274 (diff) | |
download | textadept-283770beb51385270e60d75d11d63759dac6854f.tar.gz textadept-283770beb51385270e60d75d11d63759dac6854f.zip |
Add sense.syntax.class_definition for class context completion.
-rw-r--r-- | modules/lua/adeptsense.lua | 12 | ||||
-rw-r--r-- | modules/textadept/adeptsense.lua | 20 |
2 files changed, 22 insertions, 10 deletions
diff --git a/modules/lua/adeptsense.lua b/modules/lua/adeptsense.lua index 80f843e1..0d651bcc 100644 --- a/modules/lua/adeptsense.lua +++ b/modules/lua/adeptsense.lua @@ -7,11 +7,21 @@ module('_m.lua.adeptsense', package.seeall)
sense = _m.textadept.adeptsense.new('lua')
+sense.syntax.class_definition = 'module%s*%(?%s*[\'"]([%w_%.]+)'
sense.syntax.symbol_chars = '[%w_%.:]'
sense.api_files = { _HOME..'/modules/lua/api' }
sense:add_trigger('.')
sense:add_trigger(':', false, true)
-function sense:get_class(symbol) return nil end -- no such thing
+
+---
+-- Returns the current module's name (if any) for showing module completions in
+-- addition to global completions. Otherwise returns nil so only global
+-- completions are shown.
+-- @param symbol Must be the empty string ('').
+function sense:get_class(symbol)
+ if symbol ~= '' then return nil end -- no such thing
+ return self.super.get_class(self, symbol) -- try to get current module
+end
-- script/update_doc generates a fake set of ctags used for autocompletion.
sense.ctags_kinds = {
diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index f8c7dac0..2269925c 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -32,9 +32,9 @@ end --- -- Returns the class name for a given symbol. -- If the symbol is sense.syntax.self and a class definition using the --- sense.syntax.class keyword is found, that class is returned. Otherwise the --- buffer is searched backwards for a type declaration of the symbol according --- to the patterns in sense.syntax.type_declarations. +-- sense.syntax.class_definition keyword is found, that class is returned. +-- Otherwise the buffer is searched backwards for a type declaration of the +-- symbol according to the patterns in sense.syntax.type_declarations. -- @param sense The adeptsense returned by adeptsense.new(). -- @param symbol The symbol to get the class of. -- @return class or nil @@ -42,8 +42,8 @@ end function get_class(sense, symbol) local buffer = buffer local self = sense.syntax.self - local class_def = sense.syntax.class - local class_list = sense.class_list + local class_definition = sense.syntax.class_definition + local completions = sense.completions local symbol_chars = sense.syntax.symbol_chars local type_declarations = sense.syntax.type_declarations local class @@ -51,8 +51,8 @@ function get_class(sense, symbol) local s, e if symbol == self or symbol == '' then -- Determine classname from the class declaration. - s, e, class = buffer:get_line(i):find(class_def..'%s+([%w_]+)') - if class and not class_list[class] then class = nil end + s, e, class = buffer:get_line(i):find(class_definition) + if class and not completions[class] then class = nil end else -- Search for a type declaration. local line = buffer:get_line(i) @@ -463,7 +463,9 @@ api_files = {}, --- -- Contains syntax-specific values for the language. -- @field self The language's syntax-equivalent of 'self'. Default is 'self'. --- @field class The language's class definition keyword. Default is 'class'. +-- @field class_definition A Lua pattern representing the language's class +-- definition syntax. The first capture returned must be the class name. +-- Defaults to 'class%s+([%w_]+)'. -- @field symbol_chars A Lua pattern of characters allowed in a symbol, -- including member operators. Default is '[%w_%.]'. -- @field type_declarations A list of Lua patterns used for determining the @@ -474,7 +476,7 @@ api_files = {}, -- @see get_class syntax = { self = 'self', - class = 'class', + class_definition = 'class%s+([%w_]+)', symbol_chars = '[%w_%.]', type_declarations = { '(%u[%w_%.]+)%s+%_', -- Foo bar |