Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
make the first worked autocomplete for Tarantool box submodule
Browse files Browse the repository at this point in the history
Just uses Tarantool internal submodule for autocompletion.
Parse current string, select current selected token for completion
and call Tarantool internals.
  • Loading branch information
artur-barsegyan committed Dec 12, 2019
1 parent 16bd098 commit f0ee6cb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .luacompleterc

This file was deleted.

1 change: 1 addition & 0 deletions bin/tarantool-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ box.cfg {
log = fio.pathjoin(source_root, 'log.txt'),
log_level = 6,

checkpoint_interval = 0,
wal_mode = 'none',
}

Expand Down
4 changes: 2 additions & 2 deletions tarantool-lsp/analyze.lua
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ function analyze.refresh(document)
document.lines = lines

local start_time = os.clock()
log.info('ast start build! %s %s', document.text, document.uri)
-- log.info('ast start build! %s %s', document.text, document.uri)
local ast, err = parser.parse(document.text, document.uri, Config.language)
log.info('ast builded!')
-- log.info('ast builded!')
if ast then
document.ast = ast
document.validtext = document.text
Expand Down
1 change: 0 additions & 1 deletion tarantool-lsp/loop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ local function main(_)
while not Shutdown do
-- header
local data, err = rpc.decode()
log.info('new request %t', data)
if _G.Config.debugMode then
reload_all()
end
Expand Down
1 change: 0 additions & 1 deletion tarantool-lsp/lua-parser/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ function parser.parse(subject, filename, version)
local errorinfo = { subject = subject, filename = filename }
lpeg.setmaxstack(1000)
local ast, label, errpos = lpeg.match(G["5.3"], subject, nil, errorinfo)
require('log').info('hello')
if not ast then
local errmsg = labels[label][2]
return ast, syntaxerror(errorinfo, errpos, errmsg)
Expand Down
31 changes: 27 additions & 4 deletions tarantool-lsp/methods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ local utf = require 'tarantool-lsp.unicode'
local json = require 'json'
local unpack = table.unpack or unpack

local fun = require('fun')
local console = require('console')
local method_handlers = {}

function method_handlers.initialize(params, id)
if Initialized then
if _G.Initialized then
error("already initialized!")
end
Config.root = params.rootPath or params.rootUri
Expand Down Expand Up @@ -600,9 +602,30 @@ method_handlers["textDocument/completion"] = function(params, id)
end
end

-- Add Tarantool box.* space fields
for key, _ in pairs(box) do
table.insert(items, { label = key} )
local current_line = document.lines[params.position.line + 1]["text"]
local left_part = current_line:sub(0, params.position.character)
local last_token = left_part:match("[%w.:_]*$")
if last_token then
local completions = console.completion_handler(last_token, 0, last_token:len()) or {}
-- Completion handler returns input string at the first element
for _, cmplt in fun.tail(completions) do
local showedCmplt = cmplt
local insertedCmplt = cmplt
local cmpltKind = completionKinds["Field"]

if cmplt:find("[(]") then
cmpltKind = completionKinds["Function"]
showedCmplt = cmplt:gsub("%(", "")
end

table.insert(items, {
label = showedCmplt,
kind = cmpltKind,
insertText = insertedCmplt,
-- documentation = "box.cfg{} option",
detail = "detail information"
})
end
end

return rpc.respond(id, {
Expand Down

0 comments on commit f0ee6cb

Please sign in to comment.