summaryrefslogtreecommitdiff
path: root/server-beta/src/proto
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-21 17:30:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-21 17:30:17 +0800
commit4215b35c77d879bddd1d19a71a2196e66fd439d8 (patch)
tree5f9537a637c30cb0ed3154d8e27a17427902462a /server-beta/src/proto
parent6e0641e480cc80afea6016a75ebb6c757c411867 (diff)
downloadlua-language-server-4215b35c77d879bddd1d19a71a2196e66fd439d8.zip
暂存
Diffstat (limited to 'server-beta/src/proto')
-rw-r--r--server-beta/src/proto/capability.lua2
-rw-r--r--server-beta/src/proto/init.lua58
-rw-r--r--server-beta/src/proto/provider.lua70
3 files changed, 72 insertions, 58 deletions
diff --git a/server-beta/src/proto/capability.lua b/server-beta/src/proto/capability.lua
index cc8489bd..71d3bca1 100644
--- a/server-beta/src/proto/capability.lua
+++ b/server-beta/src/proto/capability.lua
@@ -10,7 +10,7 @@ m.initer = {
},
hoverProvider = true,
- --definitionProvider = true,
+ definitionProvider = true,
--referencesProvider = true,
--renameProvider = true,
--documentSymbolProvider = true,
diff --git a/server-beta/src/proto/init.lua b/server-beta/src/proto/init.lua
index 56cb4930..e2fa1bb5 100644
--- a/server-beta/src/proto/init.lua
+++ b/server-beta/src/proto/init.lua
@@ -1,60 +1,4 @@
local proto = require 'proto.proto'
-local util = require 'utility'
-local cap = require 'proto.capability'
-local pub = require 'pub'
-local task = require 'task'
-local files = require 'files'
-
-proto.on('initialize', function (params)
- --log.debug(util.dump(params))
- return {
- capabilities = cap.initer,
- }
-end)
-
-proto.on('initialized', function (params)
- return true
-end)
-
-proto.on('exit', function ()
- log.info('Server exited.')
- os.exit(true)
-end)
-
-proto.on('shutdown', function ()
- log.info('Server shutdown.')
- return true
-end)
-
-proto.on('textDocument/hover', function ()
- return {
- contents = {
- value = 'Hello loli!',
- kind = 'markdown',
- }
- }
-end)
-
-proto.on('textDocument/didOpen', function (params)
- local doc = params.textDocument
- local uri = doc.uri
- local text = doc.text
- files.open(uri)
- files.setText(uri, text)
-end)
-
-proto.on('textDocument/didClose', function (params)
- local doc = params.textDocument
- local uri = doc.uri
- files.close(uri)
-end)
-
-proto.on('textDocument/didChange', function (params)
- local doc = params.textDocument
- local change = params.contentChanges
- local uri = doc.uri
- local text = change[1].text
- files.setText(uri, text)
-end)
+require 'proto.provider'
return proto
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
new file mode 100644
index 00000000..84463db9
--- /dev/null
+++ b/server-beta/src/proto/provider.lua
@@ -0,0 +1,70 @@
+local util = require 'utility'
+local cap = require 'proto.capability'
+local pub = require 'pub'
+local task = require 'task'
+local files = require 'files'
+local proto = require 'proto.proto'
+
+proto.on('initialize', function (params)
+ --log.debug(util.dump(params))
+ return {
+ capabilities = cap.initer,
+ }
+end)
+
+proto.on('initialized', function (params)
+ return true
+end)
+
+proto.on('exit', function ()
+ log.info('Server exited.')
+ os.exit(true)
+end)
+
+proto.on('shutdown', function ()
+ log.info('Server shutdown.')
+ return true
+end)
+
+proto.on('textDocument/didOpen', function (params)
+ local doc = params.textDocument
+ local uri = doc.uri
+ local text = doc.text
+ files.open(uri)
+ files.setText(uri, text)
+end)
+
+proto.on('textDocument/didClose', function (params)
+ local doc = params.textDocument
+ local uri = doc.uri
+ files.close(uri)
+end)
+
+proto.on('textDocument/didChange', function (params)
+ local doc = params.textDocument
+ local change = params.contentChanges
+ local uri = doc.uri
+ local text = change[1].text
+ files.setText(uri, text)
+end)
+
+proto.on('textDocument/hover', function ()
+ return {
+ contents = {
+ value = 'Hello loli!',
+ kind = 'markdown',
+ }
+ }
+end)
+
+proto.on('textDocument/definition', function (params)
+ local core = require 'core.definition'
+ local uri = params.textDocument.uri
+ local ast = files.getAst(uri)
+ local text = files.getText(uri)
+ local clock = os.clock()
+ local result, correct
+ repeat
+ result, correct = core(ast, text, pos)
+ until correct or os.clock() - clock >= 1.0
+end)