Moved syntax
from doc.highlighter
to doc
This commit is contained in:
parent
a754c60127
commit
31820b36ef
|
@ -221,7 +221,7 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:toggle-line-comments"] = function()
|
["doc:toggle-line-comments"] = function()
|
||||||
local comment = doc().highlighter.syntax.comment
|
local comment = doc().syntax.comment
|
||||||
if not comment then return end
|
if not comment then return end
|
||||||
local comment_text = comment .. " "
|
local comment_text = comment .. " "
|
||||||
local line1, _, line2 = doc():get_selection(true)
|
local line1, _, line2 = doc():get_selection(true)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
local core = require "core"
|
local core = require "core"
|
||||||
local syntax = require "core.syntax"
|
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local tokenizer = require "core.tokenizer"
|
local tokenizer = require "core.tokenizer"
|
||||||
local Object = require "core.object"
|
local Object = require "core.object"
|
||||||
|
@ -10,7 +9,9 @@ local Highlighter = Object:extend()
|
||||||
|
|
||||||
function Highlighter:new(doc)
|
function Highlighter:new(doc)
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self:reset_syntax()
|
self.lines = {}
|
||||||
|
self.last_valid_line = 1
|
||||||
|
self.max_wanted_line = 0
|
||||||
|
|
||||||
-- init incremental syntax highlighting
|
-- init incremental syntax highlighting
|
||||||
core.add_thread(function()
|
core.add_thread(function()
|
||||||
|
@ -39,28 +40,17 @@ function Highlighter:new(doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Highlighter:reset_syntax()
|
|
||||||
local syn = syntax.get(self.doc.filename or "")
|
|
||||||
if self.syntax ~= syn then
|
|
||||||
self.syntax = syn
|
|
||||||
self.lines = {}
|
|
||||||
self.last_valid_line = 1
|
|
||||||
self.max_wanted_line = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function Highlighter:invalidate(idx)
|
function Highlighter:invalidate(idx)
|
||||||
self.last_valid_line = idx
|
self.last_valid_line = idx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Highlighter:tokenize_line(idx, state)
|
function Highlighter:tokenize_line(idx, state)
|
||||||
local line = {}
|
local res = {}
|
||||||
line.init_state = state
|
res.init_state = state
|
||||||
line.text = self.doc.lines[idx]
|
res.text = self.doc.lines[idx]
|
||||||
line.tokens, line.state = tokenizer.tokenize(self.syntax, line.text, state)
|
res.tokens, res.state = tokenizer.tokenize(self.doc.syntax, res.text, state)
|
||||||
return line
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
local Object = require "core.object"
|
local Object = require "core.object"
|
||||||
local Highlighter = require "core.doc.highlighter"
|
local Highlighter = require "core.doc.highlighter"
|
||||||
|
local syntax = require "core.syntax"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local common = require "core.common"
|
local common = require "core.common"
|
||||||
|
|
||||||
|
@ -50,6 +51,16 @@ function Doc:reset()
|
||||||
self.redo_stack = { idx = 1 }
|
self.redo_stack = { idx = 1 }
|
||||||
self.clean_change_id = 1
|
self.clean_change_id = 1
|
||||||
self.highlighter = Highlighter(self)
|
self.highlighter = Highlighter(self)
|
||||||
|
self:reset_syntax()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Doc:reset_syntax()
|
||||||
|
local syn = syntax.get(self.filename or "")
|
||||||
|
if self.syntax ~= syn then
|
||||||
|
self.syntax = syn
|
||||||
|
self.highlighter:invalidate(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +80,7 @@ function Doc:load(filename)
|
||||||
table.insert(self.lines, "\n")
|
table.insert(self.lines, "\n")
|
||||||
end
|
end
|
||||||
fp:close()
|
fp:close()
|
||||||
self.highlighter:reset_syntax()
|
self:reset_syntax()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +93,7 @@ function Doc:save(filename)
|
||||||
end
|
end
|
||||||
fp:close()
|
fp:close()
|
||||||
self.filename = filename or self.filename
|
self.filename = filename or self.filename
|
||||||
self.highlighter:reset_syntax()
|
self:reset_syntax()
|
||||||
self:clean()
|
self:clean()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue