-
Notifications
You must be signed in to change notification settings - Fork 1
/
session_manager.lua
108 lines (94 loc) · 2.45 KB
/
session_manager.lua
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require('nis.sessions')
require('nis.utils')
require('nis.commands')
require('nis.project_lookup')
require('nis.project')
local sessions = {} -- a table "filepath" - session
local function current_session()
if vis.win and vis.win.file and vis.win.file.project then
return sessions[vis.win.file.project]
end
end
local function on_brace(session)
vis:insert("(")
session:context()
return true
end
local function suggest_dot(session)
vis:insert(".")
session:suggest()
return true
end
function check_it()
local session = current_session()
if session == nil then return end
session:check()
end
function goto_def()
local session = current_session()
if session == nil then return end
session:goto_definition()
end
function get_help()
local session = current_session()
if session == nil then return end
session:help()
end
function suggest_key()
local session = current_session()
if session == nil then return end
session:suggest()
end
local keyactions = {
['('] = on_brace,
['.'] = suggest_dot,
}
function dispatch_input(key)
local session = current_session()
if session == nil then return end
if keyactions[key] then return keyactions[key](session) end
end
function on_open(file)
if file == nil or file.path == nil or #file.path < 5 then return end
if file.path:sub(-3) == "nim" then
file.project, file.nimblefile = find_projectfile(file.path)
vis:info("'"..file.project.."' used as a projectfile.")
if sessions[file.project] then
local cur = sessions[file.project].refcounter
sessions[file.project].refcounter = cur + 1
else
sessions[file.project] = Session.new(file.project)
sessions[file.project].refcounter = 1
end
--debugme(sessions[file.project])
end
end
function on_close(file)
if not file.project or not sessions[file.project] then return end
local cur = sessions[file.project].refcounter
if cur - 1 == 0 then
sessions[file.project]:close()
sessions[file.project] = nil
collectgarbage()
else
sessions[file.project].refcounter = cur - 1
end
end
function cycle_all(window)
if vis.ignore then return end -- The lock to prevent endless windows updates
vis.ignore = true
for _, session in pairs(sessions) do
session:cycle()
end
if window.triggers then
for tname, trigger in pairs(window.triggers) do
trigger(window)
end
end
vis.ignore = false
end
function stop_all()
for _, session in pairs(sessions) do
session:close()
end
end