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