1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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)
|