diff --git a/lua/cmp/config.lua b/lua/cmp/config.lua index 42e9a43..59cac83 100644 --- a/lua/cmp/config.lua +++ b/lua/cmp/config.lua @@ -14,7 +14,7 @@ config.cache = cache.new() ---@type cmp.ConfigSchema config.global = require('cmp.config.default')() ----@type table +---@type table config.buffers = {} ---@type table @@ -36,7 +36,7 @@ end ---Set configuration for buffer ---@param c cmp.ConfigSchema ----@param bufnr number|nil +---@param bufnr integer config.set_buffer = function(c, bufnr) local revision = (config.buffers[bufnr] or {}).revision or 1 config.buffers[bufnr] = c or {} @@ -150,9 +150,6 @@ end ---Return the current menu is native or not. config.is_native_menu = function() local c = config.get() - if c.experimental and c.experimental.native_menu then - return true - end if c.view and c.view.entries then return c.view.entries == 'native' or c.view.entries.name == 'native' end @@ -164,6 +161,7 @@ end ---@return cmp.ConfigSchema config.normalize = function(c) -- make sure c is not 'nil' + ---@type any c = c == nil and {} or c -- Normalize mapping. diff --git a/lua/cmp/context.lua b/lua/cmp/context.lua index 6188259..0c25462 100644 --- a/lua/cmp/context.lua +++ b/lua/cmp/context.lua @@ -10,8 +10,8 @@ local api = require('cmp.utils.api') ---@field public prev_context cmp.Context ---@field public option cmp.ContextOption ---@field public filetype string ----@field public time number ----@field public bufnr number +---@field public time integer +---@field public bufnr integer ---@field public cursor vim.Position|lsp.Position ---@field public cursor_line string ---@field public cursor_after_line string @@ -31,8 +31,8 @@ context.empty = function() end ---Create new context ----@param prev_context cmp.Context ----@param option cmp.ContextOption +---@param prev_context? cmp.Context +---@param option? cmp.ContextOption ---@return cmp.Context context.new = function(prev_context, option) option = option or {} @@ -65,7 +65,7 @@ context.get_reason = function(self) end ---Get keyword pattern offset ----@return number|nil +---@return integer context.get_offset = function(self, keyword_pattern) return self.cache:ensure({ 'get_offset', keyword_pattern, self.cursor_before_line }, function() return pattern.offset(keyword_pattern .. '\\m$', self.cursor_before_line) or self.cursor.col diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 196b25e..aec6269 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -49,7 +49,7 @@ core.register_source = function(self, s) end ---Unregister source ----@param source_id string +---@param source_id integer core.unregister_source = function(self, source_id) self.sources[source_id] = nil end diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index ab03753..889baa5 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -7,15 +7,15 @@ local types = require('cmp.types') local matcher = require('cmp.matcher') ---@class cmp.Entry ----@field public id number +---@field public id integer ---@field public cache cmp.Cache ---@field public match_cache cmp.Cache ----@field public score number +---@field public score integer ---@field public exact boolean ---@field public matches table ---@field public context cmp.Context ---@field public source cmp.Source ----@field public source_offset number +---@field public source_offset integer ---@field public source_insert_range lsp.Range ---@field public source_replace_range lsp.Range ---@field public completion_item lsp.CompletionItem @@ -52,12 +52,13 @@ entry.new = function(ctx, source, completion_item) end ---Make offset value ----@return number +---@return integer entry.get_offset = function(self) return self.cache:ensure({ 'get_offset', self.resolved_completion_item and 1 or 0 }, function() local offset = self.source_offset if misc.safe(self:get_completion_item().textEdit) then - local range = misc.safe(self:get_completion_item().textEdit.insert) or misc.safe(self:get_completion_item().textEdit.range) + local range = misc.safe(self:get_completion_item().textEdit.insert) or + misc.safe(self:get_completion_item().textEdit.range) if range then local c = misc.to_vimindex(self.context.cursor_line, range.start.character) for idx = c, self.source_offset do @@ -130,16 +131,19 @@ entry.get_word = function(self) end ---Get overwrite information ----@return number, number +---@return integer, integer entry.get_overwrite = function(self) return self.cache:ensure({ 'get_overwrite', self.resolved_completion_item and 1 or 0 }, function() if misc.safe(self:get_completion_item().textEdit) then - local r = misc.safe(self:get_completion_item().textEdit.insert) or misc.safe(self:get_completion_item().textEdit.range) - local s = misc.to_vimindex(self.context.cursor_line, r.start.character) - local e = misc.to_vimindex(self.context.cursor_line, r['end'].character) - local before = self.context.cursor.col - s - local after = e - self.context.cursor.col - return { before, after } + local r = misc.safe(self:get_completion_item().textEdit.insert) or + misc.safe(self:get_completion_item().textEdit.range) + if r then + local s = misc.to_vimindex(self.context.cursor_line, r.start.character) + local e = misc.to_vimindex(self.context.cursor_line, r['end'].character) + local before = self.context.cursor.col - s + local after = e - self.context.cursor.col + return { before, after } + end end return { 0, 0 } end) @@ -184,13 +188,14 @@ end ---Return the item is deprecated or not. ---@return boolean entry.is_deprecated = function(self) - return self:get_completion_item().deprecated or vim.tbl_contains(self:get_completion_item().tags or {}, types.lsp.CompletionItemTag.Deprecated) + return self:get_completion_item().deprecated or + vim.tbl_contains(self:get_completion_item().tags or {}, types.lsp.CompletionItemTag.Deprecated) end ---Return view information. ----@param suggest_offset number ----@param entries_buf number The buffer this entry will be rendered into. ----@return { abbr: { text: string, bytes: number, width: number, hl_group: string }, kind: { text: string, bytes: number, width: number, hl_group: string }, menu: { text: string, bytes: number, width: number, hl_group: string } } +---@param suggest_offset integer +---@param entries_buf integer The buffer this entry will be rendered into. +---@return { abbr: { text: string, bytes: integer, width: integer, hl_group: string }, kind: { text: string, bytes: integer, width: integer, hl_group: string }, menu: { text: string, bytes: integer, width: integer, hl_group: string } } entry.get_view = function(self, suggest_offset, entries_buf) local item = self:get_vim_item(suggest_offset) return self.cache:ensure({ 'get_view', self.resolved_completion_item and 1 or 0, entries_buf }, function() @@ -208,7 +213,8 @@ entry.get_view = function(self, suggest_offset, entries_buf) view.kind.text = item.kind or '' view.kind.bytes = #view.kind.text view.kind.width = vim.fn.strdisplaywidth(view.kind.text) - view.kind.hl_group = item.kind_hl_group or ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '')) + view.kind.hl_group = item.kind_hl_group or ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '') + ) view.menu = {} view.menu.text = item.menu or '' view.menu.bytes = #view.menu.text @@ -221,7 +227,7 @@ entry.get_view = function(self, suggest_offset, entries_buf) end ---Make vim.CompletedItem ----@param suggest_offset number +---@param suggest_offset integer ---@return vim.CompletedItem entry.get_vim_item = function(self, suggest_offset) return self.cache:ensure({ 'get_vim_item', suggest_offset, self.resolved_completion_item and 1 or 0 }, function() @@ -313,7 +319,8 @@ entry.get_insert_range = function(self) insert_range = { start = { line = self.context.cursor.row - 1, - character = math.min(misc.to_utfindex(self.context.cursor_line, self:get_offset()), self.source_insert_range.start.character), + character = math.min(misc.to_utfindex(self.context.cursor_line, self:get_offset()), + self.source_insert_range.start.character), }, ['end'] = self.source_insert_range['end'], } @@ -332,7 +339,8 @@ entry.get_replace_range = function(self) replace_range = { start = { line = self.source_replace_range.start.line, - character = math.min(misc.to_utfindex(self.context.cursor_line, self:get_offset()), self.source_replace_range.start.character), + character = math.min(misc.to_utfindex(self.context.cursor_line, self:get_offset()), + self.source_replace_range.start.character), }, ['end'] = self.source_replace_range['end'], } @@ -344,7 +352,7 @@ end ---Match line. ---@param input string ---@param matching_config cmp.MatchingConfig ----@return { score: number, matches: table[] } +---@return { score: integer, matches: table[] } entry.match = function(self, input, matching_config) return self.match_cache:ensure({ input, @@ -372,7 +380,7 @@ entry.match = function(self, input, matching_config) local diff = self.source_offset - self:get_offset() if diff > 0 then local prefix = string.sub(self.context.cursor_line, self:get_offset(), self:get_offset() + diff) - local accept = false + local accept = nil accept = accept or string.match(prefix, '^[^%a]+$') accept = accept or string.find(self:get_completion_item().textEdit.newText, prefix, 1, true) if accept then @@ -425,13 +433,23 @@ entry.get_documentation = function(self) }) end - if type(item.documentation) == 'string' and item.documentation ~= '' then - table.insert(documents, { - kind = types.lsp.MarkupKind.PlainText, - value = str.trim(item.documentation), - }) - elseif type(item.documentation) == 'table' and item.documentation.value ~= '' then - table.insert(documents, item.documentation) + local documentation = item.documentation + if type(documentation) == 'string' and documentation ~= '' then + local value = str.trim(documentation) + if value ~= '' then + table.insert(documents, { + kind = types.lsp.MarkupKind.PlainText, + value = value, + }) + end + elseif type(documentation) == 'table' and documentation.value ~= '' then + local value = str.trim(documentation.value) + if value ~= '' then + table.insert(documents, { + kind = documentation.kind, + value = value, + }) + end end return vim.lsp.util.convert_input_to_markdown_lines(documents) diff --git a/lua/cmp/init.lua b/lua/cmp/init.lua index 45cc61e..70d533c 100644 --- a/lua/cmp/init.lua +++ b/lua/cmp/init.lua @@ -50,7 +50,7 @@ end ---Register completion sources ---@param name string ---@param s cmp.Source ----@return number +---@return integer cmp.register_source = function(name, s) local src = source.new(name, s) cmp.core:register_source(src) @@ -58,7 +58,7 @@ cmp.register_source = function(name, s) end ---Unregister completion source ----@param id number +---@param id integer cmp.unregister_source = function(id) cmp.core:unregister_source(id) end diff --git a/lua/cmp/matcher.lua b/lua/cmp/matcher.lua index 7a22d9e..8a3396e 100644 --- a/lua/cmp/matcher.lua +++ b/lua/cmp/matcher.lua @@ -79,7 +79,7 @@ end ---@param input string ---@param word string ---@param option { synonyms: string[], disallow_fuzzy_matching: boolean, disallow_partial_matching: boolean, disallow_prefix_unmatching: boolean } ----@return number +---@return integer matcher.match = function(input, word, option) option = option or {} diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index bee0634..f081642 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -10,16 +10,16 @@ local pattern = require('cmp.utils.pattern') local char = require('cmp.utils.char') ---@class cmp.Source ----@field public id number +---@field public id integer ---@field public name string ---@field public source any ---@field public cache cmp.Cache ----@field public revision number +---@field public revision integer ---@field public incomplete boolean ---@field public is_triggered_by_symbol boolean ---@field public entries cmp.Entry[] ----@field public offset number ----@field public request_offset number +---@field public offset integer +---@field public request_offset integer ---@field public context cmp.Context ---@field public completion_context lsp.CompletionContext|nil ---@field public status cmp.SourceStatus @@ -132,10 +132,10 @@ source.get_entries = function(self, ctx) end ---Get default insert range ----@return lsp.Range|nil +---@return lsp.Range source.get_default_insert_range = function(self) if not self.context then - return nil + error('context is not initialized yet.') end return self.cache:ensure({ 'get_default_insert_range', self.revision }, function() @@ -153,10 +153,10 @@ source.get_default_insert_range = function(self) end ---Get default replace range ----@return lsp.Range|nil +---@return lsp.Range source.get_default_replace_range = function(self) if not self.context then - return nil + error('context is not initialized yet.') end return self.cache:ensure({ 'get_default_replace_range', self.revision }, function() @@ -223,7 +223,7 @@ source.get_keyword_pattern = function(self) end ---Get keyword_length ----@return number +---@return integer source.get_keyword_length = function(self) local c = self:get_source_config() if c.keyword_length then diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index 996165a..f73e774 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -51,7 +51,7 @@ cmp.ItemField = { ---@class cmp.SnippetExpansionParams ---@field public body string ----@field public insert_text_mode number +---@field public insert_text_mode integer ---@class cmp.CompleteParams ---@field public reason? cmp.ContextReason @@ -67,7 +67,7 @@ cmp.ItemField = { ---@class cmp.SourceApiParams: cmp.SourceConfig ---@class cmp.SourceCompletionApiParams : cmp.SourceConfig ----@field public offset number +---@field public offset integer ---@field public context cmp.Context ---@field public completion_context lsp.CompletionContext @@ -78,7 +78,7 @@ cmp.ItemField = { ---@field public s nil|function(fallback: function): void ---@class cmp.ConfigSchema ----@field private revision number +---@field private revision integer ---@field public enabled fun():boolean|boolean ---@field public performance cmp.PerformanceConfig ---@field public preselect cmp.PreselectMode @@ -95,8 +95,8 @@ cmp.ItemField = { ---@field public experimental cmp.ExperimentalConfig ---@class cmp.PerformanceConfig ----@field public debounce number ----@field public throttle number +---@field public debounce integer +---@field public throttle integer ---@class cmp.WindowConfig ---@field completion cmp.WindowConfig @@ -106,15 +106,15 @@ cmp.ItemField = { ---@field public autocomplete cmp.TriggerEvent[] ---@field public completeopt string ---@field public get_trigger_characters fun(trigger_characters: string[]): string[] ----@field public keyword_length number +---@field public keyword_length integer ---@field public keyword_pattern string ---@class cmp.WindowConfig ---@field public border string|string[] ---@field public winhighlight string ----@field public zindex number|nil ----@field public max_width number|nil ----@field public max_height number|nil +---@field public zindex integer|nil +---@field public max_width integer|nil +---@field public max_height integer|nil ---@class cmp.ConfirmationConfig ---@field public default_behavior cmp.ConfirmBehavior @@ -126,7 +126,7 @@ cmp.ItemField = { ---@field public disallow_prefix_unmatching boolean ---@class cmp.SortingConfig ----@field public priority_weight number +---@field public priority_weight integer ---@field public comparators function[] ---@class cmp.FormattingConfig @@ -145,12 +145,12 @@ cmp.ItemField = { ---@class cmp.SourceConfig ---@field public name string ---@field public option table|nil ----@field public priority number|nil +---@field public priority integer|nil ---@field public trigger_characters string[]|nil ---@field public keyword_pattern string|nil ----@field public keyword_length number|nil ----@field public max_item_count number|nil ----@field public group_index number|nil +---@field public keyword_length integer|nil +---@field public max_item_count integer|nil +---@field public group_index integer|nil ---@class cmp.ViewConfig ---@field public entries cmp.EntriesConfig diff --git a/lua/cmp/types/lsp.lua b/lua/cmp/types/lsp.lua index 3b20f1f..2bf5cb0 100644 --- a/lua/cmp/types/lsp.lua +++ b/lua/cmp/types/lsp.lua @@ -6,7 +6,7 @@ local lsp = {} lsp.Position = { ---Convert lsp.Position to vim.Position - ---@param buf number|string + ---@param buf integer|string ---@param position lsp.Position ---@return vim.Position to_vim = function(buf, position) @@ -26,7 +26,7 @@ lsp.Position = { } end, ---Convert vim.Position to lsp.Position - ---@param buf number|string + ---@param buf integer|string ---@param position vim.Position ---@return lsp.Position to_lsp = function(buf, position) @@ -49,7 +49,7 @@ lsp.Position = { lsp.Range = { ---Convert lsp.Range to vim.Range - ---@param buf number|string + ---@param buf integer|string ---@param range lsp.Range ---@return vim.Range to_vim = function(buf, range) @@ -60,7 +60,7 @@ lsp.Range = { end, ---Convert vim.Range to lsp.Range - ---@param buf number|string + ---@param buf integer|string ---@param range vim.Range ---@return lsp.Range to_lsp = function(buf, range) @@ -145,8 +145,8 @@ lsp.CompletionItemKind = vim.tbl_add_reverse_lookup(lsp.CompletionItemKind) ---@field public value string ---@class lsp.Position ----@field public line number ----@field public character number +---@field public line integer +---@field public character integer ---@class lsp.Range ---@field public start lsp.Position @@ -161,9 +161,14 @@ lsp.CompletionItemKind = vim.tbl_add_reverse_lookup(lsp.CompletionItemKind) ---@field public range lsp.Range|nil ---@field public newText string ----@class lsp.InsertReplaceTextEdit ----@field public insert lsp.Range|nil ----@field public replace lsp.Range|nil +---@alias lsp.InsertReplaceTextEdit lsp.internal.InsertTextEdit|lsp.internal.ReplaceTextEdit + +---@class lsp.internal.InsertTextEdit +---@field public insert lsp.Range +---@field public newText string + +---@class lsp.internal.ReplaceTextEdit +---@field public insert lsp.Range ---@field public newText string ---@class lsp.CompletionItemLabelDetails diff --git a/lua/cmp/types/vim.lua b/lua/cmp/types/vim.lua index 95e757d..e9d9075 100644 --- a/lua/cmp/types/vim.lua +++ b/lua/cmp/types/vim.lua @@ -12,8 +12,8 @@ ---@field public menu_hl_group string|nil ---@class vim.Position ----@field public row number ----@field public col number +---@field public row integer +---@field public col integer ---@class vim.Range ---@field public start vim.Position diff --git a/lua/cmp/utils/async.lua b/lua/cmp/utils/async.lua index 13f126b..e1581e2 100644 --- a/lua/cmp/utils/async.lua +++ b/lua/cmp/utils/async.lua @@ -2,13 +2,13 @@ local async = {} ---@class cmp.AsyncThrottle ---@field public running boolean ----@field public timeout number ----@field public sync function(self: cmp.AsyncThrottle, timeout: number|nil) +---@field public timeout integer +---@field public sync function(self: cmp.AsyncThrottle, timeout: integer|nil) ---@field public stop function ---@field public __call function ---@param fn function ----@param timeout number +---@param timeout integer ---@return cmp.AsyncThrottle async.throttle = function(fn, timeout) local time = nil @@ -60,7 +60,7 @@ end ---Timeout callback function ---@param fn function ----@param timeout number +---@param timeout integer ---@return function async.timeout = function(fn, timeout) local timer diff --git a/lua/cmp/utils/binary.lua b/lua/cmp/utils/binary.lua index c6a7088..b799f96 100644 --- a/lua/cmp/utils/binary.lua +++ b/lua/cmp/utils/binary.lua @@ -12,7 +12,7 @@ end ---@param list any[] ---@param item any ---@param func fun(a: any, b: any): 1|-1|0 ----@return number +---@return integer binary.search = function(list, item, func) local s = 1 local e = #list diff --git a/lua/cmp/utils/buffer.lua b/lua/cmp/utils/buffer.lua index 63171c9..0705cbc 100644 --- a/lua/cmp/utils/buffer.lua +++ b/lua/cmp/utils/buffer.lua @@ -2,7 +2,7 @@ local buffer = {} buffer.cache = {} ----@return number buf +---@return integer buf buffer.get = function(name) local buf = buffer.cache[name] if buf and vim.api.nvim_buf_is_valid(buf) then @@ -12,7 +12,7 @@ buffer.get = function(name) end end ----@return number buf +---@return integer buf ---@return boolean created_new buffer.ensure = function(name) local created_new = false diff --git a/lua/cmp/utils/cache.lua b/lua/cmp/utils/cache.lua index 8607b2a..26456ad 100644 --- a/lua/cmp/utils/cache.lua +++ b/lua/cmp/utils/cache.lua @@ -9,7 +9,7 @@ cache.new = function() end ---Get cache value ----@param key string +---@param key string|string[] ---@return any|nil cache.get = function(self, key) key = self:key(key) @@ -20,7 +20,7 @@ cache.get = function(self, key) end ---Set cache value explicitly ----@param key string +---@param key string|string[] ---@vararg any cache.set = function(self, key, value) key = self:key(key) @@ -28,8 +28,10 @@ cache.set = function(self, key, value) end ---Ensure value by callback ----@param key string ----@param callback fun(): any +---@generic T +---@param key string|string[] +---@param callback fun(): T +---@return T cache.ensure = function(self, key, callback) local value = self:get(key) if value == nil then @@ -46,7 +48,7 @@ cache.clear = function(self) end ---Create key ----@param key string|table +---@param key string|string[] ---@return string cache.key = function(_, key) if type(key) == 'table' then diff --git a/lua/cmp/utils/char.lua b/lua/cmp/utils/char.lua index 6e18994..c733bef 100644 --- a/lua/cmp/utils/char.lua +++ b/lua/cmp/utils/char.lua @@ -22,50 +22,50 @@ end) local char = {} ----@param byte number +---@param byte integer ---@return boolean char.is_upper = function(byte) return ALPHA[byte] end ----@param byte number +---@param byte integer ---@return boolean char.is_alpha = function(byte) return alpha[byte] or ALPHA[byte] end ----@param byte number +---@param byte integer ---@return boolean char.is_digit = function(byte) return digit[byte] end ----@param byte number +---@param byte integer ---@return boolean char.is_white = function(byte) return white[byte] end ----@param byte number +---@param byte integer ---@return boolean char.is_symbol = function(byte) return not (char.is_alnum(byte) or char.is_white(byte)) end ----@param byte number +---@param byte integer ---@return boolean char.is_printable = function(byte) return string.match(string.char(byte), '^%c$') == nil end ----@param byte number +---@param byte integer ---@return boolean char.is_alnum = function(byte) return char.is_alpha(byte) or char.is_digit(byte) end ---@param text string ----@param index number +---@param index integer ---@return boolean char.is_semantic_index = function(text, index) if index <= 1 then @@ -91,8 +91,8 @@ char.is_semantic_index = function(text, index) end ---@param text string ----@param current_index number ----@return boolean +---@param current_index integer +---@return integer char.get_next_semantic_index = function(text, current_index) for i = current_index + 1, #text do if char.is_semantic_index(text, i) then @@ -103,8 +103,8 @@ char.get_next_semantic_index = function(text, current_index) end ---Ignore case match ----@param byte1 number ----@param byte2 number +---@param byte1 integer +---@param byte2 integer ---@return boolean char.match = function(byte1, byte2) if not char.is_alpha(byte1) or not char.is_alpha(byte2) then diff --git a/lua/cmp/utils/keymap.lua b/lua/cmp/utils/keymap.lua index aea5c1d..fba0f94 100644 --- a/lua/cmp/utils/keymap.lua +++ b/lua/cmp/utils/keymap.lua @@ -68,7 +68,7 @@ keymap.undojoin = function() end ---Create backspace keys. ----@param count number +---@param count integer ---@return string keymap.backspace = function(count) if type(count) == 'string' then diff --git a/lua/cmp/utils/misc.lua b/lua/cmp/utils/misc.lua index 7c6d0e7..1e6665a 100644 --- a/lua/cmp/utils/misc.lua +++ b/lua/cmp/utils/misc.lua @@ -32,7 +32,7 @@ end ---Repeat values ---@generic T ---@param str_or_tbl T ----@param count number +---@param count integer ---@return T misc.rep = function(str_or_tbl, count) if type(str_or_tbl) == 'string' then @@ -124,8 +124,9 @@ misc.id = setmetatable({ }) ---Check the value is nil or not. ----@param v boolean ----@return boolean +---@generic T|nil|vim.NIL +---@param v T +---@return T|nil misc.safe = function(v) if v == nil or v == vim.NIL then return nil @@ -184,8 +185,8 @@ end ---Safe version of vim.str_utfindex ---@param text string ----@param vimindex number|nil ----@return number +---@param vimindex integer|nil +---@return integer misc.to_utfindex = function(text, vimindex) vimindex = vimindex or #text + 1 return vim.str_utfindex(text, math.max(0, math.min(vimindex - 1, #text))) @@ -193,8 +194,8 @@ end ---Safe version of vim.str_byteindex ---@param text string ----@param utfindex number ----@return number +---@param utfindex integer +---@return integer misc.to_vimindex = function(text, utfindex) utfindex = utfindex or #text for i = utfindex, 1, -1 do diff --git a/lua/cmp/utils/str.lua b/lua/cmp/utils/str.lua index bca210c..df5e643 100644 --- a/lua/cmp/utils/str.lua +++ b/lua/cmp/utils/str.lua @@ -99,8 +99,8 @@ end ---get_word ---@param text string ----@param stop_char number ----@param min_length number +---@param stop_char integer +---@param min_length integer ---@return string str.get_word = function(text, stop_char, min_length) min_length = min_length or 0 diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index a8a271e..b150c03 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -5,18 +5,18 @@ local api = require('cmp.utils.api') ---@class cmp.WindowStyle ---@field public relative string ----@field public row number ----@field public col number ----@field public width number ----@field public height number +---@field public row integer +---@field public col integer +---@field public width integer +---@field public height integer ---@field public border string|string[]|nil ----@field public zindex number|nil +---@field public zindex integer|nil ---@class cmp.Window ---@field public name string ----@field public win number|nil ----@field public thumb_win number|nil ----@field public sbar_win number|nil +---@field public win integer|nil +---@field public thumb_win integer|nil +---@field public sbar_win integer|nil ---@field public style cmp.WindowStyle ---@field public opt table ---@field public buffer_opt table @@ -91,7 +91,7 @@ window.set_style = function(self, style) end ---Return buffer id. ----@return number +---@return integer window.get_buffer = function(self) local buf, created_new = buffer.ensure(self.name) if created_new then @@ -240,7 +240,7 @@ window.info = function(self) end ---Return border information. ----@return { top: number, left: number, right: number, bottom: number, vert: number, horiz: number, visible: boolean } +---@return { top: integer, left: integer, right: integer, bottom: integer, vert: integer, horiz: integer, visible: boolean } window.get_border_info = function(self) local border = self.style.border if not border or border == 'none' then @@ -296,7 +296,7 @@ end ---Get scroll height. ---NOTE: The result of vim.fn.strdisplaywidth depends on the buffer it was called in (see comment in cmp.Entry.get_view). ----@return number +---@return integer window.get_content_height = function(self) if not self:option('wrap') then return vim.api.nvim_buf_line_count(self:get_buffer()) diff --git a/lua/cmp/view.lua b/lua/cmp/view.lua index 6eb00f5..42f5664 100644 --- a/lua/cmp/view.lua +++ b/lua/cmp/view.lua @@ -153,7 +153,7 @@ view.visible = function(self) end ---Scroll documentation window if possible. ----@param delta number +---@param delta integer view.scroll_docs = function(self, delta) self.docs_view:scroll(delta) end diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index d3e97c9..2ce3bc5 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -12,7 +12,7 @@ local DEFAULT_HEIGHT = 10 -- @see https://github.com/vim/vim/blob/master/src/pop ---@class cmp.CustomEntriesView ---@field private entries_win cmp.Window ----@field private offset number +---@field private offset integer ---@field private active boolean ---@field private entries cmp.Entry[] ---@field private column_width any diff --git a/lua/cmp/view/native_entries_view.lua b/lua/cmp/view/native_entries_view.lua index 0f5fc00..a74c63d 100644 --- a/lua/cmp/view/native_entries_view.lua +++ b/lua/cmp/view/native_entries_view.lua @@ -7,10 +7,10 @@ local config = require('cmp.config') local api = require('cmp.utils.api') ---@class cmp.NativeEntriesView ----@field private offset number +---@field private offset integer ---@field private items vim.CompletedItem ---@field private entries cmp.Entry[] ----@field private preselect_index number +---@field private preselect_index integer ---@field public event cmp.Event local native_entries_view = {} diff --git a/lua/cmp/view/wildmenu_entries_view.lua b/lua/cmp/view/wildmenu_entries_view.lua index 3419164..62ee330 100644 --- a/lua/cmp/view/wildmenu_entries_view.lua +++ b/lua/cmp/view/wildmenu_entries_view.lua @@ -9,7 +9,7 @@ local misc = require('cmp.utils.misc') local api = require('cmp.utils.api') ---@class cmp.CustomEntriesView ----@field private offset number +---@field private offset integer ---@field private entries_win cmp.Window ---@field private active boolean ---@field private entries cmp.Entry[] diff --git a/lua/cmp/vim_source.lua b/lua/cmp/vim_source.lua index 2ee8fbf..5af9a72 100644 --- a/lua/cmp/vim_source.lua +++ b/lua/cmp/vim_source.lua @@ -2,7 +2,7 @@ local misc = require('cmp.utils.misc') local vim_source = {} ----@param id number +---@param id integer ---@param args any[] vim_source.on_callback = function(id, args) if vim_source.to_callback.callbacks[id] then @@ -11,7 +11,7 @@ vim_source.on_callback = function(id, args) end ---@param callback function ----@return number +---@return integer vim_source.to_callback = setmetatable({ callbacks = {}, }, { @@ -36,7 +36,7 @@ vim_source.to_args = function(args) return args end ----@param bridge_id number +---@param bridge_id integer ---@param methods string[] vim_source.new = function(bridge_id, methods) local self = {}