From ac476e05df2aab9f64cdd70b6eca0300785bb35d Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Tue, 23 Nov 2021 23:22:22 +0900 Subject: [PATCH] Remove misc.readonly Fix #571 --- lua/cmp/source.lua | 4 ++-- lua/cmp/utils/misc.lua | 13 ------------- lua/cmp/utils/misc_spec.lua | 8 -------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index 9f13789..476cc94 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -195,7 +195,7 @@ source.get_trigger_characters = function(self) local trigger_characters = {} if self.source.get_trigger_characters then - trigger_characters = self.source:get_trigger_characters(misc.readonly(self:get_config())) or {} + trigger_characters = self.source:get_trigger_characters(misc.copy(c)) or {} end if config.get().completion.get_trigger_characters then return config.get().completion.get_trigger_characters(trigger_characters) @@ -211,7 +211,7 @@ source.get_keyword_pattern = function(self) return c.keyword_pattern end if self.source.get_keyword_pattern then - return self.source:get_keyword_pattern(misc.readonly(c)) + return self.source:get_keyword_pattern(misc.copy(c)) end return config.get().completion.keyword_pattern end diff --git a/lua/cmp/utils/misc.lua b/lua/cmp/utils/misc.lua index f4ab5cf..a70d0b1 100644 --- a/lua/cmp/utils/misc.lua +++ b/lua/cmp/utils/misc.lua @@ -168,19 +168,6 @@ misc.to_vimindex = function(text, utfindex) return utfindex + 1 end ----Return readonly version object ----@generic T ----@param tbl T ----@return T -misc.readonly = function(tbl) - return setmetatable({}, { - __index = tbl, - __newindex = function() - error('this table is readonly.') - end, - }) -end - ---Mark the function as deprecated misc.deprecated = function(fn, msg) local printed = false diff --git a/lua/cmp/utils/misc_spec.lua b/lua/cmp/utils/misc_spec.lua index cd1a35b..1cafe29 100644 --- a/lua/cmp/utils/misc_spec.lua +++ b/lua/cmp/utils/misc_spec.lua @@ -49,12 +49,4 @@ describe('misc', function() assert.are.equal(merged.a, nil) end) - it('readonly', function() - local o = { a = 1, b = 2 } - local r = misc.readonly(o) - assert.are.equal(r.a, 1) - assert.has_error(function() - r.a = 5 - end) - end) end)