Skip to content

Commit b4777ac

Browse files
committed
breakchane: add snippet.path and snippet.priority
now config snippet must use , and word completion priority now is integer not table
1 parent 9fbb38e commit b4777ac

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ vim.g.phoenix = {
5555
recency = 0.3, -- 30% weight to recent usage
5656
frequency = 0.7, -- 70% weight to frequency
5757
},
58-
priority = {
59-
base = 100, -- Base priority score (0-999)
60-
position = 'after', -- Position relative to other LSP results: 'before' or 'after'
61-
},
58+
priority = 500,
6259
},
6360

6461
-- Cleanup settings control dictionary maintenance
@@ -79,7 +76,10 @@ vim.g.phoenix = {
7976
throttle_delay_ms = 200, -- Wait 200ms between updates
8077
ignore_patterns = {}, -- Dictionary or file ignored when path completion
8178
},
82-
snippet = '' -- path of snippet json file like c.json/zig.json/go.json
79+
snippet = {
80+
path = '' -- path of snippet json file like c.json/zig.json/go.json
81+
prioritiy = 200,
82+
}
8383
}
8484
```
8585

lua/phoenix/init.lua

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ local default = {
2222
recency = 0.3, -- 30% weight to recent usage
2323
frequency = 0.7, -- 70% weight to frequency
2424
},
25-
priority = {
26-
base = 100, -- Base priority score (0-999)
27-
position = 'after', -- Position relative to other LSP results: 'before' or 'after'
28-
},
25+
priority = 500,
2926
},
3027

3128
-- Cleanup settings control dictionary maintenance
@@ -46,7 +43,10 @@ local default = {
4643
throttle_delay_ms = 300, -- Wait 300ms between updates
4744
ignore_patterns = {}, -- No ignore patterns by default
4845
},
49-
snippet = '',
46+
snippet = {
47+
path = '',
48+
priority = 200,
49+
},
5050
}
5151

5252
--@type PhoenixConfig
@@ -498,7 +498,7 @@ function Snippet:preload()
498498
if self.cache[ft] or self.loading[ft] then
499499
return
500500
end
501-
local path = vim.fs.joinpath(Config.snippet, ('%s.json'):format(ft))
501+
local path = vim.fs.joinpath(Config.snippet.path, ('%s.json'):format(ft))
502502
if vim.fn.filereadable(path) == 1 then
503503
self.loading[ft] = true
504504
async.read_file(path, function(data)
@@ -525,6 +525,8 @@ local function parse_snippet(input)
525525
return ok and tostring(parsed) or input
526526
end
527527

528+
local special = { 'c', 'cpp' }
529+
528530
function Snippet:get_completions(prefix)
529531
local ft = vim.bo.filetype
530532
local results = {}
@@ -544,7 +546,7 @@ function Snippet:get_completions(prefix)
544546
end
545547

546548
table.insert(results, {
547-
label = trigger,
549+
label = vim.list_contains(special, vim.bo[0].filetype) and '' .. trigger or trigger,
548550
kind = 15,
549551
insertText = insert_text,
550552
documentation = {
@@ -557,7 +559,7 @@ function Snippet:get_completions(prefix)
557559
.. '\n```',
558560
},
559561
detail = 'Snippet: ' .. (snippet_data.description or ''),
560-
sortText = string.format('001%s', trigger),
562+
sortText = string.format('%03d%s', Config.snippet.priority or 200, trigger),
561563
insertTextFormat = 2,
562564
})
563565
end
@@ -574,7 +576,7 @@ local function collect_completions(prefix)
574576
local results = Trie.search_prefix(dict.trie, prefix)
575577
local now = vim.uv.now()
576578
local decay_time = Config.completion.decay_minutes * 60 * 1000
577-
local priority_config = Config.completion.priority
579+
local word_priority = Config.completion.priority or 500
578580

579581
local max_freq = 0
580582
for _, result in ipairs(results) do
@@ -590,21 +592,14 @@ local function collect_completions(prefix)
590592
return score_a > score_b
591593
end)
592594

593-
-- Calculate sort prefix based on priority configuration
594-
local sort_prefix = priority_config.position == 'before'
595-
and string.format('%03d', priority_config.base)
596-
or string.format('%03d', priority_config.base + 100)
597-
598-
local special = { 'c', 'cpp' }
599-
600595
return vim
601596
.iter(ipairs(results))
602597
:map(function(idx, node)
603598
local t = {
604599
label = node.word,
605600
filterText = node.word,
606601
kind = 1,
607-
sortText = string.format('%s%09d%s', sort_prefix, idx, node.word),
602+
sortText = string.format('%03d%09d%s', word_priority, idx, node.word),
608603
}
609604

610605
if vim.list_contains(special, vim.bo[0].filetype) then
@@ -843,7 +838,7 @@ return {
843838
end,
844839
})
845840

846-
if #Config.snippet > 0 then
841+
if #Config.snippet.path > 0 then
847842
Snippet:preload()
848843
end
849844
end,

lua/phoenix/types.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
---@field recency number Weight for recency in scoring (0-1). Higher values favor recently used words more strongly
44
---@field frequency number Weight for frequency in scoring (0-1). Higher values favor frequently used words more strongly
55

6-
---Configuration for completion item position
7-
---@class PriorityConfig
8-
---@field base integer Base priority score (0-999)
9-
---@field position string Position relative to other LSP results: 'before' or 'after'
10-
116
---Core dictionary configuration
127
---@class DictionaryConfig
138
---@field capacity number Maximum number of words to store in the dictionary. Higher values provide better completions but use more memory
@@ -19,7 +14,7 @@
1914
---@field max_items integer Max result items
2015
---@field decay_minutes integer Time period for decay calculation
2116
---@field weights WeightConfig Scoring weights configuration for ranking completion candidates
22-
---@field priority PriorityConfig
17+
---@field priority number
2318

2419
---Configuration for dictionary cleanup process
2520
---@class CleanupConfig
@@ -38,11 +33,15 @@
3833
---@field throttle_delay_ms number Delay between processing updates (milliseconds). Prevents excessive CPU usage during rapid changes
3934
---@field ignore_patterns string[] Patterns for files/directories to ignore during scanning. Improves performance by skipping irrelevant items
4035

36+
---@class SnippetConfig
37+
---@field path string
38+
---@field priority number
39+
4140
---Main configuration for Phoenix
4241
---@class PhoenixConfig
4342
---@field filetypes string[] List of filetypes to enable Phoenix for. Use {'*'} for all filetypes
4443
---@field dict DictionaryConfig Settings controlling the core dictionary behavior
4544
---@field completion CompletionConfig Settings controlling the core dictionary behavior
4645
---@field cleanup CleanupConfig Settings controlling how and when dictionary cleanup occurs
4746
---@field scanner ScannerConfig Settings controlling file system scanning behavior
48-
---@field snippet string Snippet path
47+
---@field snippet SnippetConfig

0 commit comments

Comments
 (0)