@@ -11,23 +11,32 @@ local util = require "obsidian.util"
11
11
12
12
local find , sub , lower = string.find , string.sub , string.lower
13
13
14
+ local function insert_snippet_marker (text , style )
15
+ if style == " markdown" then
16
+ local pos = text :find " ]"
17
+ local a , b = sub (text , 1 , pos - 1 ), sub (text , pos )
18
+ return a .. " $1" .. b
19
+ end
20
+ end
21
+
14
22
--- @param note obsidian.Note
15
23
--- @param insert_text string
16
24
--- @param insert_start integer
17
25
--- @param insert_end integer
18
26
--- @param line_num integer
19
27
--- @return lsp.CompletionItem
20
- local function calc_ref_item (note , insert_text , insert_start , insert_end , line_num )
28
+ local function calc_ref_item (note , insert_text , insert_start , insert_end , line_num , style )
21
29
return {
22
30
kind = 17 ,
23
31
label = note .title ,
24
32
filterText = note .title ,
33
+ insertTextFormat = 2 , -- is snippet
25
34
textEdit = {
26
35
range = {
27
36
start = { line = line_num , character = insert_start },
28
37
[" end" ] = { line = line_num , character = insert_end },
29
38
},
30
- newText = insert_text ,
39
+ newText = insert_snippet_marker ( insert_text , style ) ,
31
40
},
32
41
labelDetails = { description = " Obsidian" },
33
42
data = {
@@ -55,7 +64,8 @@ local function handle_ref(client, partial, ref_start, cursor_col, line_num, hand
55
64
local pattern = vim .pesc (lower (partial ))
56
65
if title and find (lower (title ), pattern ) then
57
66
local link_text = client :format_link (note )
58
- items [# items + 1 ] = calc_ref_item (note , link_text , ref_start , cursor_col , line_num )
67
+ local style = client .opts .preferred_link_style
68
+ items [# items + 1 ] = calc_ref_item (note , link_text , ref_start , cursor_col , line_num , style )
59
69
end
60
70
end
61
71
handler (nil , { items = items })
@@ -103,9 +113,9 @@ return function(client, params, handler, _)
103
113
local buf = vim .uri_to_bufnr (uri )
104
114
local line_text = vim .api .nvim_buf_get_lines (buf , line_num , line_num + 1 , false )[1 ]
105
115
106
- print (util .strip_anchor_links (line_text ))
107
- print (util .strip_block_links (line_text ))
108
-
116
+ -- print(util.strip_anchor_links(line_text))
117
+ -- print(util.strip_block_links(line_text))
118
+ --
109
119
local text_before_cursor = sub (line_text , 1 , char_num )
110
120
111
121
local tag_start = find (text_before_cursor , " #" , 1 , true )
0 commit comments