diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/completion.lua | 3 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 1 | ||||
-rw-r--r-- | server/src/method/textDocument/completion.lua | 6 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 8 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 31 | ||||
-rw-r--r-- | server/test/completion/init.lua | 17 | ||||
-rw-r--r-- | server/test/vm/dirty.lua | 7 |
7 files changed, 60 insertions, 13 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index aae94efd..0ef3317e 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -33,6 +33,9 @@ local function matchKey(me, other) if me == other then return false end + if me == '' then + return true + end if #me > #other then return false end diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 76fe3793..05a1bb49 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -22,6 +22,7 @@ return function (lsp) -- 自动完成 completionProvider = { resolveProvider = false, + triggerCharacters = { '.', ':' }, }, -- 工作目录 workspace = { diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index 2ecc06a5..9ed4e09a 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -12,9 +12,15 @@ return function (lsp, params) if not items then return nil end + if #items == 0 then + return nil + end for i, item in ipairs(items) do item.sortText = ('%04d'):format(i) end + if items[5] then + items[5].preselect = true + end local response = { isIncomplete = false, items = items, diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 5e6b9fcf..ff6f9a29 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -69,6 +69,14 @@ local defs = { [1] = str, } end, + DirtyName = function (pos) + return { + type = 'name', + start = pos, + finish = pos, + [1] = '' + } + end, Simple = function (first, ...) if ... then local obj = { diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index d4a7f648..64837f7c 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -185,8 +185,8 @@ TR <- Sp '}' COMMA <- Sp ',' SEMICOLON <- Sp ';' DOTS <- Sp ({} '...') -> DOTS -DOT <- Sp '.' -COLON <- Sp ({} ':') -> COLON +DOT <- Sp '.' !'.' +COLON <- Sp ({} ':' !':') -> COLON LABEL <- Sp '::' ASSIGN <- Sp '=' @@ -229,6 +229,8 @@ Name <- Sp ({} NameBody {}) -> Name NameBody <- ([a-zA-Z_] [a-zA-Z0-9_]*) => NotReserved +MustName <- Name + / {} -> DirtyName ]] grammar 'Exp' [[ @@ -259,8 +261,8 @@ Simple <- (Prefix (Suffix)*) -> Simple Prefix <- PL Exp PR / Name -Suffix <- DOT Name - / COLON Name +Suffix <- DOT MustName + / COLON MustName / Sp ({} Table {}) -> Call / Sp ({} String {}) -> Call / BL Exp -> Index BR @@ -268,12 +270,15 @@ Suffix <- DOT Name ExpList <- (Exp (COMMA Exp)*)? -> List -NameList <- (Name (COMMA Name)*)? +NameList <- (Name (COMMA MustName)*)? -> List -ArgList <- (Arg (COMMA Arg)*)? +ArgList <- (FirstArg (COMMA AfterArg)*)? -> List -Arg <- DOTS +FirstArg <- DOTS / Name +AfterArg <- DOTS + / MustName + Table <- Sp ({} TL TableFields TR {}) -> Table @@ -283,7 +288,7 @@ TableSep <- COMMA / SEMICOLON TableField <- NewIndex / NewField / Exp NewIndex <- (BL Exp BR ASSIGN Exp) -> NewIndex -NewField <- (Name ASSIGN Exp) +NewField <- (MustName ASSIGN Exp) -> NewField Function <- Sp ({} FunctionBody {}) @@ -293,8 +298,8 @@ FunctionBody<- FUNCTION FuncName PL ArgList PR END FuncName <- (Name? (FuncSuffix)*) -> Simple -FuncSuffix <- DOT Name - / COLON Name +FuncSuffix <- DOT MustName + / COLON MustName -- 纯占位,修改了 `relabel.lua` 使重复定义不抛错 Action <- !END . @@ -331,9 +336,9 @@ Break <- BREAK Return <- RETURN ExpList? -> Return -Label <- LABEL Name -> Label LABEL +Label <- LABEL MustName -> Label LABEL -GoTo <- GOTO Name -> GoTo +GoTo <- GOTO MustName -> GoTo If <- Sp ({} IfBody {}) -> If @@ -355,7 +360,7 @@ Loop <- Sp ({} LoopBody {}) LoopBody <- (FOR LoopStart LoopFinish LoopStep? DO) -> LoopDef Action* END -LoopStart <- Name ASSIGN Exp +LoopStart <- MustName ASSIGN Exp LoopFinish <- COMMA Exp LoopStep <- COMMA Exp diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 1524badf..c666dd5d 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -195,3 +195,20 @@ loc@ kind = CompletionItemKind.Keyword, } } + +TEST [[ +t.a = {} +t.b = {} +t.@ +]] +{ + { + label = 'a', + kind = CompletionItemKind.Field, + }, + { + label = 'b', + kind = CompletionItemKind.Field, + }, +} + diff --git a/server/test/vm/dirty.lua b/server/test/vm/dirty.lua index e69de29b..9c2e65fb 100644 --- a/server/test/vm/dirty.lua +++ b/server/test/vm/dirty.lua @@ -0,0 +1,7 @@ +TEST [[ +a. +]] + +TEST [[ +a: +]] |