From 8602723c7127e2fd6380c602650de62bd8afad02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 20 Sep 2019 17:57:28 +0800 Subject: =?UTF-8?q?=E7=AE=80=E5=8D=95=E7=9A=84=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/files.lua | 41 +++++++++++++++++++++++++++++++++++++++++ server-beta/src/proto/init.lua | 13 +++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 server-beta/src/files.lua (limited to 'server-beta/src') diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua new file mode 100644 index 00000000..eaf92ba6 --- /dev/null +++ b/server-beta/src/files.lua @@ -0,0 +1,41 @@ +local platform = require 'bee.platform' + +local m = {} + +m.openMap = {} +m.textMap = {} +m.astMap = {} + +--- 打开文件 +function m.open(uri) + if platform.OS == 'Windows' then + uri = uri:lower() + end + m.openMap[uri] = true +end + +--- 关闭文件 +function m.close(uri) + if platform.OS == 'Windows' then + uri = uri:lower() + end + m.openMap[uri] = nil +end + +--- 设置文件文本 +function m.setText(uri, text) + if platform.OS == 'Windows' then + uri = uri:lower() + end + m.textMap[uri] = text +end + +--- 设置文件语法树 +function m.setAst(uri, ast) + if platform.OS == 'Windows' then + uri = uri:lower() + end + m.astMap[uri] = ast +end + +return m diff --git a/server-beta/src/proto/init.lua b/server-beta/src/proto/init.lua index 6e52fcbe..26fd5df8 100644 --- a/server-beta/src/proto/init.lua +++ b/server-beta/src/proto/init.lua @@ -3,6 +3,7 @@ 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)) @@ -38,10 +39,16 @@ proto.on('textDocument/didOpen', function (params) local doc = params.textDocument local uri = doc.uri local text = doc.text - local state = pub.task('compile', text) + files.open(uri) + files.setText(uri, text) + local ast = pub.task('compile', text) + files.setAst(uri, ast) 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) @@ -49,7 +56,9 @@ proto.on('textDocument/didChange', function (params) local change = params.contentChanges local uri = doc.uri local text = change[1].text - local state = pub.task('compile', text) + files.setText(uri, text) + local ast = pub.task('compile', text) + files.setAst(uri, ast) end) return proto -- cgit v1.2.3