Skip to content

Commit c29fe4b

Browse files
committed
chrore: does not store the text
1 parent bea6e12 commit c29fe4b

File tree

2 files changed

+34
-89
lines changed

2 files changed

+34
-89
lines changed

lua/phoenix/async.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ local read_file = async(function(filepath, callback)
5252
callback(data)
5353
end)
5454

55-
function throttle(fn, delay)
55+
local function throttle(fn, delay)
5656
local timer = nil
5757
return function(...)
5858
local args = { ... }

lua/phoenix/init.lua

Lines changed: 33 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,6 @@ local scan_cache = LRUCache:new(100)
230230

231231
local server = {}
232232

233-
local function get_root(filename)
234-
local data
235-
for r, item in pairs(projects) do
236-
if vim.startswith(filename, r) then
237-
data = item
238-
break
239-
end
240-
end
241-
return data
242-
end
243-
244233
local function schedule_result(callback, items)
245234
vim.schedule(function()
246235
callback(nil, { isIncomplete = false, items = items or {} })
@@ -479,12 +468,11 @@ end
479468
local async = require('phoenix.async')
480469

481470
-- Initialize dictionary with full content
482-
local initialize_dict = async.throttle(function(content)
471+
local initialize_dict = async.throttle(function(lines)
483472
local dict_config = Config.dict
484473
local scanner_config = Config.scanner
485474
local processed = 0
486475
local seen = {}
487-
local lines = vim.split(content, '\n')
488476

489477
local function process_batch()
490478
processed =
@@ -500,47 +488,6 @@ local initialize_dict = async.throttle(function(content)
500488
vim.schedule(process_batch)
501489
end, Config.scanner.throttle_delay_ms)
502490

503-
-- Update dictionary with changes
504-
local update_dict = async.throttle(function(new, old)
505-
if not old then
506-
return
507-
end
508-
509-
local hunks = vim.diff(old, new, {
510-
result_type = 'indices',
511-
algorithm = 'minimal',
512-
ignore_cr_at_eol = true,
513-
ignore_whitespace = true,
514-
ignore_blank_lines = true,
515-
ctxlen = 0,
516-
ignore_whitespace_change = true,
517-
ignore_whitespace_change_at_eol = true,
518-
})
519-
520-
if not hunks or #hunks == 0 then
521-
return
522-
end
523-
524-
local seen = {}
525-
local lines = vim.split(new, '\n')
526-
local new_words = 0
527-
528-
-- Process changed lines
529-
---@diagnostic disable-next-line: param-type-mismatch
530-
for _, hunk in ipairs(hunks) do
531-
local start_new, count_new = hunk[3], hunk[4]
532-
if count_new > 0 then
533-
new_words = new_words + process_words(lines[start_new], seen, Config.dict)
534-
end
535-
end
536-
537-
dict.word_count = dict.word_count + new_words
538-
539-
if dict.word_count > dict.max_words then
540-
cleanup_dict()
541-
end
542-
end, Config.scanner.throttle_delay_ms)
543-
544491
local Snippet = {
545492
cache = {},
546493
loading = {},
@@ -676,36 +623,49 @@ end
676623

677624
-- LSP handler functions
678625
local function handle_document_open(params)
679-
local filename = vim.uri_to_fname(params.textDocument.uri)
680-
local data = get_root(filename)
681-
if not data then
626+
local text = params.textDocument.text
627+
if #text == 0 then
628+
return
629+
end
630+
local content = vim.split(text, '%s', { trimempty = true })
631+
if #content == 0 then
682632
return
683633
end
684634

685-
data[filename] = params.textDocument.text
686-
initialize_dict(data[filename])
635+
initialize_dict(content)
687636
end
688637

689638
local function handle_document_change(params)
690639
if tonumber(vim.fn.pumvisible()) == 1 then
691640
return
692641
end
693642

694-
local filename = vim.uri_to_fname(params.textDocument.uri)
695-
local root = get_root(filename)
696-
if not root then
643+
-- Process only the changed text
644+
local change = params.contentChanges[1]
645+
if not change or not change.text then
697646
return
698647
end
699648

700-
local new = params.contentChanges[1].text
701-
if not new then
649+
-- Process just the changed text
650+
local lines = vim.split(change.text, '\n')
651+
if #lines == 0 then
702652
return
703653
end
704-
local old = root[filename]
705-
root[filename] = new
706654

707-
-- Only process visible range for better performance
708-
update_dict(visible_range(new), visible_range(old))
655+
-- Process the new text directly without comparing to old version
656+
local seen = {}
657+
local dict_config = Config.dict
658+
local new_words = 0
659+
660+
for _, line in ipairs(lines) do
661+
new_words = new_words + process_words(line, seen, dict_config)
662+
end
663+
664+
dict.word_count = dict.word_count + new_words
665+
666+
if dict.word_count > dict.max_words then
667+
cleanup_dict()
668+
end
709669
end
710670

711671
function server.create()
@@ -734,17 +694,9 @@ function server.create()
734694

735695
function srv.completion(params, callback)
736696
local position = params.position
737-
local filename = vim.uri_to_fname(params.textDocument.uri)
738-
local root = get_root(filename)
739-
740-
if not root then
741-
schedule_result(callback)
742-
return
743-
end
744-
745-
local lines = vim.split(root[filename], '\n')
746-
local line = lines[position.line + 1]
747-
if not line then
697+
-- local lines = vim.split(root[filename], '\n')
698+
local line = vim.api.nvim_get_current_line()
699+
if #line == 0 then
748700
schedule_result(callback)
749701
return
750702
end
@@ -817,14 +769,7 @@ function server.create()
817769
srv['textDocument/didOpen'] = handle_document_open
818770
srv['textDocument/didChange'] = handle_document_change
819771

820-
srv['textDocument/didClose'] = function(params)
821-
local filename = vim.uri_to_fname(params.textDocument.uri)
822-
local root = get_root(filename)
823-
if not root then
824-
return
825-
end
826-
root[filename] = nil
827-
end
772+
srv['textDocument/didClose'] = function(params) end
828773

829774
function srv.shutdown(params, callback)
830775
callback(nil, nil)
@@ -858,7 +803,7 @@ return {
858803
vim.api.nvim_create_autocmd('FileType', {
859804
pattern = Config.filetypes,
860805
callback = function(args)
861-
if vim.bo[args.buf].buftype == 'nofile' then
806+
if vim.bo[args.buf].filetype == '' then
862807
return
863808
end
864809

0 commit comments

Comments
 (0)