Skip to content

Commit dc0d550

Browse files
author
zizhou teng (n451)
committed
fix: add get_word
1 parent 3406265 commit dc0d550

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lua/obsidian/lsp/handlers/_completion.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local find, sub, lower = string.find, string.sub, string.lower
2-
31
local CmpType = {
42
ref = 1,
53
tag = 2,

lua/obsidian/lsp/handlers/completion.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ handlers[CmpType.ref] = function(prefix, range, handler)
283283
end
284284
end
285285

286+
---Adpated from none-ls
287+
---gets word to complete for use in completion sources
288+
---@param params lsp.CompletionParams
289+
---@return string word_to_complete
290+
local get_word_to_complete = function(params)
291+
local col = params.position.character + 1
292+
local line = vim.api.nvim_get_current_line()
293+
local line_to_cursor = line:sub(1, col)
294+
local regex = vim.regex "\\k*$"
295+
296+
return line:sub(regex:match_str(line_to_cursor) + 1, col)
297+
end
298+
286299
-- TODO: search.find_heading
287300
-- local function handle_heading() end
288301
---@param params lsp.CompletionParams

tests/lsp/test_completion_util.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local eq = MiniTest.expect.equality
22
local h = dofile "tests/helpers.lua"
33
local M = require "obsidian.lsp.handlers._completion"
44

5-
local T, child = h.child_vault()
5+
local T, _ = h.child_vault()
66

77
T["get_cmp_type"] = function()
88
-- 012345678

0 commit comments

Comments
 (0)